Skip to content

Commit

Permalink
feat: allow nest range expr in Range Query (#2557)
Browse files Browse the repository at this point in the history
* feat: eable range expr nest

* fix: change range expr rewrite format

* chore: organize range query tests

* chore: change range expr name(e.g. MAX(v) RANGE 5s FILL 6)

* chore: add range query test

* chore: fix code advice

* chore: fix ca
  • Loading branch information
Taylor-lagrange authored Oct 18, 2023
1 parent a7507a2 commit 46e106b
Show file tree
Hide file tree
Showing 22 changed files with 1,499 additions and 661 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
smallvec = "1"
snafu = { version = "0.7", features = ["backtraces"] }
sqlparser = { git = "https://github.com/GreptimeTeam/sqlparser-rs.git", rev = "296a4f6c73b129d6f565a42a2e5e53c6bc2b9da4", features = [
sqlparser = { git = "https://github.com/GreptimeTeam/sqlparser-rs.git", rev = "6cf9d23d5b8fbecd65efc1d9afb7e80ad7a424da", features = [
"visitor",
] }
strum = { version = "0.25", features = ["derive"] }
Expand Down
12 changes: 9 additions & 3 deletions src/common/function/src/scalars/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ impl Function for RangeFunction {
"range_fn"
}

// range_fn will never been used, return_type could be arbitrary value, is not important
fn return_type(&self, _input_types: &[ConcreteDataType]) -> Result<ConcreteDataType> {
Ok(ConcreteDataType::float64_datatype())
// The first argument to range_fn is the expression to be evaluated
fn return_type(&self, input_types: &[ConcreteDataType]) -> Result<ConcreteDataType> {
input_types
.first()
.cloned()
.ok_or(DataFusionError::Internal(
"No expr found in range_fn".into(),
))
.context(GeneralDataFusionSnafu)
}

/// `range_fn` will never been used. As long as a legal signature is returned, the specific content of the signature does not matter.
Expand Down
7 changes: 6 additions & 1 deletion src/query/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,19 @@ pub enum Error {

#[snafu(display("Missing table mutation handler"))]
MissingTableMutationHandler { location: Location },

#[snafu(display("Range Query: {}", msg))]
RangeQuery { msg: String, location: Location },
}

impl ErrorExt for Error {
fn status_code(&self) -> StatusCode {
use Error::*;

match self {
QueryParse { .. } | MultipleStatements { .. } => StatusCode::InvalidSyntax,
QueryParse { .. } | MultipleStatements { .. } | RangeQuery { .. } => {
StatusCode::InvalidSyntax
}
UnsupportedExpr { .. }
| Unimplemented { .. }
| CatalogNotFound { .. }
Expand Down
2 changes: 1 addition & 1 deletion src/query/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl DfLogicalPlanner {
let result = sql_to_rel
.statement_to_plan(df_stmt)
.context(PlanSqlSnafu)?;
let plan = RangePlanRewriter::new(table_provider, context_provider)
let plan = RangePlanRewriter::new(table_provider)
.rewrite(result)
.await?;
Ok(LogicalPlan::DfPlan(plan))
Expand Down
Loading

0 comments on commit 46e106b

Please sign in to comment.