Skip to content

Commit 1ca68e8

Browse files
committed
fix test
Signed-off-by: Runji Wang <[email protected]>
1 parent c37fa65 commit 1ca68e8

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

src/common/src/types/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,13 @@ impl DataType {
347347
)
348348
}
349349

350+
pub fn as_struct(&self) -> &StructType {
351+
match self {
352+
DataType::Struct(t) => t,
353+
_ => panic!("expect struct type"),
354+
}
355+
}
356+
350357
/// WARNING: Currently this should only be used in `WatermarkFilterExecutor`. Please be careful
351358
/// if you want to use this.
352359
pub fn min(&self) -> ScalarImpl {

src/frontend/src/handler/create_function.rs

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,21 @@ pub async fn handle_create_function(
8484
Kind::Scalar(ScalarFunction {})
8585
}
8686
Some(CreateFunctionReturns::Table(columns)) => {
87-
let datatypes = columns
88-
.iter()
89-
.map(|c| bind_data_type(&c.data_type))
90-
.collect::<Result<Vec<_>>>()?;
91-
let names = columns
92-
.iter()
93-
.map(|c| c.name.real_value())
94-
.collect::<Vec<_>>();
95-
return_type = DataType::new_struct(datatypes, names);
87+
if columns.len() == 1 {
88+
// return type is the original type for single column
89+
return_type = bind_data_type(&columns[0].data_type)?;
90+
} else {
91+
// return type is a struct for multiple columns
92+
let datatypes = columns
93+
.iter()
94+
.map(|c| bind_data_type(&c.data_type))
95+
.collect::<Result<Vec<_>>>()?;
96+
let names = columns
97+
.iter()
98+
.map(|c| c.name.real_value())
99+
.collect::<Vec<_>>();
100+
return_type = DataType::new_struct(datatypes, names);
101+
}
96102
Kind::Table(TableFunction {})
97103
}
98104
None => {
@@ -137,11 +143,24 @@ pub async fn handle_create_function(
137143
.map(|t| arrow_schema::Field::new("", t.into(), true))
138144
.collect(),
139145
);
140-
let returns = arrow_schema::Schema::new(vec![arrow_schema::Field::new(
141-
"",
142-
return_type.clone().into(),
143-
true,
144-
)]);
146+
let returns = match kind {
147+
Kind::Scalar(_) => arrow_schema::Schema::new(vec![arrow_schema::Field::new(
148+
"",
149+
return_type.clone().into(),
150+
true,
151+
)]),
152+
Kind::Table(_) => arrow_schema::Schema::new(match &return_type {
153+
DataType::Struct(s) => (s.fields.iter())
154+
.map(|t| arrow_schema::Field::new("", t.clone().into(), true))
155+
.collect(),
156+
_ => vec![arrow_schema::Field::new(
157+
"",
158+
return_type.clone().into(),
159+
true,
160+
)],
161+
}),
162+
_ => unreachable!(),
163+
};
145164
client
146165
.check(&identifier, &args, &returns)
147166
.await

0 commit comments

Comments
 (0)