Skip to content

[CALCITE-7529] RexExecutor constant reduction loses sub-millisecond precision for TIME/TIMESTAMP literals#4942

Open
zzwqqq wants to merge 1 commit into
apache:mainfrom
zzwqqq:fix_time_literal
Open

[CALCITE-7529] RexExecutor constant reduction loses sub-millisecond precision for TIME/TIMESTAMP literals#4942
zzwqqq wants to merge 1 commit into
apache:mainfrom
zzwqqq:fix_time_literal

Conversation

@zzwqqq
Copy link
Copy Markdown
Contributor

@zzwqqq zzwqqq commented May 14, 2026

Jira Link

CALCITE-7529

Changes Proposed

Fix constant reduction of high-precision TIME and TIMESTAMP literals.

RexExecutorImpl evaluates constants using generated Java code, where TIME and TIMESTAMP use millisecond-based runtime values. This can drop digits beyond milliseconds when a custom RelDataTypeSystem allows precision greater than 3.

This PR avoids that loss by keeping high-precision temporal literal casts as Rex literals when possible, and by leaving existing RexLiterals unchanged during reduction.

Added regression tests for TIME(6), TIMESTAMP(6), existing temporal literals, and TIME(6) to VARCHAR.

@zzwqqq zzwqqq force-pushed the fix_time_literal branch from 575b5fd to 19b41c4 Compare May 15, 2026 02:16
@sonarqubecloud
Copy link
Copy Markdown

@Override public void reduce(RexBuilder rexBuilder, List<RexNode> constExps,
List<RexNode> reducedValues) {
assert reducedValues.isEmpty();
final List<RexNode> exps = new ArrayList<>();
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.

what happens here? you are only reducing expressions which are already literals?
This seems to be some kind of regression - other constant expressions are not reduced?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm copying literals through unchanged, and compiling/reducing only non-literal constant expressions.

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.

2 participants