-
Notifications
You must be signed in to change notification settings - Fork 97
[SQL] Fix several compiler bugs discovered while testing more complex programs #5478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… programs Signed-off-by: Mihai Budiu <[email protected]>
There was a problem hiding this 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 |
| 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; | ||
| } |
Copilot
AI
Jan 20, 2026
There was a problem hiding this comment.
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.
In the future I may submit such fixes one by one, but I do have more.