Skip to content

feat(api): Register LENGTH, REGEXP_REPLACE, DATE_TRUNC in operator table#17

Closed
dai-chen wants to merge 2 commits into
mainfrom
feature/register-scalar-functions
Closed

feat(api): Register LENGTH, REGEXP_REPLACE, DATE_TRUNC in operator table#17
dai-chen wants to merge 2 commits into
mainfrom
feature/register-scalar-functions

Conversation

@dai-chen
Copy link
Copy Markdown
Owner

@dai-chen dai-chen commented May 7, 2026

Description

Extend UnifiedFunctionSpec Builder with delegateTo() and operands() paths to support library functions backed by native Calcite operators. Add LIBRARY category with LENGTH, REGEXP_REPLACE, and DATE_TRUNC (PostgreSQL arg order). Override operatorTable() in UnifiedSqlSpec to chain these into the SQL validation pipeline.

This unblocks ClickBench q28 (LENGTH), q29 (REGEXP_REPLACE), and q43 (DATE_TRUNC) at the SQL Plugin parsing/validation layer.

Related Issues

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • New PPL command checklist all confirmed.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff or -s.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Comment thread api/src/main/java/org/opensearch/sql/api/spec/UnifiedFunctionSpec.java Outdated
Comment thread api/src/main/java/org/opensearch/sql/api/spec/UnifiedSqlSpec.java Outdated
Comment thread api/src/test/java/org/opensearch/sql/api/UnifiedSqlSpecTest.java Outdated
Comment thread api/src/main/java/org/opensearch/sql/api/spec/UnifiedFunctionSpec.java Outdated
@dai-chen dai-chen force-pushed the feature/register-scalar-functions branch from e757d9e to d5c7b6c Compare May 7, 2026 19:30
Comment thread api/src/main/java/org/opensearch/sql/api/spec/FunctionSpecBuilder.java Outdated
Comment thread api/src/main/java/org/opensearch/sql/api/spec/LanguageSpec.java Outdated
Comment thread api/src/main/java/org/opensearch/sql/api/spec/UnifiedFunctionSpec.java Outdated
Comment thread api/src/main/java/org/opensearch/sql/api/spec/UnifiedFunctionSpec.java Outdated
Comment thread api/src/main/java/org/opensearch/sql/api/spec/UnifiedFunctionSpec.java Outdated
Comment thread api/src/test/java/org/opensearch/sql/api/UnifiedFunctionLibraryTest.java Outdated
Comment thread api/src/main/java/org/opensearch/sql/api/spec/UnifiedFunctionSpec.java Outdated
Add FunctionSpecBuilder DSL with three construction paths: delegateTo()
for existing Calcite operators, vararg() for pushdown-only UDFs, and
operands() for typed functions with optional late-binding impl.

Register LENGTH, REGEXP_REPLACE, and DATE_TRUNC in UnifiedFunctionSpec
LIBRARY category. Contribute via CoreExtension registered in
UnifiedSqlSpec.extended().

This unblocks ClickBench q28 (LENGTH), q29 (REGEXP_REPLACE), and q43
(DATE_TRUNC) at the SQL Plugin parsing/validation layer.

Signed-off-by: Chen Dai <daichen@amazon.com>
@dai-chen dai-chen force-pushed the feature/register-scalar-functions branch 3 times, most recently from da83381 to 64816d7 Compare May 7, 2026 19:48
Comment thread api/src/main/java/org/opensearch/sql/api/spec/CoreExtension.java Outdated
Comment thread api/src/main/java/org/opensearch/sql/api/spec/CoreExtension.java Outdated
Comment thread api/src/main/java/org/opensearch/sql/api/spec/CoreExtension.java Outdated
Comment thread api/src/main/java/org/opensearch/sql/api/spec/CoreExtension.java Outdated
Comment thread api/src/main/java/org/opensearch/sql/api/spec/FunctionSpecBuilder.java Outdated
Comment thread api/src/main/java/org/opensearch/sql/api/spec/UnifiedFunctionSpec.java Outdated
@dai-chen dai-chen force-pushed the feature/register-scalar-functions branch from 64816d7 to 8829a74 Compare May 7, 2026 20:03
Comment thread api/src/main/java/org/opensearch/sql/api/spec/CoreExtension.java Outdated
Comment thread api/src/main/java/org/opensearch/sql/api/spec/CoreExtension.java Outdated
Comment thread api/src/main/java/org/opensearch/sql/api/spec/FunctionSpecBuilder.java Outdated
Comment thread api/src/main/java/org/opensearch/sql/api/spec/UnifiedFunctionSpec.java Outdated
@dai-chen dai-chen force-pushed the feature/register-scalar-functions branch 4 times, most recently from 73a9267 to 93dca4e Compare May 7, 2026 21:12
Add preCompilationRules() extension point to LanguageSpec that allows
extensions to transform the logical plan before in-memory execution
only. The plan remains clean for external consumers (Analytics Engine).

CoreExtension registers FunctionImplBindingRule which fetches impl
bindings from UnifiedFunctionSpec and rewrites custom function calls
into executable Calcite expressions at compilation time.

DATE_TRUNC now has an impl that rewrites to FLOOR(ts TO unit), making
it executable in-memory while preserving DATE_TRUNC in the logical plan
for the Analytics Engine path.

Signed-off-by: Chen Dai <daichen@amazon.com>
@dai-chen dai-chen force-pushed the feature/register-scalar-functions branch from 93dca4e to 6561560 Compare May 7, 2026 21:13
@dai-chen dai-chen closed this May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant