Skip to content

Commit 36ef0fe

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

File tree

2 files changed

+41
-14
lines changed

2 files changed

+41
-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: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,22 @@ 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 compatibility
89+
// TODO(wrj): should it always be a struct?
90+
return_type = bind_data_type(&columns[0].data_type)?;
91+
} else {
92+
// return type is a struct for multiple columns
93+
let datatypes = columns
94+
.iter()
95+
.map(|c| bind_data_type(&c.data_type))
96+
.collect::<Result<Vec<_>>>()?;
97+
let names = columns
98+
.iter()
99+
.map(|c| c.name.real_value())
100+
.collect::<Vec<_>>();
101+
return_type = DataType::new_struct(datatypes, names);
102+
}
96103
Kind::Table(TableFunction {})
97104
}
98105
None => {
@@ -137,11 +144,24 @@ pub async fn handle_create_function(
137144
.map(|t| arrow_schema::Field::new("", t.into(), true))
138145
.collect(),
139146
);
140-
let returns = arrow_schema::Schema::new(vec![arrow_schema::Field::new(
141-
"",
142-
return_type.clone().into(),
143-
true,
144-
)]);
147+
let returns = match kind {
148+
Kind::Scalar(_) => arrow_schema::Schema::new(vec![arrow_schema::Field::new(
149+
"",
150+
return_type.clone().into(),
151+
true,
152+
)]),
153+
Kind::Table(_) => arrow_schema::Schema::new(match &return_type {
154+
DataType::Struct(s) => (s.fields.iter())
155+
.map(|t| arrow_schema::Field::new("", t.clone().into(), true))
156+
.collect(),
157+
_ => vec![arrow_schema::Field::new(
158+
"",
159+
return_type.clone().into(),
160+
true,
161+
)],
162+
}),
163+
_ => unreachable!(),
164+
};
145165
client
146166
.check(&identifier, &args, &returns)
147167
.await

0 commit comments

Comments
 (0)