mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-14 20:10:37 +00:00
chore: upgrade DataFusion family, again (#7578)
* chore: upgrade DataFusion family Signed-off-by: luofucong <luofc@foxmail.com> * chore: switch to released version of datafusion-pg-catalog --------- Signed-off-by: luofucong <luofc@foxmail.com> Co-authored-by: Ning Sun <sunning@greptime.com> Co-authored-by: Ning Sun <sunng@protonmail.com>
This commit is contained in:
@@ -25,7 +25,10 @@ use datatypes::arrow::datatypes::{DataType as ArrowDataType, IntervalUnit};
|
||||
use datatypes::data_type::ConcreteDataType;
|
||||
use itertools::Itertools;
|
||||
use snafu::{OptionExt, ResultExt, ensure};
|
||||
use sqlparser::ast::{ColumnOption, ColumnOptionDef, DataType, Expr};
|
||||
use sqlparser::ast::{
|
||||
ColumnOption, ColumnOptionDef, DataType, Expr, KeyOrIndexDisplay, NullsDistinctOption,
|
||||
PrimaryKeyConstraint, UniqueConstraint,
|
||||
};
|
||||
use sqlparser::dialect::keywords::Keyword;
|
||||
use sqlparser::keywords::ALL_KEYWORDS;
|
||||
use sqlparser::parser::IsOptional::Mandatory;
|
||||
@@ -717,15 +720,25 @@ impl<'a> ParserContext<'a> {
|
||||
parser.parse_expr().context(SyntaxSnafu)?,
|
||||
)))
|
||||
} else if parser.parse_keywords(&[Keyword::PRIMARY, Keyword::KEY]) {
|
||||
Ok(Some(ColumnOption::Unique {
|
||||
is_primary: true,
|
||||
Ok(Some(ColumnOption::PrimaryKey(PrimaryKeyConstraint {
|
||||
name: None,
|
||||
index_name: None,
|
||||
index_type: None,
|
||||
columns: vec![],
|
||||
index_options: vec![],
|
||||
characteristics: None,
|
||||
}))
|
||||
})))
|
||||
} else if parser.parse_keyword(Keyword::UNIQUE) {
|
||||
Ok(Some(ColumnOption::Unique {
|
||||
is_primary: false,
|
||||
Ok(Some(ColumnOption::Unique(UniqueConstraint {
|
||||
name: None,
|
||||
index_name: None,
|
||||
index_type_display: KeyOrIndexDisplay::None,
|
||||
index_type: None,
|
||||
columns: vec![],
|
||||
index_options: vec![],
|
||||
characteristics: None,
|
||||
}))
|
||||
nulls_distinct: NullsDistinctOption::None,
|
||||
})))
|
||||
} else if parser.parse_keywords(&[Keyword::TIME, Keyword::INDEX]) {
|
||||
// Use a DialectSpecific option for time index
|
||||
Ok(Some(ColumnOption::DialectSpecific(vec![
|
||||
|
||||
@@ -23,8 +23,11 @@ use crate::statements::statement::Statement;
|
||||
/// DELETE statement parser implementation
|
||||
impl ParserContext<'_> {
|
||||
pub(crate) fn parse_delete(&mut self) -> Result<Statement> {
|
||||
let _ = self.parser.next_token();
|
||||
let spstatement = self.parser.parse_delete().context(error::SyntaxSnafu)?;
|
||||
let token = self.parser.next_token();
|
||||
let spstatement = self
|
||||
.parser
|
||||
.parse_delete(token)
|
||||
.context(error::SyntaxSnafu)?;
|
||||
|
||||
match spstatement {
|
||||
SpStatement::Delete { .. } => {
|
||||
|
||||
@@ -69,6 +69,7 @@ mod tests {
|
||||
|
||||
let select = sqlparser::ast::Select {
|
||||
distinct: None,
|
||||
select_modifiers: None,
|
||||
top: None,
|
||||
projection: vec![sqlparser::ast::SelectItem::Wildcard(
|
||||
WildcardAdditionalOptions::default(),
|
||||
@@ -103,9 +104,10 @@ mod tests {
|
||||
top_before_distinct: false,
|
||||
prewhere: None,
|
||||
window_before_qualify: false,
|
||||
connect_by: None,
|
||||
connect_by: vec![],
|
||||
select_token: AttachedToken::empty(),
|
||||
flavor: SelectFlavor::Standard,
|
||||
optimizer_hint: None,
|
||||
};
|
||||
|
||||
let sp_query = Box::new(
|
||||
|
||||
@@ -23,8 +23,11 @@ use crate::statements::statement::Statement;
|
||||
/// INSERT/REPLACE statement parser implementation
|
||||
impl ParserContext<'_> {
|
||||
pub(crate) fn parse_insert(&mut self) -> Result<Statement> {
|
||||
let _ = self.parser.next_token();
|
||||
let spstatement = self.parser.parse_insert().context(error::SyntaxSnafu)?;
|
||||
let token = self.parser.next_token();
|
||||
let spstatement = self
|
||||
.parser
|
||||
.parse_insert(token)
|
||||
.context(error::SyntaxSnafu)?;
|
||||
|
||||
match spstatement {
|
||||
SpStatement::Insert { .. } => {
|
||||
@@ -38,8 +41,11 @@ impl ParserContext<'_> {
|
||||
}
|
||||
|
||||
pub(crate) fn parse_replace(&mut self) -> Result<Statement> {
|
||||
let _ = self.parser.next_token();
|
||||
let spstatement = self.parser.parse_insert().context(error::SyntaxSnafu)?;
|
||||
let token = self.parser.next_token();
|
||||
let spstatement = self
|
||||
.parser
|
||||
.parse_insert(token)
|
||||
.context(error::SyntaxSnafu)?;
|
||||
|
||||
match spstatement {
|
||||
SpStatement::Insert(mut insert_stmt) => {
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use chrono::Utc;
|
||||
use datafusion::config::ConfigOptions;
|
||||
use datafusion::error::Result as DfResult;
|
||||
use datafusion::execution::SessionStateBuilder;
|
||||
@@ -23,7 +22,6 @@ use datafusion::execution::context::SessionState;
|
||||
use datafusion::optimizer::simplify_expressions::ExprSimplifier;
|
||||
use datafusion_common::tree_node::{TreeNode, TreeNodeVisitor};
|
||||
use datafusion_common::{DFSchema, ScalarValue};
|
||||
use datafusion_expr::execution_props::ExecutionProps;
|
||||
use datafusion_expr::simplify::SimplifyContext;
|
||||
use datafusion_expr::{AggregateUDF, Expr, ScalarUDF, TableSource, WindowUDF};
|
||||
use datafusion_sql::TableReference;
|
||||
@@ -130,10 +128,7 @@ pub fn parser_expr_to_scalar_value_literal(
|
||||
}
|
||||
|
||||
// 2. simplify logical expr
|
||||
let execution_props = ExecutionProps::new().with_query_execution_start_time(Utc::now());
|
||||
let info =
|
||||
SimplifyContext::new(&execution_props).with_schema(Arc::new(empty_df_schema.clone()));
|
||||
|
||||
let info = SimplifyContext::default().with_current_time();
|
||||
let simplifier = ExprSimplifier::new(info);
|
||||
|
||||
// Coerce the logical expression so simplifier can handle it correctly. This is necessary for const eval with possible type mismatch. i.e.: `now() - now() + '15s'::interval` which is `TimestampNanosecond - TimestampNanosecond + IntervalMonthDayNano`.
|
||||
@@ -293,8 +288,6 @@ pub fn parse_with_options(parser: &mut Parser) -> Result<OptionMap> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
|
||||
use chrono::DateTime;
|
||||
use datafusion::functions::datetime::expr_fn::now;
|
||||
use datafusion_expr::lit;
|
||||
@@ -343,9 +336,7 @@ mod tests {
|
||||
),
|
||||
];
|
||||
|
||||
let execution_props = ExecutionProps::new().with_query_execution_start_time(now_time);
|
||||
let info = SimplifyContext::new(&execution_props).with_schema(Arc::new(DFSchema::empty()));
|
||||
|
||||
let info = SimplifyContext::default().with_query_execution_start_time(Some(now_time));
|
||||
let simplifier = ExprSimplifier::new(info);
|
||||
for (expr, expected) in testcases {
|
||||
let expr_name = expr.schema_name().to_string();
|
||||
|
||||
@@ -114,6 +114,7 @@ impl ParserContext<'_> {
|
||||
match cte.content {
|
||||
CteContent::Sql(body) => sql_cte_tables.push(Cte {
|
||||
alias: TableAlias {
|
||||
explicit: false,
|
||||
name: cte.name,
|
||||
columns: cte
|
||||
.columns
|
||||
|
||||
@@ -91,10 +91,7 @@ pub fn has_primary_key_option(column_def: &ColumnDef) -> bool {
|
||||
column_def
|
||||
.options
|
||||
.iter()
|
||||
.any(|options| match options.option {
|
||||
ColumnOption::Unique { is_primary, .. } => is_primary,
|
||||
_ => false,
|
||||
})
|
||||
.any(|options| matches!(options.option, ColumnOption::PrimaryKey(..)))
|
||||
}
|
||||
|
||||
/// Create a `ColumnSchema` from `Column`.
|
||||
@@ -198,15 +195,10 @@ pub fn sql_column_def_to_grpc_column_def(
|
||||
.context(ConvertToGrpcDataTypeSnafu)?
|
||||
.to_parts();
|
||||
|
||||
let is_primary_key = col.options.iter().any(|o| {
|
||||
matches!(
|
||||
o.option,
|
||||
ColumnOption::Unique {
|
||||
is_primary: true,
|
||||
..
|
||||
}
|
||||
)
|
||||
});
|
||||
let is_primary_key = col
|
||||
.options
|
||||
.iter()
|
||||
.any(|o| matches!(o.option, ColumnOption::PrimaryKey(..)));
|
||||
|
||||
let semantic_type = if is_primary_key {
|
||||
SemanticType::Tag
|
||||
@@ -375,7 +367,7 @@ mod tests {
|
||||
use datatypes::schema::{
|
||||
COLUMN_FULLTEXT_OPT_KEY_ANALYZER, COLUMN_FULLTEXT_OPT_KEY_CASE_SENSITIVE, FulltextAnalyzer,
|
||||
};
|
||||
use sqlparser::ast::{ColumnOptionDef, Expr};
|
||||
use sqlparser::ast::{ColumnOptionDef, Expr, PrimaryKeyConstraint};
|
||||
|
||||
use super::*;
|
||||
use crate::ast::TimezoneInfo;
|
||||
@@ -505,10 +497,14 @@ mod tests {
|
||||
data_type: SqlDataType::Double(ExactNumberInfo::None),
|
||||
options: vec![ColumnOptionDef {
|
||||
name: None,
|
||||
option: ColumnOption::Unique {
|
||||
is_primary: true,
|
||||
option: ColumnOption::PrimaryKey(PrimaryKeyConstraint {
|
||||
name: None,
|
||||
index_name: None,
|
||||
index_type: None,
|
||||
columns: vec![],
|
||||
index_options: vec![],
|
||||
characteristics: None,
|
||||
},
|
||||
}),
|
||||
}],
|
||||
};
|
||||
|
||||
@@ -583,10 +579,14 @@ mod tests {
|
||||
data_type: SqlDataType::Double(ExactNumberInfo::None),
|
||||
options: vec![ColumnOptionDef {
|
||||
name: None,
|
||||
option: ColumnOption::Unique {
|
||||
is_primary: true,
|
||||
option: ColumnOption::PrimaryKey(PrimaryKeyConstraint {
|
||||
name: None,
|
||||
index_name: None,
|
||||
index_type: None,
|
||||
columns: vec![],
|
||||
index_options: vec![],
|
||||
characteristics: None,
|
||||
},
|
||||
}),
|
||||
}],
|
||||
};
|
||||
assert!(has_primary_key_option(&column_def));
|
||||
|
||||
@@ -111,6 +111,7 @@ impl TransformRule for ExpandIntervalTransformRule {
|
||||
Expr::Cast {
|
||||
expr: cast_exp,
|
||||
data_type,
|
||||
array,
|
||||
kind,
|
||||
format,
|
||||
} => {
|
||||
@@ -130,6 +131,7 @@ impl TransformRule for ExpandIntervalTransformRule {
|
||||
kind: kind.clone(),
|
||||
expr: single_quoted_string_expr(interval_value),
|
||||
data_type: data_type.clone(),
|
||||
array: *array,
|
||||
format: std::mem::take(format),
|
||||
}
|
||||
}
|
||||
@@ -396,6 +398,7 @@ mod tests {
|
||||
fields: None,
|
||||
precision: None,
|
||||
},
|
||||
array: false,
|
||||
format: None,
|
||||
kind: sqlparser::ast::CastKind::Cast,
|
||||
};
|
||||
@@ -414,6 +417,7 @@ mod tests {
|
||||
fields: None,
|
||||
precision: None,
|
||||
},
|
||||
array: false,
|
||||
format: None,
|
||||
}
|
||||
);
|
||||
@@ -421,6 +425,7 @@ mod tests {
|
||||
let mut cast_to_i64_expr = Expr::Cast {
|
||||
expr: single_quoted_string_expr("5".to_string()),
|
||||
data_type: DataType::Int64,
|
||||
array: false,
|
||||
format: None,
|
||||
kind: sqlparser::ast::CastKind::Cast,
|
||||
};
|
||||
@@ -431,6 +436,7 @@ mod tests {
|
||||
Expr::Cast {
|
||||
expr: single_quoted_string_expr("5".to_string()),
|
||||
data_type: DataType::Int64,
|
||||
array: false,
|
||||
format: None,
|
||||
kind: sqlparser::ast::CastKind::Cast,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user