mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-31 04:10:38 +00:00
feat: handle PromQL HTTP API parameters (#985)
* feat: impl EvalStmt parser Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * fix compile errors Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * update test result Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * add integration test Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * fix clippy Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * resolve CR comments Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * impl From<PromqlQuery> for PromQuery Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * move format into with_context Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * update test result Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * shorthand compound error Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * use rfc3339 error to report float parsing error Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * remove CompoundError Signed-off-by: Ruihang Xia <waynestxia@gmail.com> --------- Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
This commit is contained in:
@@ -44,6 +44,7 @@ use meta_client::client::{MetaClient, MetaClientBuilder};
|
||||
use meta_client::MetaClientOpts;
|
||||
use partition::manager::PartitionRuleManager;
|
||||
use partition::route::TableRoutes;
|
||||
use query::parser::PromQuery;
|
||||
use query::query_engine::options::{validate_catalog_and_schema, QueryOptions};
|
||||
use servers::error as server_error;
|
||||
use servers::interceptor::{SqlQueryInterceptor, SqlQueryInterceptorRef};
|
||||
@@ -448,12 +449,14 @@ impl SqlQueryHandler for Instance {
|
||||
}
|
||||
}
|
||||
|
||||
async fn do_promql_query(&self, query: &str, _: QueryContextRef) -> Vec<Result<Output>> {
|
||||
async fn do_promql_query(&self, query: &PromQuery, _: QueryContextRef) -> Vec<Result<Output>> {
|
||||
if let Some(handler) = &self.promql_handler {
|
||||
let result = handler
|
||||
.do_query(query)
|
||||
.await
|
||||
.context(ExecutePromqlSnafu { query });
|
||||
let result = handler.do_query(query).await.with_context(|_| {
|
||||
let query_literal = format!("{query:?}");
|
||||
ExecutePromqlSnafu {
|
||||
query: query_literal,
|
||||
}
|
||||
});
|
||||
vec![result]
|
||||
} else {
|
||||
vec![Err(NotSupportedSnafu {
|
||||
@@ -523,7 +526,7 @@ impl ScriptHandler for Instance {
|
||||
|
||||
#[async_trait]
|
||||
impl PromqlHandler for Instance {
|
||||
async fn do_query(&self, query: &str) -> server_error::Result<Output> {
|
||||
async fn do_query(&self, query: &PromQuery) -> server_error::Result<Output> {
|
||||
if let Some(promql_handler) = &self.promql_handler {
|
||||
promql_handler.do_query(query).await
|
||||
} else {
|
||||
|
||||
@@ -42,7 +42,7 @@ use meta_client::rpc::{
|
||||
RouteResponse, TableName,
|
||||
};
|
||||
use partition::partition::{PartitionBound, PartitionDef};
|
||||
use query::parser::QueryStatement;
|
||||
use query::parser::{PromQuery, QueryStatement};
|
||||
use query::sql::{describe_table, explain, show_databases, show_tables};
|
||||
use query::{QueryEngineFactory, QueryEngineRef};
|
||||
use servers::query_handler::sql::SqlQueryHandler;
|
||||
@@ -508,7 +508,7 @@ impl SqlQueryHandler for DistInstance {
|
||||
|
||||
async fn do_promql_query(
|
||||
&self,
|
||||
_: &str,
|
||||
_: &PromQuery,
|
||||
_: QueryContextRef,
|
||||
) -> Vec<std::result::Result<Output, Self::Error>> {
|
||||
unimplemented!()
|
||||
|
||||
@@ -19,6 +19,7 @@ use async_trait::async_trait;
|
||||
use common_query::Output;
|
||||
use datanode::error::Error as DatanodeError;
|
||||
use datatypes::schema::Schema;
|
||||
use query::parser::PromQuery;
|
||||
use servers::query_handler::grpc::{GrpcQueryHandler, GrpcQueryHandlerRef};
|
||||
use servers::query_handler::sql::{SqlQueryHandler, SqlQueryHandlerRef};
|
||||
use session::context::QueryContextRef;
|
||||
@@ -50,7 +51,7 @@ impl SqlQueryHandler for StandaloneSqlQueryHandler {
|
||||
|
||||
async fn do_promql_query(
|
||||
&self,
|
||||
_: &str,
|
||||
_: &PromQuery,
|
||||
_: QueryContextRef,
|
||||
) -> Vec<std::result::Result<Output, Self::Error>> {
|
||||
unimplemented!()
|
||||
|
||||
Reference in New Issue
Block a user