-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* define endpoint Signed-off-by: Ruihang Xia <[email protected]> * planner Signed-off-by: Ruihang Xia <[email protected]> * update lock file Signed-off-by: Ruihang Xia <[email protected]> * add unit test Signed-off-by: Ruihang Xia <[email protected]> * fix toml format Signed-off-by: Ruihang Xia <[email protected]> * revert metric change Signed-off-by: Ruihang Xia <[email protected]> * Update src/query/src/log_query/planner.rs Co-authored-by: Copilot <[email protected]> * fix compile Signed-off-by: Ruihang Xia <[email protected]> * refactor and tests Signed-off-by: Ruihang Xia <[email protected]> --------- Signed-off-by: Ruihang Xia <[email protected]> Co-authored-by: Copilot <[email protected]>
- Loading branch information
Showing
25 changed files
with
827 additions
and
25 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 |
---|---|---|
|
@@ -26,3 +26,4 @@ pub mod function_registry; | |
pub mod handlers; | ||
pub mod helper; | ||
pub mod state; | ||
pub mod utils; |
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,58 @@ | ||
// Copyright 2023 Greptime Team | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/// Escapes special characters in the provided pattern string for `LIKE`. | ||
/// | ||
/// Specifically, it prefixes the backslash (`\`), percent (`%`), and underscore (`_`) | ||
/// characters with an additional backslash to ensure they are treated literally. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ```rust | ||
/// let escaped = escape_pattern("100%_some\\path"); | ||
/// assert_eq!(escaped, "100\\%\\_some\\\\path"); | ||
/// ``` | ||
pub fn escape_like_pattern(pattern: &str) -> String { | ||
pattern | ||
.chars() | ||
.flat_map(|c| match c { | ||
'\\' | '%' | '_' => vec!['\\', c], | ||
_ => vec![c], | ||
}) | ||
.collect::<String>() | ||
} | ||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_escape_like_pattern() { | ||
assert_eq!( | ||
escape_like_pattern("100%_some\\path"), | ||
"100\\%\\_some\\\\path" | ||
); | ||
assert_eq!(escape_like_pattern(""), ""); | ||
assert_eq!(escape_like_pattern("hello"), "hello"); | ||
assert_eq!(escape_like_pattern("\\%_"), "\\\\\\%\\_"); | ||
assert_eq!(escape_like_pattern("%%__\\\\"), "\\%\\%\\_\\_\\\\\\\\"); | ||
assert_eq!(escape_like_pattern("abc123"), "abc123"); | ||
assert_eq!(escape_like_pattern("%_\\"), "\\%\\_\\\\"); | ||
assert_eq!( | ||
escape_like_pattern("%%__\\\\another%string"), | ||
"\\%\\%\\_\\_\\\\\\\\another\\%string" | ||
); | ||
assert_eq!(escape_like_pattern("foo%bar_"), "foo\\%bar\\_"); | ||
assert_eq!(escape_like_pattern("\\_\\%"), "\\\\\\_\\\\\\%"); | ||
} | ||
} |
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,67 @@ | ||
// Copyright 2023 Greptime Team | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use auth::{PermissionChecker, PermissionCheckerRef, PermissionReq}; | ||
use client::Output; | ||
use common_error::ext::BoxedError; | ||
use log_query::LogQuery; | ||
use server_error::Result as ServerResult; | ||
use servers::error::{self as server_error, AuthSnafu, ExecuteQuerySnafu}; | ||
use servers::interceptor::{LogQueryInterceptor, LogQueryInterceptorRef}; | ||
use servers::query_handler::LogQueryHandler; | ||
use session::context::QueryContextRef; | ||
use snafu::ResultExt; | ||
use tonic::async_trait; | ||
|
||
use super::Instance; | ||
|
||
#[async_trait] | ||
impl LogQueryHandler for Instance { | ||
async fn query(&self, mut request: LogQuery, ctx: QueryContextRef) -> ServerResult<Output> { | ||
let interceptor = self | ||
.plugins | ||
.get::<LogQueryInterceptorRef<server_error::Error>>(); | ||
|
||
self.plugins | ||
.get::<PermissionCheckerRef>() | ||
.as_ref() | ||
.check_permission(ctx.current_user(), PermissionReq::LogQuery) | ||
.context(AuthSnafu)?; | ||
|
||
interceptor.as_ref().pre_query(&request, ctx.clone())?; | ||
|
||
request | ||
.time_filter | ||
.canonicalize() | ||
.map_err(BoxedError::new) | ||
.context(ExecuteQuerySnafu)?; | ||
|
||
let plan = self | ||
.query_engine | ||
.planner() | ||
.plan_logs_query(request, ctx.clone()) | ||
.await | ||
.map_err(BoxedError::new) | ||
.context(ExecuteQuerySnafu)?; | ||
|
||
let output = self | ||
.statement_executor | ||
.exec_plan(plan, ctx.clone()) | ||
.await | ||
.map_err(BoxedError::new) | ||
.context(ExecuteQuerySnafu)?; | ||
|
||
Ok(interceptor.as_ref().post_query(output, ctx.clone())?) | ||
} | ||
} |
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
Oops, something went wrong.