forked from apache/datafusion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some initial content about creating logical plans (apache#7952)
- Loading branch information
Showing
8 changed files
with
264 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# 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. | ||
|
||
[package] | ||
name = "datafusion-docs-tests" | ||
description = "DataFusion Documentation Tests" | ||
publish = false | ||
version = { workspace = true } | ||
edition = { workspace = true } | ||
readme = { workspace = true } | ||
homepage = { workspace = true } | ||
repository = { workspace = true } | ||
license = { workspace = true } | ||
authors = { workspace = true } | ||
rust-version = "1.70" | ||
|
||
[dependencies] | ||
datafusion = { path = "../datafusion/core", version = "32.0.0", default-features = false } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// 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. | ||
|
||
#[cfg(test)] | ||
mod library_logical_plan; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// 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. | ||
|
||
use datafusion::arrow::datatypes::{DataType, Field, Schema, SchemaRef}; | ||
use datafusion::error::Result; | ||
use datafusion::logical_expr::builder::LogicalTableSource; | ||
use datafusion::logical_expr::{Filter, LogicalPlan, LogicalPlanBuilder, TableScan}; | ||
use datafusion::prelude::*; | ||
use std::sync::Arc; | ||
|
||
#[test] | ||
fn plan_1() -> Result<()> { | ||
// create a logical table source | ||
let schema = Schema::new(vec![ | ||
Field::new("id", DataType::Int32, true), | ||
Field::new("name", DataType::Utf8, true), | ||
]); | ||
let table_source = LogicalTableSource::new(SchemaRef::new(schema)); | ||
|
||
// create a TableScan plan | ||
let projection = None; // optional projection | ||
let filters = vec![]; // optional filters to push down | ||
let fetch = None; // optional LIMIT | ||
let table_scan = LogicalPlan::TableScan(TableScan::try_new( | ||
"person", | ||
Arc::new(table_source), | ||
projection, | ||
filters, | ||
fetch, | ||
)?); | ||
|
||
// create a Filter plan that evaluates `id > 500` and wraps the TableScan | ||
let filter_expr = col("id").gt(lit(500)); | ||
let plan = LogicalPlan::Filter(Filter::try_new(filter_expr, Arc::new(table_scan))?); | ||
|
||
// print the plan | ||
println!("{}", plan.display_indent_schema()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn plan_builder_1() -> Result<()> { | ||
// create a logical table source | ||
let schema = Schema::new(vec![ | ||
Field::new("id", DataType::Int32, true), | ||
Field::new("name", DataType::Utf8, true), | ||
]); | ||
let table_source = LogicalTableSource::new(SchemaRef::new(schema)); | ||
|
||
// optional projection | ||
let projection = None; | ||
|
||
// create a LogicalPlanBuilder for a table scan | ||
let builder = LogicalPlanBuilder::scan("person", Arc::new(table_source), projection)?; | ||
|
||
// perform a filter that evaluates `id > 500`, and build the plan | ||
let plan = builder.filter(col("id").gt(lit(500)))?.build()?; | ||
|
||
// print the plan | ||
println!("{}", plan.display_indent_schema()); | ||
|
||
Ok(()) | ||
} |