Skip to content

[improvement](fe) Add current_database builtin alias#62591

Merged
yiguolei merged 1 commit intoapache:masterfrom
tonywasson:codex/current-database-pr
Apr 21, 2026
Merged

[improvement](fe) Add current_database builtin alias#62591
yiguolei merged 1 commit intoapache:masterfrom
tonywasson:codex/current-database-pr

Conversation

@tonywasson
Copy link
Copy Markdown
Contributor

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)

- 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
@hello-stephen
Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@yiguolei
Copy link
Copy Markdown
Contributor

run buildall

@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label Apr 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

PR approved by at least one committer and no changes requested.

@github-actions
Copy link
Copy Markdown
Contributor

PR approved by anyone and no changes requested.

Copy link
Copy Markdown
Contributor

@HappenLee HappenLee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hello-stephen
Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 100.00% (1/1) 🎉
Increment coverage report
Complete coverage report

@morrySnow
Copy link
Copy Markdown
Contributor

/review

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two blocking issues:

  1. current_database() is only added at FE alias registration. With debug_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() lowers Database to a generic FunctionCallExpr("database") (fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java:697-717), and BE resolves that through SimpleFunctionFactory (be/src/exprs/vectorized_fn_call.cpp:162-170). I could not find any BE database function registration under be/src, so this new alias still looks broken once constant folding is disabled.
  2. 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=true coverage.
  • 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"),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

Suggested change
sql "SELECT CURRENT_DATABASE();"
assertEquals((sql "SELECT DATABASE();")[0][0], (sql "SELECT CURRENT_DATABASE();")[0][0])

@yiguolei yiguolei merged commit 9125b17 into apache:master Apr 21, 2026
35 checks passed
github-actions Bot pushed a commit that referenced this pull request Apr 21, 2026
### 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
yiguolei pushed a commit that referenced this pull request Apr 22, 2026
… (#62652)

Cherry-picked from #62591

Co-authored-by: Tony Wasson <ajwasson@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. dev/4.1.1-merged reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants