forked from apache/horaedb
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support rewrite basic raw query in influxql (apache#683)
* draft. * implement influxql stmt rewriter. * add tests. * address CR.
- Loading branch information
Showing
10 changed files
with
860 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2023 CeresDB Project Authors. Licensed under Apache-2.0. | ||
|
||
//! Influxql processing | ||
pub mod planner; | ||
pub(crate) mod stmt_rewriter; | ||
pub(crate) mod util; | ||
pub mod error { | ||
use common_util::error::GenericError; | ||
use snafu::{Backtrace, Snafu}; | ||
|
||
#[derive(Debug, Snafu)] | ||
#[snafu(visibility = "pub")] | ||
pub enum Error { | ||
#[snafu(display( | ||
"Unimplemented influxql statement, msg: {}.\nBacktrace:{}", | ||
msg, | ||
backtrace | ||
))] | ||
Unimplemented { msg: String, backtrace: Backtrace }, | ||
|
||
#[snafu(display( | ||
"Failed to rewrite influxql from statement with cause, msg:{}, source:{}", | ||
msg, | ||
source | ||
))] | ||
RewriteWithCause { msg: String, source: GenericError }, | ||
|
||
#[snafu(display( | ||
"Failed to rewrite influxql from statement no cause, msg:{}.\nBacktrace:{}", | ||
msg, | ||
backtrace | ||
))] | ||
RewriteNoCause { msg: String, backtrace: Backtrace }, | ||
} | ||
|
||
define_result!(Error); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2023 CeresDB Project Authors. Licensed under Apache-2.0. | ||
|
||
//! Influxql planner. | ||
use common_util::error::BoxError; | ||
use influxdb_influxql_parser::statement::Statement as InfluxqlStatement; | ||
use snafu::ResultExt; | ||
use table_engine::table::TableRef; | ||
|
||
use crate::{influxql::error::*, plan::Plan, provider::MetaProvider}; | ||
|
||
#[allow(dead_code)] | ||
pub(crate) struct Planner<'a, P: MetaProvider> { | ||
sql_planner: crate::planner::PlannerDelegate<'a, P>, | ||
} | ||
|
||
impl<'a, P: MetaProvider> Planner<'a, P> { | ||
pub fn new(sql_planner: crate::planner::PlannerDelegate<'a, P>) -> Self { | ||
Self { sql_planner } | ||
} | ||
|
||
pub fn statement_to_plan(&self, stmt: InfluxqlStatement) -> Result<Plan> { | ||
match stmt { | ||
InfluxqlStatement::Select(_) => todo!(), | ||
InfluxqlStatement::CreateDatabase(_) => todo!(), | ||
InfluxqlStatement::ShowDatabases(_) => todo!(), | ||
InfluxqlStatement::ShowRetentionPolicies(_) => todo!(), | ||
InfluxqlStatement::ShowTagKeys(_) => todo!(), | ||
InfluxqlStatement::ShowTagValues(_) => todo!(), | ||
InfluxqlStatement::ShowFieldKeys(_) => todo!(), | ||
InfluxqlStatement::ShowMeasurements(_) => todo!(), | ||
InfluxqlStatement::Delete(_) => todo!(), | ||
InfluxqlStatement::DropMeasurement(_) => todo!(), | ||
InfluxqlStatement::Explain(_) => todo!(), | ||
} | ||
} | ||
} | ||
|
||
pub trait MeasurementProvider { | ||
fn measurement(&self, measurement_name: &str) -> Result<Option<TableRef>>; | ||
} | ||
|
||
pub(crate) struct MeasurementProviderImpl<'a, P: MetaProvider>( | ||
crate::planner::PlannerDelegate<'a, P>, | ||
); | ||
|
||
impl<'a, P: MetaProvider> MeasurementProvider for MeasurementProviderImpl<'a, P> { | ||
fn measurement(&self, measurement_name: &str) -> Result<Option<TableRef>> { | ||
self.0 | ||
.find_table(measurement_name) | ||
.box_err() | ||
.context(RewriteWithCause { | ||
msg: format!("failed to find measurement, measurement:{measurement_name}"), | ||
}) | ||
} | ||
} |
Oops, something went wrong.