Skip to content

Commit 39abacc

Browse files
authored
feat(query): support tag_reference table function (#19221)
* feat(query): support tag_reference table function * fix stage privilege check * fix unit test
1 parent 687810a commit 39abacc

File tree

6 files changed

+714
-0
lines changed

6 files changed

+714
-0
lines changed

src/query/ast/src/parser/parser.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,22 @@ use pretty_assertions::assert_eq;
2020
use crate::ParseError;
2121
use crate::Range;
2222
use crate::Result;
23+
use crate::ast::DatabaseRef;
2324
use crate::ast::ExplainKind;
2425
use crate::ast::Expr;
2526
use crate::ast::Identifier;
2627
use crate::ast::Literal;
2728
use crate::ast::SelectTarget;
2829
use crate::ast::Statement;
2930
use crate::ast::StatementWithFormat;
31+
use crate::ast::TableRef;
3032
use crate::parser::Backtrace;
3133
use crate::parser::common::IResult;
3234
use crate::parser::common::comma_separated_list0;
3335
use crate::parser::common::comma_separated_list1;
36+
use crate::parser::common::database_ref;
3437
use crate::parser::common::ident;
38+
use crate::parser::common::table_ref;
3539
use crate::parser::common::transform_span;
3640
use crate::parser::error::display_parser_error;
3741
use crate::parser::expr::expr;
@@ -66,6 +70,20 @@ pub fn parse_expr(tokens: &[Token], dialect: Dialect) -> Result<Expr> {
6670
run_parser(tokens, dialect, ParseMode::Default, false, expr)
6771
}
6872

73+
/// Parse a table reference string like "table", "db.table", or "catalog.db.table".
74+
/// Correctly handles quoted identifiers like `"my.weird.table"`.
75+
pub fn parse_table_ref(sql: &str, dialect: Dialect) -> Result<TableRef> {
76+
let tokens = tokenize_sql(sql)?;
77+
run_parser(&tokens, dialect, ParseMode::Default, false, table_ref)
78+
}
79+
80+
/// Parse a database reference string like "db" or "catalog.db".
81+
/// Correctly handles quoted identifiers.
82+
pub fn parse_database_ref(sql: &str, dialect: Dialect) -> Result<DatabaseRef> {
83+
let tokens = tokenize_sql(sql)?;
84+
run_parser(&tokens, dialect, ParseMode::Default, false, database_ref)
85+
}
86+
6987
pub fn parse_comma_separated_exprs(tokens: &[Token], dialect: Dialect) -> Result<Vec<Expr>> {
7088
run_parser(tokens, dialect, ParseMode::Default, true, |i| {
7189
comma_separated_list0(expr)(i)

src/query/service/src/table_functions/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ mod sync_crash_me;
3131
mod system;
3232
mod table_function;
3333
mod table_function_factory;
34+
mod tag_references;
3435
mod temporary_tables_table;
3536
mod udf_table;
3637

@@ -46,5 +47,6 @@ pub use system::get_fuse_table_snapshot;
4647
pub use system::get_fuse_table_statistics;
4748
pub use table_function::TableFunction;
4849
pub use table_function_factory::TableFunctionFactory;
50+
pub use tag_references::TagReferencesTable;
4951
pub use temporary_tables_table::TemporaryTablesTable;
5052
pub use udf_table::UDTFTable;

src/query/service/src/table_functions/table_function_factory.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ use crate::table_functions::show_variables::ShowVariables;
6666
use crate::table_functions::srf::RangeTable;
6767
use crate::table_functions::sync_crash_me::SyncCrashMeTable;
6868
use crate::table_functions::system::TableStatisticsFunc;
69+
use crate::table_functions::tag_references::TagReferencesTable;
6970
type TableFunctionCreators = RwLock<HashMap<String, (MetaId, Arc<dyn TableFunctionCreator>)>>;
7071

7172
pub trait TableFunctionCreator: Send + Sync {
@@ -324,6 +325,11 @@ impl TableFunctionFactory {
324325
(next_id(), Arc::new(PolicyReferencesTable::create)),
325326
);
326327

328+
creators.insert(
329+
"tag_references".to_string(),
330+
(next_id(), Arc::new(TagReferencesTable::create)),
331+
);
332+
327333
creators.insert(
328334
"udf_echo".to_string(),
329335
(next_id(), Arc::new(UdfEchoTable::create)),
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2021 Datafuse Labs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
mod tag_references_table;
16+
17+
pub use tag_references_table::TagReferencesTable;

0 commit comments

Comments
 (0)