[improvement](fe) Add current_database builtin alias#62591
[improvement](fe) Add current_database builtin alias#62591yiguolei merged 1 commit intoapache:masterfrom
Conversation
### What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary: Add current_database() as a small compatibility alias for the existing database() builtin so portable SQL can resolve the current database name without rewrites.
### Release note
Support current_database() as an alias of database().
### Check List (For Author)
- Test: FE checkstyle and regression test update
- Manual test / No need to test (with reason)
- Behavior changed: Yes (adds a compatibility alias for current database lookup)
- Does this need documentation: No
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
|
run buildall |
|
PR approved by at least one committer and no changes requested. |
|
PR approved by anyone and no changes requested. |
FE Regression Coverage ReportIncrement line coverage |
|
/review |
There was a problem hiding this comment.
Two blocking issues:
current_database()is only added at FE alias registration. Withdebug_skip_fold_constant=true,FoldConstantRule.evaluate()skips FE folding (fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRule.java:66-77),ExpressionTranslator.visitScalarFunction()lowersDatabaseto a genericFunctionCallExpr("database")(fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java:697-717), and BE resolves that throughSimpleFunctionFactory(be/src/exprs/vectorized_fn_call.cpp:162-170). I could not find any BEdatabasefunction registration underbe/src, so this new alias still looks broken once constant folding is disabled.- The regression only uses plain
sql "SELECT CURRENT_DATABASE();", which does not assert the returned value.Suite.sql()just executes and returns rows (regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy:593-599), so this will not catch wrong results or the no-fold failure above.
Critical checkpoint conclusions:
- Goal and correctness: Partially met. The folded path is wired up, but the non-folded execution path is not proven and the test does not verify the alias result.
- Change scope: Small and focused.
- Concurrency: Not involved.
- Lifecycle/static initialization: Not involved.
- Config changes: None.
- Incompatible or parallel code paths: User-visible alias added, but execution modes that skip FE constant folding are not covered.
- Special conditions: The implementation currently depends on constant folding.
- Test coverage: Insufficient. No value assertion and no
debug_skip_fold_constant=truecoverage. - Test result files: Not applicable.
- Observability: Not needed.
- Transaction, persistence, data writes, FE-BE variable passing: Not involved.
- Performance: No material concern in this diff.
| scalar(CutIpv6.class, "cut_ipv6"), | ||
| scalar(CutToFirstSignificantSubdomain.class, "cut_to_first_significant_subdomain"), | ||
| scalar(Database.class, "database", "schema"), | ||
| scalar(Database.class, "database", "schema", "current_database"), |
There was a problem hiding this comment.
Adding the alias here only covers FE binding. When debug_skip_fold_constant=true, FoldConstantRule.evaluate() returns Database unchanged (fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRule.java:66-77), then ExpressionTranslator.visitScalarFunction() lowers it to a generic FunctionCallExpr("database") (fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java:697-717). That is serialized as FUNCTION_CALL, and BE resolves it through SimpleFunctionFactory in be/src/exprs/vectorized_fn_call.cpp:162-170. I could not find any BE database function registration under be/src, so SELECT CURRENT_DATABASE() still looks broken as soon as constant folding is disabled. This needs either a dedicated lowering to the legacy InformationFunction/INFO_FUNC path or a real BE scalar implementation, plus regression coverage for that mode.
|
|
||
| def tableName = "test" | ||
| sql "SELECT DATABASE();" | ||
| sql "SELECT CURRENT_DATABASE();" |
There was a problem hiding this comment.
sql here only smoke-tests that the statement does not throw. Suite.sql() just executes the query and returns rows (regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy:593-599), so this will not catch a wrong result or the non-folded runtime failure above. Since this is the only coverage for a new user-visible alias, please assert that it matches database().
| sql "SELECT CURRENT_DATABASE();" | |
| assertEquals((sql "SELECT DATABASE();")[0][0], (sql "SELECT CURRENT_DATABASE();")[0][0]) |
### What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary: Add current_database() as a small compatibility alias
for the existing database() builtin so portable SQL can resolve the
current database name without rewrites.
### Release note
Support current_database() as an alias of database().
### Check List (For Author)
- Test: FE checkstyle and regression test update
- Manual test / No need to test (with reason)
- Behavior changed: Yes (adds a compatibility alias for current database
lookup)
- Does this need documentation: No
What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary: Add current_database() as a small compatibility alias for the existing database() builtin so portable SQL can resolve the current database name without rewrites.
Release note
Support current_database() as an alias of database().
Check List (For Author)