-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Support consuming Substrait with compound signature function names #10653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cd549d8
f39c63b
90eaed9
339ea97
eb6cd9a
e6ff946
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ use datafusion::logical_expr::expr::{ | |
| }; | ||
| use datafusion::logical_expr::{expr, Between, JoinConstraint, LogicalPlan, Operator}; | ||
| use datafusion::prelude::Expr; | ||
| use prost_types::Any as ProtoAny; | ||
| use pbjson_types::Any as ProtoAny; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WHy do we need to change to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this confuses me a bit as well - but the way I understand it, adding the "serde" feature to "substrait-rs" seems to change the types it expects from the original Given we use the I'd also prefer to not change this, but I couldn't find another way if we want to have the JSON proto plans :/ |
||
| use substrait::proto::exchange_rel::{ExchangeKind, RoundRobin, ScatterFields}; | ||
| use substrait::proto::expression::literal::user_defined::Val; | ||
| use substrait::proto::expression::literal::UserDefined; | ||
|
|
@@ -487,7 +487,7 @@ pub fn to_substrait_rel( | |
| .serialize_logical_plan(extension_plan.node.as_ref())?; | ||
| let detail = ProtoAny { | ||
| type_url: extension_plan.node.name().to_string(), | ||
| value: extension_bytes, | ||
| value: extension_bytes.into(), | ||
| }; | ||
| let mut inputs_rel = extension_plan | ||
| .node | ||
|
|
@@ -1802,7 +1802,7 @@ fn to_substrait_literal(value: &ScalarValue) -> Result<Literal> { | |
| }], | ||
| val: Some(Val::Value(ProtoAny { | ||
| type_url: INTERVAL_YEAR_MONTH_TYPE_URL.to_string(), | ||
| value: bytes.to_vec(), | ||
| value: bytes.to_vec().into(), | ||
| })), | ||
| }), | ||
| INTERVAL_YEAR_MONTH_TYPE_REF, | ||
|
|
@@ -1825,7 +1825,7 @@ fn to_substrait_literal(value: &ScalarValue) -> Result<Literal> { | |
| type_parameters: vec![i64_param.clone(), i64_param], | ||
| val: Some(Val::Value(ProtoAny { | ||
| type_url: INTERVAL_MONTH_DAY_NANO_TYPE_URL.to_string(), | ||
| value: bytes.to_vec(), | ||
| value: bytes.to_vec().into(), | ||
| })), | ||
| }), | ||
| INTERVAL_MONTH_DAY_NANO_TYPE_REF, | ||
|
|
@@ -1848,7 +1848,7 @@ fn to_substrait_literal(value: &ScalarValue) -> Result<Literal> { | |
| }], | ||
| val: Some(Val::Value(ProtoAny { | ||
| type_url: INTERVAL_DAY_TIME_TYPE_URL.to_string(), | ||
| value: bytes.to_vec(), | ||
| value: bytes.to_vec().into(), | ||
| })), | ||
| }), | ||
| INTERVAL_DAY_TIME_TYPE_REF, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| //! Tests for reading substrait plans produced by other systems | ||
|
|
||
| #[cfg(test)] | ||
Blizzara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| mod tests { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general the idea of having checked in substrait plans (as json protobuf) is actually likely a pretty good way to build up a library of test cases "from the wild" (not round tripped) This is quite cool @Blizzara |
||
| use datafusion::common::Result; | ||
| use datafusion::prelude::{CsvReadOptions, SessionContext}; | ||
| use datafusion_substrait::logical_plan::consumer::from_substrait_plan; | ||
| use std::fs::File; | ||
| use std::io::BufReader; | ||
| use substrait::proto::Plan; | ||
|
|
||
| #[tokio::test] | ||
| async fn function_compound_signature() -> Result<()> { | ||
| // DataFusion currently produces Substrait that refers to functions only by their name. | ||
| // However, the Substrait spec requires that functions be identified by their compound signature. | ||
| // This test confirms that DataFusion is able to consume plans following the spec, even though | ||
| // we don't yet produce such plans. | ||
| // Once we start producing plans with compound signatures, this test can be replaced by the roundtrip tests. | ||
|
|
||
| let ctx = create_context().await?; | ||
|
|
||
| // File generated with substrait-java's Isthmus: | ||
| // ./isthmus-cli/build/graal/isthmus "select not d from data" -c "create table data (d boolean)" | ||
| let path = "tests/testdata/select_not_bool.substrait.json"; | ||
| let proto = serde_json::from_reader::<_, Plan>(BufReader::new( | ||
| File::open(path).expect("file not found"), | ||
| )) | ||
| .expect("failed to parse json"); | ||
|
|
||
| let plan = from_substrait_plan(&ctx, &proto).await?; | ||
|
|
||
| assert_eq!( | ||
| format!("{:?}", plan), | ||
| "Projection: NOT DATA.a\ | ||
| \n TableScan: DATA projection=[a, b, c, d, e, f]" | ||
| ); | ||
| Ok(()) | ||
| } | ||
|
|
||
| async fn create_context() -> datafusion::common::Result<SessionContext> { | ||
| let ctx = SessionContext::new(); | ||
| ctx.register_csv("DATA", "tests/testdata/data.csv", CsvReadOptions::new()) | ||
| .await?; | ||
| Ok(ctx) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| { | ||
| "extensionUris": [ | ||
| { | ||
| "extensionUriAnchor": 1, | ||
| "uri": "/functions_boolean.yaml" | ||
| } | ||
| ], | ||
| "extensions": [ | ||
| { | ||
| "extensionFunction": { | ||
| "extensionUriReference": 1, | ||
| "functionAnchor": 0, | ||
| "name": "not:bool" | ||
| } | ||
| } | ||
| ], | ||
| "relations": [ | ||
| { | ||
| "root": { | ||
| "input": { | ||
| "project": { | ||
| "common": { | ||
| "emit": { | ||
| "outputMapping": [ | ||
| 1 | ||
| ] | ||
| } | ||
| }, | ||
| "input": { | ||
| "read": { | ||
| "common": { | ||
| "direct": { | ||
| } | ||
| }, | ||
| "baseSchema": { | ||
| "names": [ | ||
| "D" | ||
| ], | ||
| "struct": { | ||
| "types": [ | ||
| { | ||
| "bool": { | ||
| "typeVariationReference": 0, | ||
| "nullability": "NULLABILITY_NULLABLE" | ||
| } | ||
| } | ||
| ], | ||
| "typeVariationReference": 0, | ||
| "nullability": "NULLABILITY_REQUIRED" | ||
| } | ||
| }, | ||
| "namedTable": { | ||
| "names": [ | ||
| "DATA" | ||
| ] | ||
| } | ||
| } | ||
| }, | ||
| "expressions": [ | ||
| { | ||
| "scalarFunction": { | ||
| "functionReference": 0, | ||
| "args": [], | ||
| "outputType": { | ||
| "bool": { | ||
| "typeVariationReference": 0, | ||
| "nullability": "NULLABILITY_NULLABLE" | ||
| } | ||
| }, | ||
| "arguments": [ | ||
| { | ||
| "value": { | ||
| "selection": { | ||
| "directReference": { | ||
| "structField": { | ||
| "field": 0 | ||
| } | ||
| }, | ||
| "rootReference": { | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ], | ||
| "options": [] | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "names": [ | ||
| "EXPR$0" | ||
| ] | ||
| } | ||
| } | ||
| ], | ||
| "expectedTypeUrls": [] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this need to be a actual dependency or can it be a dev dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answered in more depth here, but yes I think it does need to be actual dep
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That said we can remove the prost-types dep, we don't need both: e6ff946