-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Rewriting tree model mathematical operators #16786
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
base: master
Are you sure you want to change the base?
Conversation
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.
Hi, this is your first pull request in IoTDB project. Thanks for your contribution! IoTDB will be better because of you.
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 PR refactors arithmetic operators for tree models by introducing TSDataType-based type inference alongside the existing Type system. The refactoring delegates operator type resolution to dedicated resolver classes and introduces a new API layer (ArithmeticColumnTransformerApi) for creating column transformers.
Key changes:
- Added TSDataType support to arithmetic resolver classes (Addition, Subtraction, Multiplication, Division, Modulus)
- Refactored ColumnTransformerVisitor to use ArithmeticColumnTransformerApi instead of direct transformer instantiation
- Updated ExpressionTypeAnalyzer to use resolver-based type inference with comprehensive error handling
- Added SessionInfo integration for ZoneId access in operator tree generation
- Expanded test coverage for DATE/TIMESTAMP arithmetic, negation operations, overflow handling, and error cases
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| AdditionResolver.java | Added CONDITION_MAP_TREE and inferType method for TSDataType support with DATE/TIMESTAMP operations |
| SubtractionResolver.java | Added CONDITION_MAP_TREE and inferType method for TSDataType support with DATE/TIMESTAMP operations |
| MultiplicationResolver.java | Added CONDITION_MAP_TREE and inferType method for TSDataType support (no DATE/TIMESTAMP) |
| ModulusResolver.java | Added CONDITION_MAP_TREE and inferType method for TSDataType support (no DATE/TIMESTAMP) |
| DivisionResolver.java | Added CONDITION_MAP_TREE and inferType method for TSDataType support (no DATE/TIMESTAMP) |
| ColumnTransformerVisitor.java | Replaced direct transformer instantiation with ArithmeticColumnTransformerApi calls; added SessionInfo/ZoneId support |
| ExpressionTypeAnalyzer.java | Refactored arithmetic type inference to use resolver classes with improved error messages |
| OperatorTreeGenerator.java | Added SessionInfo parameter to ColumnTransformerVisitorContext constructors |
| IoTDBArithmeticIT.java | Added comprehensive tests for new DATE/TIMESTAMP arithmetic, negation, overflow, and error handling |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
| import org.apache.iotdb.db.queryengine.transformation.dag.column.binary.ArithmeticModuloColumnTransformer; | ||
| import org.apache.iotdb.db.queryengine.transformation.dag.column.binary.ArithmeticMultiplicationColumnTransformer; | ||
| import org.apache.iotdb.db.queryengine.transformation.dag.column.binary.ArithmeticSubtractionColumnTransformer; | ||
| import org.apache.iotdb.db.queryengine.transformation.dag.column.binary.ArithmeticColumnTransformerApi; |
Copilot
AI
Nov 28, 2025
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 ArithmeticColumnTransformerApi class is imported and used throughout this file but is not included in this PR. This will cause compilation failures as the class doesn't exist in the codebase. The API class must be added to the PR or this import should reference an existing class.
| import org.apache.iotdb.db.queryengine.transformation.dag.column.binary.ArithmeticColumnTransformerApi; |
| addConditionTS(TSDataType.INT32, TSDataType.INT32, TSDataType.INT32); | ||
| addConditionTS(TSDataType.INT32, TSDataType.INT64, TSDataType.INT64); | ||
| addConditionTS(TSDataType.INT32, TSDataType.FLOAT, TSDataType.FLOAT); | ||
| addConditionTS(TSDataType.INT32, TSDataType.DOUBLE, TSDataType.DOUBLE); | ||
| addConditionTS(TSDataType.INT32, TSDataType.DATE, TSDataType.DATE); | ||
| addConditionTS(TSDataType.INT32, TSDataType.TIMESTAMP, TSDataType.TIMESTAMP); | ||
| addConditionTS(TSDataType.INT32, TSDataType.UNKNOWN, TSDataType.INT32); | ||
|
|
||
| addConditionTS(TSDataType.INT64, TSDataType.INT32, TSDataType.INT64); | ||
| addConditionTS(TSDataType.INT64, TSDataType.INT64, TSDataType.INT64); | ||
| addConditionTS(TSDataType.INT64, TSDataType.FLOAT, TSDataType.FLOAT); | ||
| addConditionTS(TSDataType.INT64, TSDataType.DOUBLE, TSDataType.DOUBLE); | ||
| addConditionTS(TSDataType.INT64, TSDataType.DATE, TSDataType.DATE); | ||
| addConditionTS(TSDataType.INT64, TSDataType.TIMESTAMP, TSDataType.TIMESTAMP); | ||
| addConditionTS(TSDataType.INT64, TSDataType.UNKNOWN, TSDataType.INT64); | ||
|
|
||
| addConditionTS(TSDataType.FLOAT, TSDataType.INT32, TSDataType.FLOAT); | ||
| addConditionTS(TSDataType.FLOAT, TSDataType.INT64, TSDataType.FLOAT); | ||
| addConditionTS(TSDataType.FLOAT, TSDataType.FLOAT, TSDataType.FLOAT); | ||
| addConditionTS(TSDataType.FLOAT, TSDataType.DOUBLE, TSDataType.DOUBLE); | ||
| addConditionTS(TSDataType.FLOAT, TSDataType.UNKNOWN, TSDataType.FLOAT); | ||
|
|
||
| addConditionTS(TSDataType.DOUBLE, TSDataType.INT32, TSDataType.DOUBLE); | ||
| addConditionTS(TSDataType.DOUBLE, TSDataType.INT64, TSDataType.DOUBLE); | ||
| addConditionTS(TSDataType.DOUBLE, TSDataType.FLOAT, TSDataType.DOUBLE); | ||
| addConditionTS(TSDataType.DOUBLE, TSDataType.DOUBLE, TSDataType.DOUBLE); | ||
| addConditionTS(TSDataType.DOUBLE, TSDataType.UNKNOWN, TSDataType.DOUBLE); | ||
|
|
||
| addConditionTS(TSDataType.DATE, TSDataType.INT32, TSDataType.DATE); | ||
| addConditionTS(TSDataType.DATE, TSDataType.INT64, TSDataType.DATE); | ||
| addConditionTS(TSDataType.DATE, TSDataType.UNKNOWN, TSDataType.DATE); | ||
|
|
||
| addConditionTS(TSDataType.TIMESTAMP, TSDataType.INT32, TSDataType.TIMESTAMP); | ||
| addConditionTS(TSDataType.TIMESTAMP, TSDataType.INT64, TSDataType.TIMESTAMP); | ||
| addConditionTS(TSDataType.TIMESTAMP, TSDataType.UNKNOWN, TSDataType.TIMESTAMP); | ||
|
|
||
| addConditionTS(TSDataType.UNKNOWN, TSDataType.INT32, TSDataType.INT32); | ||
| addConditionTS(TSDataType.UNKNOWN, TSDataType.INT64, TSDataType.INT64); | ||
| addConditionTS(TSDataType.UNKNOWN, TSDataType.FLOAT, TSDataType.FLOAT); | ||
| addConditionTS(TSDataType.UNKNOWN, TSDataType.DOUBLE, TSDataType.DOUBLE); | ||
| addConditionTS(TSDataType.UNKNOWN, TSDataType.DATE, TSDataType.DATE); | ||
| addConditionTS(TSDataType.UNKNOWN, TSDataType.TIMESTAMP, TSDataType.TIMESTAMP); |
Copilot
AI
Nov 28, 2025
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 CONDITION_MAP_TREE initialization duplicates the exact same type promotion rules as CONDITION_MAP (lines 47-88). This duplication exists across all five resolver classes (Addition, Subtraction, Multiplication, Modulus, Division). Consider extracting this logic into a shared utility method or using a conversion function between Type and TSDataType to maintain a single source of truth for type promotion rules.
This PR achieves the refactoring of mathematical operators for tree models by reusing the type inference and runtime execution infrastructure generated by the FreeMarker template engine.