Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mihaibudiu
Copy link
Contributor

@mihaibudiu mihaibudiu commented Jan 20, 2026

  • workaround a bug in Calcite's computation of types for arithmetic on timestamps
  • introduce a literal for null interned strings, used by the optimizer internally (its absence would cause a crash)
  • fix a bug in the handling of uninterning of tuple expressions
  • fix a bug in the handling of GC for ASOF joins right-hand side, where the GC operator was not introduced in the correct topological order
  • casts from NULL are always allowed
  • never use struct types inside the IR, just tuples
  • simple optimization for if expressions with constant conditions (without requiring a visitor)
  • added a test case for a bug which is still unfixed

In the future I may submit such fixes one by one, but I do have more.

@mihaibudiu mihaibudiu added this pull request to the merge queue Jan 20, 2026
@mihaibudiu mihaibudiu removed this pull request from the merge queue due to a manual request Jan 20, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes several compiler bugs discovered while testing more complex SQL programs. The fixes address issues in type handling, expression optimization, operator ordering, and null value representation.

Changes:

  • Added workaround for Calcite's incorrect type inference in timestamp arithmetic
  • Introduced null literal support for interned strings to prevent crashes in the optimizer
  • Fixed tuple expression uninterning to handle nullable tuples correctly
  • Fixed ASOF join GC operator topological ordering for right-hand side
  • Allowed casts from NULL type (always valid)
  • Changed type conversion to use tuples instead of struct types in IR
  • Added simple constant-folding optimization for if expressions
  • Added test case for an unfixed bug and removed unused NameGen class

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Regression1Tests.java Added test case for CASE/ROW casting
IncrementalRegressionTests.java Added test for unfixed lateness types bug
MetadataTests.java Removed unused NameGen import and cleaned up test code
NameGen.java Deleted unused name generation utility class
FreshName.java Added add() and isUsed() helper methods
DBSPTypeStruct.java Changed error reporting to use InternalCompilerError instead of deprecated error() method
DBSPLiteral.java Added INTERNED_STRING case to none() factory method
DBSPInternedStringLiteral.java New literal class for null interned strings used by optimizer
DBSPIfExpression.java Added simplify() method for constant condition optimization
IDBSPNode.java Removed deprecated checkNull() and error() helper methods
InternInner.java Fixed tuple uninterning to properly handle nullable tuple expressions
ExpandOperators.java Fixed operator ordering for ASOF join GC operators
LowerAsof.java Added right-hand side GC operator handling for ASOF joins
Projection.java Fixed cast validation to use sameTypeIgnoringNullability and added toString to InputAndFieldIndex
InnerVisitor.java Added visitor methods for DBSPInternedStringLiteral
InnerRewriteVisitor.java Added rewrite support for DBSPInternedStringLiteral
TypeCompiler.java Added removeDuplicateFields method and fixed struct/tuple type handling
ExpressionCompiler.java Added timestamp arithmetic workaround and null cast support
CalciteToDBSPCompiler.java Integrated duplicate field removal in type conversion
ToRustInnerVisitor.java Added Rust code generation for DBSPInternedStringLiteral
ToJsonInnerVisitor.java Added JSON serialization for DBSPInternedStringLiteral

Comment on lines +93 to +102
public DBSPExpression simplify() {
if (this.condition.is(DBSPBoolLiteral.class)) {
Boolean cond = this.condition.to(DBSPBoolLiteral.class).value;
if (cond == null || !cond) {
return Objects.requireNonNull(this.negative);
}
return this.positive;
}
return this;
}
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

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

The simplify() method has a potential bug when handling null or false conditions. When the condition is null or false, the method returns Objects.requireNonNull(this.negative), but this.negative can be null (as indicated by the @nullable annotation). This will throw a NullPointerException when negative is null. The method should check if this.negative is null before returning it, or handle the case appropriately.

Copilot uses AI. Check for mistakes.
@mihaibudiu mihaibudiu added this pull request to the merge queue Jan 20, 2026
Merged via the queue into main with commit d9a41d7 Jan 20, 2026
7 checks passed
@mihaibudiu mihaibudiu deleted the bugs branch January 20, 2026 23:45
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.

3 participants