Skip to content

Apache DataFusion SQL Query Engine

Move FileType enum from sql module to logical_plan module (#2290)

Andy Grove8e5551fc03ac
diff --git a/ballista/rust/client/src/context.rs b/ballista/rust/client/src/context.rs
index 7dc7ec63b9..7d21b11216 100644
--- a/ballista/rust/client/src/context.rs
+++ b/ballista/rust/client/src/context.rs
@@ -34,11 +34,11 @@ use datafusion::catalog::TableReference;
use datafusion::dataframe::DataFrame;
use datafusion::datasource::TableProvider;
use datafusion::error::{DataFusionError, Result};
-use datafusion::logical_plan::{CreateExternalTable, LogicalPlan, TableScan};
+use datafusion::logical_plan::{CreateExternalTable, FileType, LogicalPlan, TableScan};
use datafusion::prelude::{
AvroReadOptions, CsvReadOptions, ParquetReadOptions, SessionConfig, SessionContext,
};
-use datafusion::sql::parser::{DFParser, FileType, Statement as DFStatement};
+use datafusion::sql::parser::{DFParser, Statement as DFStatement};
struct BallistaContextState {
/// Ballista configuration
diff --git a/ballista/rust/core/src/serde/logical_plan/from_proto.rs b/ballista/rust/core/src/serde/logical_plan/from_proto.rs
index afd9b268d2..a17c646caa 100644
--- a/ballista/rust/core/src/serde/logical_plan/from_proto.rs
+++ b/ballista/rust/core/src/serde/logical_plan/from_proto.rs
@@ -39,9 +39,9 @@ impl TryFrom<i32> for protobuf::FileType {
}
#[allow(clippy::from_over_into)]
-impl Into<datafusion::sql::parser::FileType> for protobuf::FileType {
- fn into(self) -> datafusion::sql::parser::FileType {
- use datafusion::sql::parser::FileType;
+impl Into<datafusion::logical_plan::FileType> for protobuf::FileType {
+ fn into(self) -> datafusion::logical_plan::FileType {
+ use datafusion::logical_plan::FileType;
match self {
protobuf::FileType::NdJson => FileType::NdJson,
protobuf::FileType::Parquet => FileType::Parquet,
diff --git a/ballista/rust/core/src/serde/logical_plan/mod.rs b/ballista/rust/core/src/serde/logical_plan/mod.rs
index a0264271a5..d88498b86f 100644
--- a/ballista/rust/core/src/serde/logical_plan/mod.rs
+++ b/ballista/rust/core/src/serde/logical_plan/mod.rs
@@ -818,7 +818,7 @@ impl AsLogicalPlan for LogicalPlanNode {
table_partition_cols,
if_not_exists,
}) => {
- use datafusion::sql::parser::FileType;
+ use datafusion::logical_plan::FileType;
let pb_file_type: protobuf::FileType = match file_type {
FileType::NdJson => protobuf::FileType::NdJson,
@@ -994,11 +994,10 @@ mod roundtrip_tests {
},
datasource::listing::ListingTable,
logical_plan::{
- col, CreateExternalTable, Expr, LogicalPlan, LogicalPlanBuilder, Repartition,
- ToDFSchema,
+ col, CreateExternalTable, Expr, FileType, LogicalPlan, LogicalPlanBuilder,
+ Repartition, ToDFSchema,
},
prelude::*,
- sql::parser::FileType,
};
use std::io;
use std::sync::Arc;
diff --git a/datafusion/core/src/execution/context.rs b/datafusion/core/src/execution/context.rs
index f7262def03..eae5319702 100644
--- a/datafusion/core/src/execution/context.rs
+++ b/datafusion/core/src/execution/context.rs
@@ -62,7 +62,8 @@ use crate::datasource::TableProvider;
use crate::error::{DataFusionError, Result};
use crate::logical_plan::{
CreateCatalog, CreateCatalogSchema, CreateExternalTable, CreateMemoryTable,
- DropTable, FunctionRegistry, LogicalPlan, LogicalPlanBuilder, UNNAMED_TABLE,
+ DropTable, FileType, FunctionRegistry, LogicalPlan, LogicalPlanBuilder,
+ UNNAMED_TABLE,
};
use crate::optimizer::common_subexpr_eliminate::CommonSubexprEliminate;
use crate::optimizer::filter_push_down::FilterPushDown;
@@ -86,7 +87,7 @@ use crate::physical_plan::udf::ScalarUDF;
use crate::physical_plan::ExecutionPlan;
use crate::physical_plan::PhysicalPlanner;
use crate::sql::{
- parser::{DFParser, FileType},
+ parser::DFParser,
planner::{ContextProvider, SqlToRel},
};
use crate::variable::{VarProvider, VarType};
diff --git a/datafusion/core/src/logical_plan/mod.rs b/datafusion/core/src/logical_plan/mod.rs
index cc5023008f..d2c0a1fa32 100644
--- a/datafusion/core/src/logical_plan/mod.rs
+++ b/datafusion/core/src/logical_plan/mod.rs
@@ -64,8 +64,9 @@ pub use extension::UserDefinedLogicalNode;
pub use operators::Operator;
pub use plan::{
CreateCatalog, CreateCatalogSchema, CreateExternalTable, CreateMemoryTable,
- CrossJoin, DropTable, EmptyRelation, JoinConstraint, JoinType, Limit, LogicalPlan,
- Partitioning, PlanType, PlanVisitor, Repartition, TableScan, Union, Values,
+ CrossJoin, DropTable, EmptyRelation, FileType, JoinConstraint, JoinType, Limit,
+ LogicalPlan, Partitioning, PlanType, PlanVisitor, Repartition, TableScan, Union,
+ Values,
};
pub(crate) use plan::{StringifiedPlan, ToStringifiedPlan};
pub use registry::FunctionRegistry;
diff --git a/datafusion/core/src/logical_plan/plan.rs b/datafusion/core/src/logical_plan/plan.rs
index 66307c6aba..72fd3fa284 100644
--- a/datafusion/core/src/logical_plan/plan.rs
+++ b/datafusion/core/src/logical_plan/plan.rs
@@ -24,7 +24,6 @@ use crate::datasource::datasource::TableProviderFilterPushDown;
use crate::datasource::TableProvider;
use crate::error::DataFusionError;
use crate::logical_plan::dfschema::DFSchemaRef;
-use crate::sql::parser::FileType;
use arrow::datatypes::{DataType, Field, Schema, SchemaRef};
use std::fmt::Formatter;
use std::{
@@ -184,6 +183,19 @@ pub struct CreateMemoryTable {
pub if_not_exists: bool,
}
+/// Types of files to parse as DataFrames
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub enum FileType {
+ /// Newline-delimited JSON
+ NdJson,
+ /// Apache Parquet columnar storage
+ Parquet,
+ /// Comma separated values
+ CSV,
+ /// Avro binary records
+ Avro,
+}
+
/// Creates an external table.
#[derive(Clone)]
pub struct CreateExternalTable {
diff --git a/datafusion/core/src/sql/parser.rs b/datafusion/core/src/sql/parser.rs
index 2b98a3090a..0f4596fe6d 100644
--- a/datafusion/core/src/sql/parser.rs
+++ b/datafusion/core/src/sql/parser.rs
@@ -19,6 +19,7 @@
//!
//! Declares a SQL parser based on sqlparser that handles custom formats that we need.
+use crate::logical_plan::FileType;
use sqlparser::{
ast::{ColumnDef, ColumnOptionDef, Statement as SQLStatement, TableConstraint},
dialect::{keywords::Keyword, Dialect, GenericDialect},
@@ -35,19 +36,6 @@ macro_rules! parser_err {
};
}
-/// Types of files to parse as DataFrames
-#[derive(Debug, Clone, Copy, PartialEq)]
-pub enum FileType {
- /// Newline-delimited JSON
- NdJson,
- /// Apache Parquet columnar storage
- Parquet,
- /// Comma separated values
- CSV,
- /// Avro binary records
- Avro,
-}
-
impl FromStr for FileType {
type Err = ParserError;
diff --git a/datafusion/core/src/sql/planner.rs b/datafusion/core/src/sql/planner.rs
index 2f2bdc5feb..a60f8c2f85 100644
--- a/datafusion/core/src/sql/planner.rs
+++ b/datafusion/core/src/sql/planner.rs
@@ -31,8 +31,8 @@ use crate::logical_plan::{
and, builder::expand_qualified_wildcard, builder::expand_wildcard, col, lit,
normalize_col, union_with_alias, Column, CreateCatalog, CreateCatalogSchema,
CreateExternalTable as PlanCreateExternalTable, CreateMemoryTable, DFSchema,
- DFSchemaRef, DropTable, Expr, LogicalPlan, LogicalPlanBuilder, Operator, PlanType,
- ToDFSchema, ToStringifiedPlan,
+ DFSchemaRef, DropTable, Expr, FileType, LogicalPlan, LogicalPlanBuilder, Operator,
+ PlanType, ToDFSchema, ToStringifiedPlan,
};
use crate::optimizer::utils::exprlist_to_columns;
use crate::prelude::JoinType;
@@ -43,7 +43,7 @@ use crate::{
physical_plan::aggregates,
physical_plan::udaf::AggregateUDF,
physical_plan::udf::ScalarUDF,
- sql::parser::{CreateExternalTable, FileType, Statement as DFStatement},
+ sql::parser::{CreateExternalTable, Statement as DFStatement},
};
use arrow::datatypes::*;
use datafusion_expr::{window_function::WindowFunction, BuiltinScalarFunction};