|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +//! Tests for reading substrait plans produced by other systems |
| 19 | +
|
| 20 | +#[cfg(test)] |
| 21 | +mod tests { |
| 22 | + use datafusion::common::Result; |
| 23 | + use datafusion::prelude::{CsvReadOptions, SessionContext}; |
| 24 | + use datafusion_substrait::logical_plan::consumer::from_substrait_plan; |
| 25 | + use std::fs::File; |
| 26 | + use std::io::BufReader; |
| 27 | + use substrait::proto::Plan; |
| 28 | + |
| 29 | + #[tokio::test] |
| 30 | + async fn function_compound_signature() -> Result<()> { |
| 31 | + // DataFusion currently produces Substrait that refers to functions only by their name. |
| 32 | + // However, the Substrait spec requires that functions be identified by their compound signature. |
| 33 | + // This test confirms that DataFusion is able to consume plans following the spec, even though |
| 34 | + // we don't yet produce such plans. |
| 35 | + // Once we start producing plans with compound signatures, this test can be replaced by the roundtrip tests. |
| 36 | + |
| 37 | + let ctx = create_context().await?; |
| 38 | + |
| 39 | + // File generated with substrait-java's Isthmus: |
| 40 | + // ./isthmus-cli/build/graal/isthmus "select not d from data" -c "create table data (d boolean)" |
| 41 | + let path = "tests/testdata/select_not_bool.substrait.json"; |
| 42 | + let proto = serde_json::from_reader::<_, Plan>(BufReader::new( |
| 43 | + File::open(path).expect("file not found"), |
| 44 | + )) |
| 45 | + .expect("failed to parse json"); |
| 46 | + |
| 47 | + let plan = from_substrait_plan(&ctx, &proto).await?; |
| 48 | + |
| 49 | + assert_eq!( |
| 50 | + format!("{:?}", plan), |
| 51 | + "Projection: NOT DATA.a\ |
| 52 | + \n TableScan: DATA projection=[a, b, c, d, e, f]" |
| 53 | + ); |
| 54 | + Ok(()) |
| 55 | + } |
| 56 | + |
| 57 | + async fn create_context() -> datafusion::common::Result<SessionContext> { |
| 58 | + let ctx = SessionContext::new(); |
| 59 | + ctx.register_csv("DATA", "tests/testdata/data.csv", CsvReadOptions::new()) |
| 60 | + .await?; |
| 61 | + Ok(ctx) |
| 62 | + } |
| 63 | +} |
0 commit comments