fix(native): Fix Dereference expression index type in VeloxToPrestoExprConverter#27057
fix(native): Fix Dereference expression index type in VeloxToPrestoExprConverter#27057pramodsatya merged 1 commit intoprestodb:masterfrom
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts the Velox-to-Presto dereference expression index type to use INTEGER instead of BIGINT and adds end-to-end tests to cover dereference usage via array_least_frequent under the native optimizer. Sequence diagram for DEREFERENCE conversion with INTEGER indexsequenceDiagram
participant NativeOptimizer
participant VeloxToPrestoExprConverter as Converter
participant velox_core_FieldAccessTypedExpr as FieldAccessExpr
participant velox_core_ConstantTypedExpr as ConstantExpr
participant protocol_RowExpression as RowExpr
NativeOptimizer->>Converter: getDereferenceExpression(FieldAccessExpr)
Converter->>FieldAccessExpr: inputs()
FieldAccessExpr-->>Converter: std_vector_TypedExprPtr
Converter->>FieldAccessExpr: index()
FieldAccessExpr-->>Converter: index_int32
Converter->>ConstantExpr: new ConstantTypedExpr(velox_INTEGER, index_int32)
Converter->>Converter: build dereferenceInputs[0] = base_expr
Converter->>Converter: build dereferenceInputs[1] = ConstantExpr
loop for each input in dereferenceInputs
Converter->>Converter: getRowExpression(input)
Converter-->>Converter: RowExpr
end
Converter-->>NativeOptimizer: RowExpr representing DEREFERENCE with INTEGER index
Class diagram for updated dereference conversion in VeloxToPrestoExprConverterclassDiagram
class VeloxToPrestoExprConverter {
+getDereferenceExpression(dereferenceExpr : velox_core_FieldAccessTypedExprPtr) SpecialFormExpressionPtr
+getRowExpression(input : velox_core_TypedExprPtr) protocol_RowExpressionPtr
}
class velox_core_FieldAccessTypedExpr {
+inputs() std_vector_velox_core_TypedExprPtr
+index() int32_t
}
class velox_core_TypedExpr {
}
class velox_core_ConstantTypedExpr {
+ConstantTypedExpr(type : velox_TypePtr, value : int32_t)
}
class velox_Type {
}
class protocol_RowExpression {
}
VeloxToPrestoExprConverter --> velox_core_FieldAccessTypedExpr : uses
VeloxToPrestoExprConverter --> velox_core_TypedExpr : builds_dereferenceInputs
VeloxToPrestoExprConverter --> velox_core_ConstantTypedExpr : creates_index_constant
velox_core_ConstantTypedExpr --> velox_Type : has_type
VeloxToPrestoExprConverter --> protocol_RowExpression : returns
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The change from BIGINT to INTEGER introduces a narrowing cast on
dereferenceExpr->index(); consider adding an assertion or explicit range check (or a comment explaining why the index is guaranteed to fit in int32) to make the assumption about index bounds clear.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The change from BIGINT to INTEGER introduces a narrowing cast on `dereferenceExpr->index()`; consider adding an assertion or explicit range check (or a comment explaining why the index is guaranteed to fit in int32) to make the assumption about index bounds clear.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
@aditi-pandit, could you please help review this fix? |
pdabre12
left a comment
There was a problem hiding this comment.
@pramodsatya Changes look good.
Seems like the test case is failing because of a known varchar(N) issue, can you instead add another test case without varchar column ?
Optionally, you can keep this test case with an assertQueryFails message , whatever you prefer.
aditi-pandit
left a comment
There was a problem hiding this comment.
Thanks @pramodsatya. Please add more tests.
...native-sidecar-plugin/src/test/java/com/facebook/presto/sidecar/TestNativeSidecarPlugin.java
Outdated
Show resolved
Hide resolved
a12177f to
0e65303
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug where the native expression optimizer crashes when processing DEREFERENCE expressions. The fix changes the index type from BIGINT to INTEGER to match Presto's RowExpression protocol expectations.
Changes:
- Updated DEREFERENCE expression index type from BIGINT/int64_t to INTEGER/int32_t in VeloxToPrestoExprConverter
- Added comprehensive end-to-end tests for dereference expressions including nested row access patterns
- Added regression tests for array_least_frequent function which triggered the original crash
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| presto-native-execution/presto_cpp/main/types/VeloxToPrestoExpr.cpp | Fixed DEREFERENCE expression index type from BIGINT to INTEGER and cast from int64_t to int32_t to match Presto protocol |
| presto-native-sidecar-plugin/src/test/java/com/facebook/presto/sidecar/TestNativeSidecarPlugin.java | Added e2e tests for dereference expressions with nested rows and array_least_frequent function |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0e65303 to
19b24f7
Compare
|
Thanks @aditi-pandit, @pdabre12, added more tests, could you please take another look? |
aditi-pandit
left a comment
There was a problem hiding this comment.
Thanks @pramodsatya
Description
Changes the type of index in
DEREFERENCEexpression fromBIGINTtoINTEGERto match the PrestoRowExpressiontype.Motivation and Context
Resolves #27037.
Impact
Sql invoked functions with dereference expression won't fail with native expression optimizer enabled.
Test Plan
Added e2e tests.
Summary by Sourcery
Align DEREFERENCE expression index type with Presto RowExpression and add coverage for native optimizer queries using dereference.
Bug Fixes:
Tests: