Skip to content

Commit 3b6996f

Browse files
authored
TableFunction Fixes (#23)
* TableFunction Fixes * Also fix tests after rebase * Taplo format * Clippy * Fix docs
1 parent 9b365ac commit 3b6996f

6 files changed

Lines changed: 31 additions & 13 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ regex = "1.8"
165165
rstest = "0.24.0"
166166
serde_json = "1"
167167
sqlparser = { git = "https://github.com/Embucket/datafusion-sqlparser-rs.git", rev = "ed416548dcfe4a73a3240bbf625fb9010a4925c8", features = [
168-
"visitor",
168+
"visitor",
169169
] }
170170
tempfile = "3"
171171
tokio = { version = "1.44", features = ["macros", "rt", "sync"] }

datafusion/ffi/src/udtf.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ unsafe extern "C" fn call_fn_wrapper(
100100
let args =
101101
rresult_return!(parse_exprs(proto_filters.expr.iter(), &default_ctx, &codec));
102102

103-
let table_provider = rresult_return!(udtf.call(&args));
103+
let args_with_names = args
104+
.into_iter()
105+
.map(|expr| (expr, None))
106+
.collect::<Vec<_>>();
107+
let table_provider = rresult_return!(udtf.call(&args_with_names));
104108
RResult::ROk(FFI_TableProvider::new(table_provider, false, runtime))
105109
}
106110

@@ -176,10 +180,13 @@ impl From<FFI_TableFunction> for ForeignTableFunction {
176180
}
177181

178182
impl TableFunctionImpl for ForeignTableFunction {
179-
fn call(&self, args: &[Expr]) -> Result<Arc<dyn TableProvider>> {
183+
fn call(&self, args: &[(Expr, Option<String>)]) -> Result<Arc<dyn TableProvider>> {
180184
let codec = DefaultLogicalExtensionCodec {};
181185
let expr_list = LogicalExprList {
182-
expr: serialize_exprs(args, &codec)?,
186+
expr: serialize_exprs(
187+
args.iter().map(|(expr, _)| expr).collect::<Vec<_>>(),
188+
&codec,
189+
)?,
183190
};
184191
let filters_serialized = expr_list.encode_to_vec().into();
185192

@@ -210,10 +217,13 @@ mod tests {
210217
struct TestUDTF {}
211218

212219
impl TableFunctionImpl for TestUDTF {
213-
fn call(&self, args: &[Expr]) -> Result<Arc<dyn TableProvider>> {
220+
fn call(
221+
&self,
222+
args: &[(Expr, Option<String>)],
223+
) -> Result<Arc<dyn TableProvider>> {
214224
let args = args
215225
.iter()
216-
.map(|arg| {
226+
.map(|(arg, _)| {
217227
if let Expr::Literal(scalar) = arg {
218228
Ok(scalar)
219229
} else {
@@ -293,8 +303,12 @@ mod tests {
293303

294304
let foreign_udf: ForeignTableFunction = local_udtf.into();
295305

296-
let table =
297-
foreign_udf.call(&vec![lit(6_u64), lit("one"), lit(2.0), lit(3_u64)])?;
306+
let table = foreign_udf.call(&vec![
307+
(lit(6_u64), None),
308+
(lit("one"), None),
309+
(lit(2.0), None),
310+
(lit(3_u64), None),
311+
])?;
298312

299313
let ctx = SessionContext::default();
300314
let _ = ctx.register_table("test-table", table)?;

datafusion/functions/src/datetime/to_date.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,12 @@ mod tests {
455455
ScalarValue::TimestampNanosecond(Some(1736782134736782134), None),
456456
];
457457
for scalar in test_cases {
458-
let timestamp_to_date_result = ToDateFunc::new()
459-
.invoke_batch(&[ColumnarValue::Scalar(scalar.clone())], 1);
458+
let timestamp_to_date_result =
459+
ToDateFunc::new().invoke_with_args(datafusion_expr::ScalarFunctionArgs {
460+
args: vec![ColumnarValue::Scalar(scalar.clone())],
461+
number_rows: 1,
462+
return_type: &DataType::Date32,
463+
});
460464

461465
match timestamp_to_date_result {
462466
Ok(ColumnarValue::Scalar(ScalarValue::Date32(date_val))) => {

datafusion/functions/src/regex/regexplike.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use datafusion_expr::{
3333
use datafusion_macros::user_doc;
3434

3535
use std::any::Any;
36-
use std::sync::{Arc, OnceLock};
36+
use std::sync::Arc;
3737

3838
#[user_doc(
3939
doc_section(label = "Regular Expression Functions"),

datafusion/sql/src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ mod tests {
10701070
}
10711071

10721072
#[test]
1073-
fn skip_create_stage_snowflake() -> Result<(), ParserError> {
1073+
fn skip_create_stage_snowflake() -> Result<(), DataFusionError> {
10741074
let sql =
10751075
"CREATE OR REPLACE STAGE stage URL='s3://data.csv' FILE_FORMAT=(TYPE=csv)";
10761076
let dialect = Box::new(SnowflakeDialect);

docs/source/user-guide/sql/scalar_functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1956,7 +1956,7 @@ Additional examples can be found [here](https://github.com/apache/datafusion/blo
19561956

19571957
Returns the substring that matches a [regular expression](https://docs.rs/regex/latest/regex/#syntax) within a string.
19581958

1959-
```
1959+
```sql
19601960
regexp_substr(str, regexp[, position[, occurrence[, flags[, group_num]]]])
19611961
```
19621962

0 commit comments

Comments
 (0)