andygrove commented on code in PR #7952:
URL: https://github.com/apache/arrow-datafusion/pull/7952#discussion_r1375268473
##########
docs/source/library-user-guide/building-logical-plans.md:
##########
@@ -19,4 +19,135 @@
# Building Logical Plans
-Coming Soon
+A logical plan is a structured representation of a database query that
describes the high-level operations and
+transformations needed to retrieve data from a database or data source. It
abstracts away specific implementation
+details and focuses on the logical flow of the query, including operations
like filtering, sorting, and joining tables.
+
+This logical plan serves as an intermediate step before generating an
optimized physical execution plan.
+
+## Building Logical Plans Manually
+
+DataFusion's [LogicalPlan] is an enum containing variants representing all the
supported operators, and also
+contains an `Extension` variant that allows projects building on DataFusion to
add custom logical operators.
+
+It is possible to create logical plans by directly creating instances of the
[LogicalPlan] enum as follows, but is is
+much easier to use the [LogicalPlanBuilder], which is described in the next
section.
+
+Here is an example of building a logical plan directly:
+
+<!-- source for this example is in
datafusion_docs::library_logical_plan::plan_1 -->
+
+```rust
+// 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 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
Review Comment:
I'll address this one in a future PR once I have the initial automation in
place - I need to implement some code so that I have more control over which
code from the test makes it into the docs
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]