Skip to content

Commit 1cc8a05

Browse files
committed
chore: codefmt
1 parent 76bff5e commit 1cc8a05

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

src/meta/app/src/principal/user_defined_function.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ pub struct UDFScript {
5353

5454
#[derive(Clone, Debug, Eq, PartialEq)]
5555
pub struct UDTF {
56+
// arg name with data type
5657
pub arg_types: Vec<(String, DataType)>,
58+
// return column name with data type
5759
pub return_types: Vec<(String, DataType)>,
5860
pub sql: String,
5961
}

src/meta/proto-conv/src/udf_from_to_protobuf_impl.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -289,22 +289,20 @@ impl FromToProto for mt::UDTF {
289289

290290
let mut arg_types = Vec::new();
291291
for arg_ty in p.arg_types {
292-
let ty = (&TableDataType::from_pb(arg_ty.r#type.ok_or_else(|| {
292+
let ty = TableDataType::from_pb(arg_ty.ty.ok_or_else(|| {
293293
Incompatible::new("UDTF.arg_types.ty can not be None".to_string())
294-
})?)?)
295-
.into();
294+
})?)?;
296295

297-
arg_types.push((arg_ty.name, ty));
296+
arg_types.push((arg_ty.name, (&ty).into()));
298297
}
299298

300299
let mut return_types = Vec::new();
301300
for return_ty in p.return_types {
302-
let ty = (&TableDataType::from_pb(return_ty.r#type.ok_or_else(|| {
301+
let ty = TableDataType::from_pb(return_ty.ty.ok_or_else(|| {
303302
Incompatible::new("UDTF.arg_types.ty can not be None".to_string())
304-
})?)?)
305-
.into();
303+
})?)?;
306304

307-
return_types.push((return_ty.name, ty));
305+
return_types.push((return_ty.name, (&ty).into()));
308306
}
309307

310308
Ok(Self {
@@ -327,7 +325,7 @@ impl FromToProto for mt::UDTF {
327325
.to_pb()?;
328326
arg_types.push(UdtfArg {
329327
name: arg_name.clone(),
330-
r#type: Some(arg_type),
328+
ty: Some(arg_type),
331329
});
332330
}
333331

@@ -343,7 +341,7 @@ impl FromToProto for mt::UDTF {
343341
.to_pb()?;
344342
return_types.push(UdtfArg {
345343
name: return_name.clone(),
346-
r#type: Some(return_type),
344+
ty: Some(return_type),
347345
});
348346
}
349347

src/meta/proto-conv/tests/it/v142_udtf.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use chrono::DateTime;
1616
use chrono::Utc;
17+
use databend_common_expression::types::DataType;
1718
use databend_common_meta_app::principal::UDFDefinition;
1819
use databend_common_meta_app::principal::UserDefinedFunction;
1920
use databend_common_meta_app::principal::UDTF;
@@ -35,18 +36,20 @@ use crate::common;
3536
fn test_decode_v142_udtf() -> anyhow::Result<()> {
3637
let bytes = vec![
3738
10, 9, 116, 101, 115, 116, 95, 117, 100, 116, 102, 18, 21, 84, 104, 105, 115, 32, 105, 115,
38-
32, 97, 32, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 66, 25, 26, 16, 115, 101,
39-
108, 101, 99, 116, 32, 42, 32, 102, 114, 111, 109, 32, 116, 49, 160, 6, 142, 1, 168, 6, 24,
40-
42, 23, 50, 48, 50, 51, 45, 49, 50, 45, 49, 53, 32, 48, 49, 58, 50, 54, 58, 48, 57, 32, 85,
41-
84, 67, 160, 6, 142, 1, 168, 6, 24,
39+
32, 97, 32, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 66, 79, 10, 16, 10, 2,
40+
99, 49, 18, 10, 146, 2, 0, 160, 6, 142, 1, 168, 6, 24, 10, 16, 10, 2, 99, 50, 18, 10, 138,
41+
2, 0, 160, 6, 142, 1, 168, 6, 24, 18, 16, 10, 2, 99, 51, 18, 10, 170, 2, 0, 160, 6, 142, 1,
42+
168, 6, 24, 26, 16, 115, 101, 108, 101, 99, 116, 32, 42, 32, 102, 114, 111, 109, 32, 116,
43+
49, 160, 6, 142, 1, 168, 6, 24, 42, 23, 50, 48, 50, 51, 45, 49, 50, 45, 49, 53, 32, 48, 49,
44+
58, 50, 54, 58, 48, 57, 32, 85, 84, 67, 160, 6, 142, 1, 168, 6, 24,
4245
];
4346

4447
let want = || UserDefinedFunction {
4548
name: "test_udtf".to_string(),
4649
description: "This is a description".to_string(),
4750
definition: UDFDefinition::UDTF(UDTF {
48-
arg_types: vec![],
49-
return_types: vec![],
51+
arg_types: vec![(s("c1"), DataType::String), (s("c2"), DataType::Boolean)],
52+
return_types: vec![(s("c3"), DataType::Date)],
5053
sql: "select * from t1".to_string(),
5154
}),
5255
created_on: DateTime::<Utc>::from_timestamp(1702603569, 0).unwrap(),
@@ -55,3 +58,7 @@ fn test_decode_v142_udtf() -> anyhow::Result<()> {
5558
common::test_pb_from_to(func_name!(), want())?;
5659
common::test_load_old(func_name!(), bytes.as_slice(), 142, want())
5760
}
61+
62+
fn s(ss: impl ToString) -> String {
63+
ss.to_string()
64+
}

src/meta/protos/proto/udf.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ message UDAFScript {
7171

7272
message UDTFArg {
7373
string name = 1;
74-
DataType type = 2;
74+
DataType ty = 2;
7575
}
7676

7777
message UDTF {

0 commit comments

Comments
 (0)