Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ rstest = "0.28.0"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sha2 = "^0.11.0"
sqlparser = { version = "0.63.0", default-features = false, features = ["std", "visitor"] }
sqlparser = { version = "0.64.0", git = "https://github.com/apache/datafusion-sqlparser-rs", rev = "ba850faff0d7bde0193e4c8635fdf5155a801d97", default-features = false, features = [
"std",
"visitor",
] }
stacker = "0.1.24"
strum = "0.28.0"
strum_macros = "0.28.0"
Expand Down
6 changes: 4 additions & 2 deletions datafusion-examples/examples/relation_planner/table_sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ impl RelationPlanner for TableSamplePlanner {
with_ordinality,
partitions,
json_path,
index_hints,
index_directives,
inheritance,
} = relation
else {
return Ok(RelationPlanning::Original(Box::new(relation)));
Expand Down Expand Up @@ -371,7 +372,8 @@ impl RelationPlanner for TableSamplePlanner {
with_ordinality,
partitions,
json_path,
index_hints,
index_directives,
inheritance,
};
let input = context.plan(base_relation)?;

Expand Down
42 changes: 30 additions & 12 deletions datafusion/sql/src/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use datafusion_expr::planner::{
use sqlparser::ast::{
AccessExpr, BinaryOperator, CastFormat, CastKind, CeilFloorKind,
DataType as SQLDataType, DateTimeField, DictionaryField, Expr as SQLExpr,
ExprWithAlias as SQLExprWithAlias, JsonPath, JsonPathElem, MapEntry, Spanned,
StructField, Subscript, TrimWhereField, TypedString, Value, ValueWithSpan,
ExprWithAlias as SQLExprWithAlias, InTarget, JsonPath, JsonPathElem, MapEntry,
Spanned, StructField, Subscript, TrimWhereField, TypedString, Value, ValueWithSpan,
};
use sqlparser::ast::{Query, Visit, Visitor};

Expand Down Expand Up @@ -584,11 +584,36 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
)?),
))),

SQLExpr::InList {
SQLExpr::In {
expr,
list,
target,
negated,
} => self.sql_in_list_to_expr(*expr, list, negated, schema, planner_context),
global,
} => {
if global {
return not_impl_err!("GLOBAL IN is not supported");
}
match target {
InTarget::List(list) => self.sql_in_list_to_expr(
*expr,
list,
negated,
schema,
planner_context,
),
InTarget::Subquery(subquery) => self.parse_in_subquery(
*expr,
*subquery,
negated,
schema,
planner_context,
),
InTarget::Unnest(_) => not_impl_err!("IN UNNEST is not supported"),
InTarget::Table { .. } => {
not_impl_err!("IN <table name> is not supported")
}
}
}

SQLExpr::Like {
negated,
Expand Down Expand Up @@ -732,13 +757,6 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
SQLExpr::Exists { subquery, negated } => {
self.parse_exists_subquery(*subquery, negated, schema, planner_context)
}
SQLExpr::InSubquery {
expr,
subquery,
negated,
} => {
self.parse_in_subquery(*expr, *subquery, negated, schema, planner_context)
}
SQLExpr::Subquery(subquery) => {
self.parse_scalar_subquery(*subquery, schema, planner_context)
}
Expand Down
9 changes: 9 additions & 0 deletions datafusion/sql/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,9 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
| SQLDataType::FixedString(_)
| SQLDataType::Tuple(_)
| SQLDataType::Nested(_)
| SQLDataType::Object(_)
| SQLDataType::Zerofill(_)
| SQLDataType::Collate(_, _)
| SQLDataType::Union(_)
| SQLDataType::Nullable(_)
| SQLDataType::LowCardinality(_)
Expand All @@ -932,6 +935,12 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
| SQLDataType::TsVector
| SQLDataType::TsQuery
| SQLDataType::GeometricType(_)
| SQLDataType::NationalCharacter(_)
| SQLDataType::NationalCharacterVarying(_)
| SQLDataType::NationalChar(_)
| SQLDataType::NationalCharVarying(_)
| SQLDataType::Nchar(_)
| SQLDataType::NcharVarying(_)
| SQLDataType::DecimalUnsigned(_) // deprecated mysql type
| SQLDataType::FloatUnsigned(_) // deprecated mysql type
| SQLDataType::RealUnsigned // deprecated mysql type
Expand Down
6 changes: 6 additions & 0 deletions datafusion/sql/src/relation/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
.asof_join_on(right, None, match_condition)?
.build(),
JoinConstraint::Natural => plan_err!("NATURAL ASOF JOIN is not supported"),
JoinConstraint::UsingAlias(_, _) => {
not_impl_err!("USING (...) AS alias is not supported")
}
}
}

Expand Down Expand Up @@ -218,6 +221,9 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
.join_using(right, join_type, keys)?
.build()
}
JoinConstraint::UsingAlias(_, _) => {
not_impl_err!("USING (...) AS alias is not supported")
}
JoinConstraint::Natural => {
let left_cols: HashSet<&String> =
left.schema().fields().iter().map(|f| f.name()).collect();
Expand Down
70 changes: 63 additions & 7 deletions datafusion/sql/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ fn calc_inline_constraints_from_columns(columns: &[ColumnDef]) -> Vec<TableConst
include: _include,
index_options: _index_options,
nulls_distinct: _nulls_distinct,
on_conflict,
}) => constraints.push(TableConstraint::Unique(UniqueConstraint {
name: name.clone(),
index_name: None,
Expand All @@ -128,6 +129,7 @@ fn calc_inline_constraints_from_columns(columns: &[ColumnDef]) -> Vec<TableConst
index_options: vec![],
characteristics: *characteristics,
nulls_distinct: NullsDistinctOption::None,
on_conflict: *on_conflict,
})),
ast::ColumnOption::PrimaryKey(PrimaryKeyConstraint {
characteristics,
Expand All @@ -137,6 +139,7 @@ fn calc_inline_constraints_from_columns(columns: &[ColumnDef]) -> Vec<TableConst
columns: _columns,
include: _include,
index_options: _index_options,
on_conflict,
}) => {
constraints.push(TableConstraint::PrimaryKey(PrimaryKeyConstraint {
name: name.clone(),
Expand All @@ -156,6 +159,7 @@ fn calc_inline_constraints_from_columns(columns: &[ColumnDef]) -> Vec<TableConst
include: vec![],
index_options: vec![],
characteristics: *characteristics,
on_conflict: *on_conflict,
}))
}
ast::ColumnOption::ForeignKey(ForeignKeyConstraint {
Expand Down Expand Up @@ -186,11 +190,13 @@ fn calc_inline_constraints_from_columns(columns: &[ColumnDef]) -> Vec<TableConst
expr,
no_inherit: _no_inherit,
enforced: _enforced,
on_conflict,
}) => constraints.push(TableConstraint::Check(CheckConstraint {
name: name.clone(),
expr: expr.clone(),
no_inherit: false,
enforced: None,
on_conflict: *on_conflict,
})),
ast::ColumnOption::Default(_)
| ast::ColumnOption::Null
Expand All @@ -200,6 +206,7 @@ fn calc_inline_constraints_from_columns(columns: &[ColumnDef]) -> Vec<TableConst
| ast::ColumnOption::Generated { .. }
| ast::ColumnOption::Comment(_)
| ast::ColumnOption::Options(_)
| ast::ColumnOption::GenericOptions(_)
| ast::ColumnOption::OnUpdate(_)
| ast::ColumnOption::Materialized(_)
| ast::ColumnOption::Ephemeral(_)
Expand Down Expand Up @@ -312,7 +319,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
constraints,
if_not_exists,
or_replace,
without_rowid,
sqlite_table_options,
like,
clone,
comment,
Expand All @@ -323,7 +330,6 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
partition_by,
cluster_by,
clustered_by,
strict,
copy_grants,
enable_schema_evolution,
change_tracking,
Expand All @@ -350,6 +356,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
require_user,
partition_of,
for_values,
of_type,
snapshot,
with_storage_lifecycle_policy,
diststyle,
Expand Down Expand Up @@ -401,7 +408,10 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
if location.is_some() {
return not_impl_err!("Location not supported");
}
if without_rowid {
if sqlite_table_options
.options
.contains(&ast::SqliteTableOption::WithoutRowid)
{
return not_impl_err!("Without rowid not supported");
}
if like.is_some() {
Expand Down Expand Up @@ -434,7 +444,10 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
if clustered_by.is_some() {
return not_impl_err!("Clustered by not supported");
}
if strict {
if sqlite_table_options
.options
.contains(&ast::SqliteTableOption::Strict)
{
return not_impl_err!("Strict not supported");
}
if copy_grants {
Expand Down Expand Up @@ -514,6 +527,9 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
if for_values.is_some() {
return not_impl_err!("PARTITION OF .. FOR VALUES .. not supported");
}
if of_type.is_some() {
return not_impl_err!("Typed tables not supported");
}
if snapshot {
return not_impl_err!("Snapshot tables not supported");
}
Expand Down Expand Up @@ -1057,6 +1073,8 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
source,
partitioned,
after_columns,
by_name,
overriding,
table,
on,
returning,
Expand Down Expand Up @@ -1102,6 +1120,12 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
if !after_columns.is_empty() {
plan_err!("After-columns clause not supported")?;
}
if by_name {
plan_err!("INSERT BY NAME not supported")?;
}
if overriding.is_some() {
plan_err!("Insert-overriding clause not supported")?;
}
if on.is_some() {
plan_err!("Insert-on clause not supported")?;
}
Expand Down Expand Up @@ -1166,7 +1190,15 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
optimizer_hints,
output,
order_by,
on_cluster,
settings,
}) => {
if on_cluster.is_some() {
plan_err!("UPDATE ON CLUSTER not supported")?;
}
if settings.is_some() {
plan_err!("Update with settings not supported")?;
}
let from_clauses =
from.map(|update_table_from_kind| match update_table_from_kind {
UpdateTableFromKind::BeforeSet(from_clauses) => from_clauses,
Expand Down Expand Up @@ -1218,10 +1250,18 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
delete_token: _,
optimizer_hints,
output,
on_cluster,
settings,
}) => {
if !tables.is_empty() {
plan_err!("DELETE <TABLE> not supported")?;
}
if on_cluster.is_some() {
plan_err!("DELETE ON CLUSTER not supported")?;
}
if settings.is_some() {
plan_err!("Delete with settings not supported")?;
}

if using.is_some() {
plan_err!("Using clause not supported")?;
Expand Down Expand Up @@ -1466,7 +1506,8 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
ast::CreateFunctionBody::AsBeforeOptions{body: expr, link_symbol: _link_symbol} => expr,
ast::CreateFunctionBody::AsAfterOptions(expr) => expr,
ast::CreateFunctionBody::Return(expr) => expr,
ast::CreateFunctionBody::AsBeginEnd(_) => {
ast::CreateFunctionBody::AsBeginEnd(_)
| ast::CreateFunctionBody::BeginAtomic(_) => {
return not_impl_err!(
"BEGIN/END enclosed function body syntax is not supported"
)?;
Expand Down Expand Up @@ -1992,7 +2033,11 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
index_options: _,
characteristics: _,
nulls_distinct: _,
on_conflict,
}) => {
if on_conflict.is_some() {
return _plan_err!("ON CONFLICT on constraints is not supported");
}
let constraint_name = match &name {
Some(name) => &format!("unique constraint with name '{name}'"),
None => "unique constraint",
Expand All @@ -2013,7 +2058,11 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
include: _,
index_options: _,
characteristics: _,
on_conflict,
}) => {
if on_conflict.is_some() {
return _plan_err!("ON CONFLICT on constraints is not supported");
}
// Get primary key indices in the schema
let indices = self.get_constraint_column_indices(
df_schema,
Expand All @@ -2031,6 +2080,11 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
TableConstraint::Check { .. } => {
_plan_err!("Check constraints are not currently supported")
}
TableConstraint::NotNull(_) => {
_plan_err!(
"Table-level NOT NULL constraints are not currently supported"
)
}
TableConstraint::Index { .. } => {
_plan_err!("Indexes are not currently supported")
}
Expand Down Expand Up @@ -2472,7 +2526,8 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
partitions,
json_path,
sample,
index_hints,
index_directives,
inheritance,
} => {
if alias
.as_ref()
Expand All @@ -2489,7 +2544,8 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
|| !partitions.is_empty()
|| json_path.is_some()
|| sample.is_some()
|| !index_hints.is_empty()
|| !index_directives.is_empty()
|| inheritance.is_some()
{
return not_impl_err!(
"MERGE target table modifiers are not supported"
Expand Down
Loading