You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "Caideyipi (via GitHub)" <gi...@apache.org> on 2026/06/05 04:06:17 UTC
[PR] Support constant folding for insert values [iotdb]
Caideyipi opened a new pull request, #17850:
URL: https://github.com/apache/iotdb/pull/17850
## Summary
- defer table-model INSERT VALUES materialization until analysis so values can reuse IrExpressionInterpreter constant folding
- throw a readable SemanticException when an insert expression still is not constant after folding
- add relational session coverage for folded INSERT VALUES expressions
## Verification
- mvn -pl iotdb-core/datanode spotless:check
- mvn -pl integration-test spotless:check -P with-integration-tests
- mvn -pl iotdb-core/datanode -DskipTests compile (fails in pre-existing generated aggregation sources: missing ComparatorChain / getModeMapSizeThreshold)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support constant folding for insert values [iotdb]
Posted by "Caideyipi (via GitHub)" <gi...@apache.org>.
Caideyipi commented on PR #17850:
URL: https://github.com/apache/iotdb/pull/17850#issuecomment-6408137368
Self-review passed.
I reviewed the full PR diff and fixed two correctness issues in `939d153bdf9`:
- `IN` constant folding now normalizes numeric containers and uses numeric comparison for mixed SQL numeric types, so folded arithmetic matches literal values.
- Numeric comparisons now reject NaN operands, including `<>`, matching `CompareBinaryColumnTransformer`.
Verification:
- `spotless:apply -P with-integration-tests`: passed.
- English source compile/install path with the constrained 2 GB retry: passed; `InsertValuesTest`: 5/5.
- Chinese full-reactor `test-compile -P with-zh-locale`: passed.
- Direct Failsafe execution: `IoTDBInsertTableIT` 3/3 and `IoTDBSessionRelationalIT` 2/2 passed.
- The standard `verify -pl integration-test -am` path was blocked by the unrelated pre-existing `DropPipeProcedureTest` test-compilation error; the direct Failsafe run completed the five requested methods successfully.
- The earlier PR Sonar job failed inside the scanner with the `NOPLoggerFactory`/`LoggerContext` incompatibility, so that CI check is not claimed as passing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support constant folding for insert values [iotdb]
Posted by "jt2594838 (via GitHub) via reviews" <re...@iotdb.apache.org>.
jt2594838 commented on code in PR #17850:
URL: https://github.com/apache/iotdb/pull/17850#discussion_r4523712934
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/IrExpressionInterpreter.java:
##########
@@ -981,6 +922,218 @@ private boolean hasUnresolvedValue(List<Object> values) {
return values.stream().anyMatch(instanceOf(Expression.class));
}
+ private boolean isSupportedArithmeticBinaryType(Type type) {
+ return type.equals(INT32) || type.equals(INT64) || type.equals(FLOAT) || type.equals(DOUBLE);
+ }
+
+ private boolean isSupportedArithmeticUnaryType(Type type) {
+ return isSupportedArithmeticBinaryType(type) || type.equals(TIMESTAMP);
+ }
+
+ private Object evaluateArithmeticNegation(Object value, Type returnType) {
+ if (returnType.equals(INT32)) {
+ int intValue = toInt(value);
+ if (intValue == Integer.MIN_VALUE) {
+ throw new SemanticException(
+ String.format(
+ DataNodeQueryMessages.EXCEPTION_THE_ARG_IS_OUT_OF_RANGE_OF_INT_F8E58471,
+ intValue));
+ }
+ return -intValue;
+ }
+ if (returnType.equals(INT64) || returnType.equals(TIMESTAMP)) {
+ long longValue = toLong(value);
+ if (longValue == Long.MIN_VALUE) {
+ throw new SemanticException(
+ String.format(
+ DataNodeQueryMessages.EXCEPTION_THE_ARG_IS_OUT_OF_RANGE_OF_LONG_9B1C872A,
+ longValue));
+ }
+ return -longValue;
+ }
+ if (returnType.equals(FLOAT)) {
+ return -toFloat(value);
+ }
+ if (returnType.equals(DOUBLE)) {
+ return -toDouble(value);
+ }
+ throw new SemanticException(DataNodeQueryMessages.UNKNOWN_TYPE_2 + returnType);
+ }
+
+ private Object evaluateArithmeticBinary(
+ ArithmeticBinaryExpression.Operator operator,
+ Object left,
+ Type leftType,
+ Object right,
+ Type returnType) {
+ if (returnType.equals(INT32)) {
+ return evaluateIntArithmetic(operator, toInt(left), toInt(right));
+ }
+ if (returnType.equals(INT64)) {
+ return evaluateLongArithmetic(operator, toLong(left), leftType, toLong(right));
+ }
+ if (returnType.equals(FLOAT)) {
+ return evaluateFloatArithmetic(operator, toFloat(left), toFloat(right));
+ }
+ if (returnType.equals(DOUBLE)) {
+ return evaluateDoubleArithmetic(operator, toDouble(left), toDouble(right));
+ }
+ throw new SemanticException(DataNodeQueryMessages.UNKNOWN_TYPE_2 + returnType);
+ }
+
+ private int evaluateIntArithmetic(
+ ArithmeticBinaryExpression.Operator operator, int left, int right) {
+ try {
+ switch (operator) {
+ case ADD:
+ return Math.addExact(left, right);
+ case SUBTRACT:
+ return Math.subtractExact(left, right);
+ case MULTIPLY:
+ return Math.multiplyExact(left, right);
+ case DIVIDE:
+ if (left == Integer.MIN_VALUE && right == -1) {
+ throw new SemanticException(
+ String.format(
+ DataNodeQueryMessages.EXCEPTION_INT_OVERFLOW_ARG_ARG_BB287017, left, right));
+ }
+ return left / right;
+ case MODULUS:
+ return left % right;
+ default:
+ throw new UnsupportedOperationException(
+ DataNodeQueryMessages.UNSUPPORTED_EXPRESSION + operator);
+ }
Review Comment:
May use an enhanced switch without a default to ease the process of adding operators.
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/IrExpressionInterpreter.java:
##########
@@ -981,6 +922,218 @@ private boolean hasUnresolvedValue(List<Object> values) {
return values.stream().anyMatch(instanceOf(Expression.class));
}
+ private boolean isSupportedArithmeticBinaryType(Type type) {
+ return type.equals(INT32) || type.equals(INT64) || type.equals(FLOAT) || type.equals(DOUBLE);
+ }
+
+ private boolean isSupportedArithmeticUnaryType(Type type) {
+ return isSupportedArithmeticBinaryType(type) || type.equals(TIMESTAMP);
+ }
+
+ private Object evaluateArithmeticNegation(Object value, Type returnType) {
+ if (returnType.equals(INT32)) {
+ int intValue = toInt(value);
+ if (intValue == Integer.MIN_VALUE) {
+ throw new SemanticException(
+ String.format(
+ DataNodeQueryMessages.EXCEPTION_THE_ARG_IS_OUT_OF_RANGE_OF_INT_F8E58471,
+ intValue));
+ }
+ return -intValue;
+ }
+ if (returnType.equals(INT64) || returnType.equals(TIMESTAMP)) {
+ long longValue = toLong(value);
+ if (longValue == Long.MIN_VALUE) {
+ throw new SemanticException(
+ String.format(
+ DataNodeQueryMessages.EXCEPTION_THE_ARG_IS_OUT_OF_RANGE_OF_LONG_9B1C872A,
+ longValue));
+ }
+ return -longValue;
+ }
+ if (returnType.equals(FLOAT)) {
+ return -toFloat(value);
+ }
+ if (returnType.equals(DOUBLE)) {
+ return -toDouble(value);
+ }
+ throw new SemanticException(DataNodeQueryMessages.UNKNOWN_TYPE_2 + returnType);
+ }
+
+ private Object evaluateArithmeticBinary(
+ ArithmeticBinaryExpression.Operator operator,
+ Object left,
+ Type leftType,
+ Object right,
+ Type returnType) {
+ if (returnType.equals(INT32)) {
+ return evaluateIntArithmetic(operator, toInt(left), toInt(right));
+ }
+ if (returnType.equals(INT64)) {
+ return evaluateLongArithmetic(operator, toLong(left), leftType, toLong(right));
+ }
+ if (returnType.equals(FLOAT)) {
+ return evaluateFloatArithmetic(operator, toFloat(left), toFloat(right));
+ }
+ if (returnType.equals(DOUBLE)) {
+ return evaluateDoubleArithmetic(operator, toDouble(left), toDouble(right));
+ }
+ throw new SemanticException(DataNodeQueryMessages.UNKNOWN_TYPE_2 + returnType);
+ }
+
+ private int evaluateIntArithmetic(
+ ArithmeticBinaryExpression.Operator operator, int left, int right) {
+ try {
+ switch (operator) {
+ case ADD:
+ return Math.addExact(left, right);
+ case SUBTRACT:
+ return Math.subtractExact(left, right);
+ case MULTIPLY:
+ return Math.multiplyExact(left, right);
+ case DIVIDE:
+ if (left == Integer.MIN_VALUE && right == -1) {
+ throw new SemanticException(
+ String.format(
+ DataNodeQueryMessages.EXCEPTION_INT_OVERFLOW_ARG_ARG_BB287017, left, right));
+ }
+ return left / right;
+ case MODULUS:
+ return left % right;
+ default:
+ throw new UnsupportedOperationException(
+ DataNodeQueryMessages.UNSUPPORTED_EXPRESSION + operator);
+ }
+ } catch (ArithmeticException e) {
+ throw new SemanticException(e.getMessage());
+ }
+ }
+
+ private long evaluateLongArithmetic(
+ ArithmeticBinaryExpression.Operator operator, long left, Type leftType, long right) {
+ try {
+ switch (operator) {
+ case ADD:
+ return Math.addExact(left, right);
+ case SUBTRACT:
+ return Math.subtractExact(left, right);
+ case MULTIPLY:
+ return Math.multiplyExact(left, right);
+ case DIVIDE:
+ if ((leftType.equals(INT32) && left == Integer.MIN_VALUE && right == -1)
+ || (leftType.equals(INT64) && left == Long.MIN_VALUE && right == -1)) {
+ throw new SemanticException(
+ String.format(
+ DataNodeQueryMessages.EXCEPTION_LONG_OVERFLOW_ARG_ARG_46CC95E2, left, right));
+ }
+ return left / right;
+ case MODULUS:
+ return left % right;
+ default:
+ throw new UnsupportedOperationException(
+ DataNodeQueryMessages.UNSUPPORTED_EXPRESSION + operator);
+ }
+ } catch (ArithmeticException e) {
+ throw new SemanticException(e.getMessage());
+ }
+ }
+
+ private float evaluateFloatArithmetic(
+ ArithmeticBinaryExpression.Operator operator, float left, float right) {
+ switch (operator) {
+ case ADD:
+ return left + right;
+ case SUBTRACT:
+ return left - right;
+ case MULTIPLY:
+ return left * right;
+ case DIVIDE:
+ return left / right;
+ case MODULUS:
+ return left % right;
+ default:
+ throw new UnsupportedOperationException(
+ DataNodeQueryMessages.UNSUPPORTED_EXPRESSION + operator);
+ }
+ }
+
+ private double evaluateDoubleArithmetic(
+ ArithmeticBinaryExpression.Operator operator, double left, double right) {
+ switch (operator) {
+ case ADD:
+ return left + right;
+ case SUBTRACT:
+ return left - right;
+ case MULTIPLY:
+ return left * right;
+ case DIVIDE:
+ return left / right;
+ case MODULUS:
+ return left % right;
+ default:
+ throw new UnsupportedOperationException(
+ DataNodeQueryMessages.UNSUPPORTED_EXPRESSION + operator);
+ }
+ }
+
+ private Object normalizeArithmeticValue(Object value, Type type) {
+ if (type.equals(INT32)) {
+ return toInt(value);
+ }
+ if (type.equals(INT64) || type.equals(TIMESTAMP)) {
+ return toLong(value);
+ }
+ if (type.equals(FLOAT)) {
+ return toFloat(value);
+ }
+ if (type.equals(DOUBLE)) {
+ return toDouble(value);
+ }
+ return value;
+ }
+
+ private Boolean evaluateNumericComparison(
+ ComparisonExpression.Operator operator, Number left, Number right) {
+ if (Double.isNaN(left.doubleValue()) || Double.isNaN(right.doubleValue())) {
+ return false;
+ }
+ int comparison =
+ (left instanceof Float
+ || left instanceof Double
+ || right instanceof Float
+ || right instanceof Double)
+ ? Double.compare(left.doubleValue(), right.doubleValue())
+ : Long.compare(left.longValue(), right.longValue());
+ switch (operator) {
+ case LESS_THAN:
+ return comparison < 0;
+ case LESS_THAN_OR_EQUAL:
+ return comparison <= 0;
+ case EQUAL:
+ return comparison == 0;
+ case NOT_EQUAL:
+ return comparison != 0;
+ default:
+ return null;
Review Comment:
Throw an exception?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support constant folding for insert values [iotdb]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17850:
URL: https://github.com/apache/iotdb/pull/17850#issuecomment-4892053895
## [](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17850) **Quality Gate passed**
Issues
 [19 New issues](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17850&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17850&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_iotdb&pullRequest=17850&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_iotdb&pullRequest=17850&metric=new_coverage&view=list)
 [3.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_iotdb&pullRequest=17850&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17850)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support constant folding for insert values [iotdb]
Posted by "sonarqubecloud[bot] (via GitHub) via reviews" <re...@iotdb.apache.org>.
sonarqubecloud[bot] commented on PR #17850:
URL: https://github.com/apache/iotdb/pull/17850#issuecomment-6680202303
## [](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17850) **Quality Gate failed**
Failed conditions
 [C Reliability Rating on New Code](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17850&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true) (required ≥ A)
<!-- sqra:qg_revision=8ae1bc07684675289a5224056ec163722ce1f35cbdcbdfda2efd6c5b108c95d2 -->
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17850)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support constant folding for insert values [iotdb]
Posted by "sonarqubecloud[bot] (via GitHub) via reviews" <re...@iotdb.apache.org>.
sonarqubecloud[bot] commented on PR #17850:
URL: https://github.com/apache/iotdb/pull/17850#issuecomment-6761555906
## [](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17850) **Quality Gate failed**
Failed conditions
 [C Reliability Rating on New Code](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17850&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true) (required ≥ A)
<!-- sqra:qg_revision=6cc4452aef47d2525e6441501679f66d17cc46dcc55d448a019b4e0fe536ed19 -->
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17850)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support constant folding for insert values [iotdb]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17850:
URL: https://github.com/apache/iotdb/pull/17850#issuecomment-4785554515
## [](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17850) **Quality Gate passed**
Issues
 [20 New issues](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17850&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17850&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_iotdb&pullRequest=17850&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_iotdb&pullRequest=17850&metric=new_coverage&view=list)
 [3.3% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_iotdb&pullRequest=17850&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17850)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support constant folding for insert values [iotdb]
Posted by "sonarqubecloud[bot] (via GitHub) via reviews" <re...@iotdb.apache.org>.
sonarqubecloud[bot] commented on PR #17850:
URL: https://github.com/apache/iotdb/pull/17850#issuecomment-6757797090
## [](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17850) **Quality Gate failed**
Failed conditions
 [C Reliability Rating on New Code](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17850&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true) (required ≥ A)
<!-- sqra:qg_revision=131e8f06c384eec9b16ca775170e8645a31f400b75e9a11299854ddd2319192e -->
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17850)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support constant folding for insert values [iotdb]
Posted by "sonarqubecloud[bot] (via GitHub) via reviews" <re...@iotdb.apache.org>.
sonarqubecloud[bot] commented on PR #17850:
URL: https://github.com/apache/iotdb/pull/17850#issuecomment-6785421555
## [](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17850) **Quality Gate failed**
Failed conditions
 [C Reliability Rating on New Code](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17850&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true) (required ≥ A)
<!-- sqra:qg_revision=ec0fbb85a479c022c9407ccd8187c21287d900ef67f5e5d72d53fd5b5d0b8df5 -->
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17850)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support constant folding for insert values [iotdb]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17850:
URL: https://github.com/apache/iotdb/pull/17850#issuecomment-4976762424
## [](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17850) **Quality Gate passed**
Issues
 [19 New issues](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17850&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17850&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_iotdb&pullRequest=17850&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_iotdb&pullRequest=17850&metric=new_coverage&view=list)
 [3.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_iotdb&pullRequest=17850&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17850)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support constant folding for insert values [iotdb]
Posted by "Caideyipi (via GitHub)" <gi...@apache.org>.
Caideyipi commented on code in PR #17850:
URL: https://github.com/apache/iotdb/pull/17850#discussion_r4373909128
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/IrExpressionInterpreter.java:
##########
@@ -981,6 +922,218 @@ private boolean hasUnresolvedValue(List<Object> values) {
return values.stream().anyMatch(instanceOf(Expression.class));
}
+ private boolean isSupportedArithmeticBinaryType(Type type) {
+ return type.equals(INT32) || type.equals(INT64) || type.equals(FLOAT) || type.equals(DOUBLE);
+ }
+
+ private boolean isSupportedArithmeticUnaryType(Type type) {
+ return isSupportedArithmeticBinaryType(type) || type.equals(TIMESTAMP);
+ }
+
+ private Object evaluateArithmeticNegation(Object value, Type returnType) {
+ if (returnType.equals(INT32)) {
+ int intValue = toInt(value);
+ if (intValue == Integer.MIN_VALUE) {
+ throw new SemanticException(
+ String.format(
+ DataNodeQueryMessages.EXCEPTION_THE_ARG_IS_OUT_OF_RANGE_OF_INT_F8E58471,
+ intValue));
+ }
+ return -intValue;
+ }
+ if (returnType.equals(INT64) || returnType.equals(TIMESTAMP)) {
+ long longValue = toLong(value);
+ if (longValue == Long.MIN_VALUE) {
+ throw new SemanticException(
+ String.format(
+ DataNodeQueryMessages.EXCEPTION_THE_ARG_IS_OUT_OF_RANGE_OF_LONG_9B1C872A,
+ longValue));
+ }
+ return -longValue;
+ }
+ if (returnType.equals(FLOAT)) {
+ return -toFloat(value);
+ }
+ if (returnType.equals(DOUBLE)) {
+ return -toDouble(value);
+ }
+ throw new SemanticException(DataNodeQueryMessages.UNKNOWN_TYPE_2 + returnType);
+ }
+
+ private Object evaluateArithmeticBinary(
+ ArithmeticBinaryExpression.Operator operator,
+ Object left,
+ Type leftType,
+ Object right,
+ Type returnType) {
+ if (returnType.equals(INT32)) {
+ return evaluateIntArithmetic(operator, toInt(left), toInt(right));
+ }
+ if (returnType.equals(INT64)) {
+ return evaluateLongArithmetic(operator, toLong(left), leftType, toLong(right));
+ }
+ if (returnType.equals(FLOAT)) {
+ return evaluateFloatArithmetic(operator, toFloat(left), toFloat(right));
+ }
+ if (returnType.equals(DOUBLE)) {
+ return evaluateDoubleArithmetic(operator, toDouble(left), toDouble(right));
+ }
+ throw new SemanticException(DataNodeQueryMessages.UNKNOWN_TYPE_2 + returnType);
+ }
+
+ private int evaluateIntArithmetic(
+ ArithmeticBinaryExpression.Operator operator, int left, int right) {
+ try {
+ switch (operator) {
+ case ADD:
+ return Math.addExact(left, right);
+ case SUBTRACT:
+ return Math.subtractExact(left, right);
+ case MULTIPLY:
+ return Math.multiplyExact(left, right);
+ case DIVIDE:
+ if (left == Integer.MIN_VALUE && right == -1) {
+ throw new SemanticException(
+ String.format(
+ DataNodeQueryMessages.EXCEPTION_INT_OVERFLOW_ARG_ARG_BB287017, left, right));
+ }
+ return left / right;
+ case MODULUS:
+ return left % right;
+ default:
+ throw new UnsupportedOperationException(
+ DataNodeQueryMessages.UNSUPPORTED_EXPRESSION + operator);
+ }
+ } catch (ArithmeticException e) {
+ throw new SemanticException(e.getMessage());
+ }
+ }
+
+ private long evaluateLongArithmetic(
+ ArithmeticBinaryExpression.Operator operator, long left, Type leftType, long right) {
+ try {
+ switch (operator) {
+ case ADD:
+ return Math.addExact(left, right);
+ case SUBTRACT:
+ return Math.subtractExact(left, right);
+ case MULTIPLY:
+ return Math.multiplyExact(left, right);
+ case DIVIDE:
+ if ((leftType.equals(INT32) && left == Integer.MIN_VALUE && right == -1)
+ || (leftType.equals(INT64) && left == Long.MIN_VALUE && right == -1)) {
+ throw new SemanticException(
+ String.format(
+ DataNodeQueryMessages.EXCEPTION_LONG_OVERFLOW_ARG_ARG_46CC95E2, left, right));
+ }
+ return left / right;
+ case MODULUS:
+ return left % right;
+ default:
+ throw new UnsupportedOperationException(
+ DataNodeQueryMessages.UNSUPPORTED_EXPRESSION + operator);
+ }
+ } catch (ArithmeticException e) {
+ throw new SemanticException(e.getMessage());
+ }
+ }
+
+ private float evaluateFloatArithmetic(
+ ArithmeticBinaryExpression.Operator operator, float left, float right) {
+ switch (operator) {
+ case ADD:
+ return left + right;
+ case SUBTRACT:
+ return left - right;
+ case MULTIPLY:
+ return left * right;
+ case DIVIDE:
+ return left / right;
+ case MODULUS:
+ return left % right;
+ default:
+ throw new UnsupportedOperationException(
+ DataNodeQueryMessages.UNSUPPORTED_EXPRESSION + operator);
+ }
+ }
+
+ private double evaluateDoubleArithmetic(
+ ArithmeticBinaryExpression.Operator operator, double left, double right) {
+ switch (operator) {
+ case ADD:
+ return left + right;
+ case SUBTRACT:
+ return left - right;
+ case MULTIPLY:
+ return left * right;
+ case DIVIDE:
+ return left / right;
+ case MODULUS:
+ return left % right;
+ default:
+ throw new UnsupportedOperationException(
+ DataNodeQueryMessages.UNSUPPORTED_EXPRESSION + operator);
+ }
+ }
+
+ private Object normalizeArithmeticValue(Object value, Type type) {
+ if (type.equals(INT32)) {
+ return toInt(value);
+ }
+ if (type.equals(INT64) || type.equals(TIMESTAMP)) {
+ return toLong(value);
+ }
+ if (type.equals(FLOAT)) {
+ return toFloat(value);
+ }
+ if (type.equals(DOUBLE)) {
+ return toDouble(value);
+ }
+ return value;
+ }
+
+ private Boolean evaluateNumericComparison(
+ ComparisonExpression.Operator operator, Number left, Number right) {
+ if (Double.isNaN(left.doubleValue()) || Double.isNaN(right.doubleValue())) {
Review Comment:
Found and fixed in `939d153bdf9`: `Double.compare` orders NaN above finite values and treats NaN as equal to itself, so constant folding incorrectly made `1.0 < NaN`, `NaN >= 1.0`, `NaN = NaN`, and the derived `<>` predicate true. The interpreter now returns false whenever either operand is NaN, matching `CompareBinaryColumnTransformer`. `testFoldedNaNComparisons` and the focused IT cover these cases.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support constant folding for insert values [iotdb]
Posted by "Caideyipi (via GitHub)" <gi...@apache.org>.
Caideyipi commented on code in PR #17850:
URL: https://github.com/apache/iotdb/pull/17850#discussion_r4373907393
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/IrExpressionInterpreter.java:
##########
@@ -422,17 +426,21 @@ public Object visitInPredicate(InPredicate node, Object context) {
// optimization
if (!inListCache.containsKey(valueList)) {
if (valueList.getValues().stream().allMatch(Literal.class::isInstance)
- && valueList.getValues().stream().noneMatch(NullLiteral.class::isInstance)) {
+ && valueList.getValues().stream().noneMatch(NullLiteral.class::isInstance)
+ && valueList.getValues().stream()
+ .allMatch(item -> type(item).equals(type(node.getValue())))) {
set =
valueList.getValues().stream()
.map(expr -> processWithExceptionHandling(expr, context))
+ // INT32 literals and folded arithmetic may use different Java containers.
+ .map(item -> normalizeArithmeticValue(item, type(node.getValue())))
.collect(Collectors.toSet());
}
inListCache.put(valueList, set);
}
if (set != null) {
- return set.contains(value);
+ return set.contains(normalizeArithmeticValue(value, type(node.getValue())));
Review Comment:
Found and fixed in `939d153bdf9`: folded INT32 arithmetic can produce `Integer` while an INT32 literal can produce `Long`, so raw `Set.contains` made `1 + 1 IN (2, 3)` false. The IN cache now normalizes same-type values to the SQL native container, and mixed SQL types use numeric comparison. `testFoldedNumericInPredicates` covers both paths.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support constant folding for insert values [iotdb]
Posted by "Caideyipi (via GitHub) via reviews" <re...@iotdb.apache.org>.
Caideyipi commented on PR #17850:
URL: https://github.com/apache/iotdb/pull/17850#issuecomment-6757617429
The prepared `INSERT VALUES` failure came from copying the statement through the eager `InsertRows` path, which discarded its deferred expressions and database context. Its memory estimate also omitted the retained expression tree, and two tests still expected eager materialization. Commit `5960402182788356ba636b7ed12b6167077ade04` adds execution-local copies, accounts for the retained AST, and updates the regression coverage.
Validation passed: `AstMemoryEstimatorTest` (102), `InsertValuesTest` (6), and `IoTDBSetSystemStatusTableIT` under both `TableSimpleIT` and `TableClusterIT` (2 each). The related `IoTDBInsertTableIT` and `IoTDBSessionRelationalIT` standalone regressions passed (1 and 2 tests). Spotless passed. The PR remains a draft pending independent review.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support constant folding for insert values [iotdb]
Posted by "Caideyipi (via GitHub) via reviews" <re...@iotdb.apache.org>.
Caideyipi commented on PR #17850:
URL: https://github.com/apache/iotdb/pull/17850#issuecomment-6758008712
Independent re-review summary (narrow scope)
Reviewed commit: `5960402182788356ba636b7ed12b6167077ade04` (parent: `dc810af74e2c2ec57a1bbcb0460b5f6aade483bd`).
Scope: This review covers only this commit's `InsertValues` prepared-execution copy, deferred-expression memory estimate, and corresponding independent-execution and parse-failure tests.
Result: No actionable findings were identified in this increment, and no fixes were needed. This round does not cover earlier PR changes and does not claim that the full PR received an independent review.
Validation reported for this commit: `AstMemoryEstimatorTest` (102 cases), `InsertValuesTest` (6 cases), `IoTDBSetSystemStatusTableIT` with `TableSimpleIT` and `TableClusterIT` (2 cases each), and related standalone regression tests passed. These checks were not rerun in this review.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support constant folding for insert values [iotdb]
Posted by "jt2594838 (via GitHub) via reviews" <re...@iotdb.apache.org>.
jt2594838 merged PR #17850:
URL: https://github.com/apache/iotdb/pull/17850
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support constant folding for insert values [iotdb]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #17850:
URL: https://github.com/apache/iotdb/pull/17850#issuecomment-4628424016
## [Codecov](https://app.codecov.io/gh/apache/iotdb/pull/17850?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `0.56180%` with `177 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 40.79%. Comparing base ([`594fb87`](https://app.codecov.io/gh/apache/iotdb/commit/594fb879c4d21398449291ccdcbe0d0e0ec26631?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`88803de`](https://app.codecov.io/gh/apache/iotdb/commit/88803decb3af030bc26ab712cc8ac4d1695a783d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
| [Files with missing lines](https://app.codecov.io/gh/apache/iotdb/pull/17850?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [...ryengine/plan/relational/sql/ast/InsertValues.java](https://app.codecov.io/gh/apache/iotdb/pull/17850?src=pr&el=tree&filepath=iotdb-core%2Fdatanode%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fiotdb%2Fdb%2Fqueryengine%2Fplan%2Frelational%2Fsql%2Fast%2FInsertValues.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aW90ZGItY29yZS9kYXRhbm9kZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaW90ZGIvZGIvcXVlcnllbmdpbmUvcGxhbi9yZWxhdGlvbmFsL3NxbC9hc3QvSW5zZXJ0VmFsdWVzLmphdmE=) | 0.00% | [140 Missing :warning: ](https://app.codecov.io/gh/apache/iotdb/pull/17850?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [.../queryengine/plan/relational/sql/util/AstUtil.java](https://app.codecov.io/gh/apache/iotdb/pull/17850?src=pr&el=tree&filepath=iotdb-core%2Fdatanode%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fiotdb%2Fdb%2Fqueryengine%2Fplan%2Frelational%2Fsql%2Futil%2FAstUtil.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aW90ZGItY29yZS9kYXRhbm9kZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaW90ZGIvZGIvcXVlcnllbmdpbmUvcGxhbi9yZWxhdGlvbmFsL3NxbC91dGlsL0FzdFV0aWwuamF2YQ==) | 0.00% | [32 Missing :warning: ](https://app.codecov.io/gh/apache/iotdb/pull/17850?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [...yengine/plan/relational/sql/parser/AstBuilder.java](https://app.codecov.io/gh/apache/iotdb/pull/17850?src=pr&el=tree&filepath=iotdb-core%2Fdatanode%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fiotdb%2Fdb%2Fqueryengine%2Fplan%2Frelational%2Fsql%2Fparser%2FAstBuilder.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aW90ZGItY29yZS9kYXRhbm9kZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaW90ZGIvZGIvcXVlcnllbmdpbmUvcGxhbi9yZWxhdGlvbmFsL3NxbC9wYXJzZXIvQXN0QnVpbGRlci5qYXZh) | 0.00% | [3 Missing :warning: ](https://app.codecov.io/gh/apache/iotdb/pull/17850?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [...ne/plan/relational/analyzer/StatementAnalyzer.java](https://app.codecov.io/gh/apache/iotdb/pull/17850?src=pr&el=tree&filepath=iotdb-core%2Fdatanode%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fiotdb%2Fdb%2Fqueryengine%2Fplan%2Frelational%2Fanalyzer%2FStatementAnalyzer.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aW90ZGItY29yZS9kYXRhbm9kZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaW90ZGIvZGIvcXVlcnllbmdpbmUvcGxhbi9yZWxhdGlvbmFsL2FuYWx5emVyL1N0YXRlbWVudEFuYWx5emVyLmphdmE=) | 33.33% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/iotdb/pull/17850?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #17850 +/- ##
============================================
- Coverage 40.81% 40.79% -0.02%
- Complexity 2610 2612 +2
============================================
Files 5200 5201 +1
Lines 353732 353774 +42
Branches 45266 45270 +4
============================================
- Hits 144361 144339 -22
- Misses 209371 209435 +64
```
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/iotdb/pull/17850?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support constant folding for insert values [iotdb]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17850:
URL: https://github.com/apache/iotdb/pull/17850#issuecomment-4628932004
## [](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17850) **Quality Gate passed**
Issues
 [9 New issues](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17850&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17850&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_iotdb&pullRequest=17850&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_iotdb&pullRequest=17850&metric=new_coverage&view=list)
 [3.7% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_iotdb&pullRequest=17850&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17850)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support constant folding for insert values [iotdb]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17850:
URL: https://github.com/apache/iotdb/pull/17850#issuecomment-4778848063
## [](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17850) **Quality Gate passed**
Issues
 [20 New issues](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17850&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_iotdb&pullRequest=17850&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_iotdb&pullRequest=17850&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_iotdb&pullRequest=17850&metric=new_coverage&view=list)
 [3.3% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_iotdb&pullRequest=17850&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=17850)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support constant folding for insert values [iotdb]
Posted by "Caideyipi (via GitHub) via reviews" <re...@iotdb.apache.org>.
Caideyipi commented on code in PR #17850:
URL: https://github.com/apache/iotdb/pull/17850#discussion_r4533274937
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/IrExpressionInterpreter.java:
##########
@@ -981,6 +922,218 @@ private boolean hasUnresolvedValue(List<Object> values) {
return values.stream().anyMatch(instanceOf(Expression.class));
}
+ private boolean isSupportedArithmeticBinaryType(Type type) {
+ return type.equals(INT32) || type.equals(INT64) || type.equals(FLOAT) || type.equals(DOUBLE);
+ }
+
+ private boolean isSupportedArithmeticUnaryType(Type type) {
+ return isSupportedArithmeticBinaryType(type) || type.equals(TIMESTAMP);
+ }
+
+ private Object evaluateArithmeticNegation(Object value, Type returnType) {
+ if (returnType.equals(INT32)) {
+ int intValue = toInt(value);
+ if (intValue == Integer.MIN_VALUE) {
+ throw new SemanticException(
+ String.format(
+ DataNodeQueryMessages.EXCEPTION_THE_ARG_IS_OUT_OF_RANGE_OF_INT_F8E58471,
+ intValue));
+ }
+ return -intValue;
+ }
+ if (returnType.equals(INT64) || returnType.equals(TIMESTAMP)) {
+ long longValue = toLong(value);
+ if (longValue == Long.MIN_VALUE) {
+ throw new SemanticException(
+ String.format(
+ DataNodeQueryMessages.EXCEPTION_THE_ARG_IS_OUT_OF_RANGE_OF_LONG_9B1C872A,
+ longValue));
+ }
+ return -longValue;
+ }
+ if (returnType.equals(FLOAT)) {
+ return -toFloat(value);
+ }
+ if (returnType.equals(DOUBLE)) {
+ return -toDouble(value);
+ }
+ throw new SemanticException(DataNodeQueryMessages.UNKNOWN_TYPE_2 + returnType);
+ }
+
+ private Object evaluateArithmeticBinary(
+ ArithmeticBinaryExpression.Operator operator,
+ Object left,
+ Type leftType,
+ Object right,
+ Type returnType) {
+ if (returnType.equals(INT32)) {
+ return evaluateIntArithmetic(operator, toInt(left), toInt(right));
+ }
+ if (returnType.equals(INT64)) {
+ return evaluateLongArithmetic(operator, toLong(left), leftType, toLong(right));
+ }
+ if (returnType.equals(FLOAT)) {
+ return evaluateFloatArithmetic(operator, toFloat(left), toFloat(right));
+ }
+ if (returnType.equals(DOUBLE)) {
+ return evaluateDoubleArithmetic(operator, toDouble(left), toDouble(right));
+ }
+ throw new SemanticException(DataNodeQueryMessages.UNKNOWN_TYPE_2 + returnType);
+ }
+
+ private int evaluateIntArithmetic(
+ ArithmeticBinaryExpression.Operator operator, int left, int right) {
+ try {
+ switch (operator) {
+ case ADD:
+ return Math.addExact(left, right);
+ case SUBTRACT:
+ return Math.subtractExact(left, right);
+ case MULTIPLY:
+ return Math.multiplyExact(left, right);
+ case DIVIDE:
+ if (left == Integer.MIN_VALUE && right == -1) {
+ throw new SemanticException(
+ String.format(
+ DataNodeQueryMessages.EXCEPTION_INT_OVERFLOW_ARG_ARG_BB287017, left, right));
+ }
+ return left / right;
+ case MODULUS:
+ return left % right;
+ default:
+ throw new UnsupportedOperationException(
+ DataNodeQueryMessages.UNSUPPORTED_EXPRESSION + operator);
+ }
Review Comment:
Updated all four numeric arithmetic helpers to use exhaustive switch expressions without a default branch. Adding an `ArithmeticBinaryExpression.Operator` now requires handling it at compile time. The existing division overflow checks are preserved. Fixed in `05899a3a9c2aca79861ede7bc2d2e5560021dc99`.
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/IrExpressionInterpreter.java:
##########
@@ -981,6 +922,218 @@ private boolean hasUnresolvedValue(List<Object> values) {
return values.stream().anyMatch(instanceOf(Expression.class));
}
+ private boolean isSupportedArithmeticBinaryType(Type type) {
+ return type.equals(INT32) || type.equals(INT64) || type.equals(FLOAT) || type.equals(DOUBLE);
+ }
+
+ private boolean isSupportedArithmeticUnaryType(Type type) {
+ return isSupportedArithmeticBinaryType(type) || type.equals(TIMESTAMP);
+ }
+
+ private Object evaluateArithmeticNegation(Object value, Type returnType) {
+ if (returnType.equals(INT32)) {
+ int intValue = toInt(value);
+ if (intValue == Integer.MIN_VALUE) {
+ throw new SemanticException(
+ String.format(
+ DataNodeQueryMessages.EXCEPTION_THE_ARG_IS_OUT_OF_RANGE_OF_INT_F8E58471,
+ intValue));
+ }
+ return -intValue;
+ }
+ if (returnType.equals(INT64) || returnType.equals(TIMESTAMP)) {
+ long longValue = toLong(value);
+ if (longValue == Long.MIN_VALUE) {
+ throw new SemanticException(
+ String.format(
+ DataNodeQueryMessages.EXCEPTION_THE_ARG_IS_OUT_OF_RANGE_OF_LONG_9B1C872A,
+ longValue));
+ }
+ return -longValue;
+ }
+ if (returnType.equals(FLOAT)) {
+ return -toFloat(value);
+ }
+ if (returnType.equals(DOUBLE)) {
+ return -toDouble(value);
+ }
+ throw new SemanticException(DataNodeQueryMessages.UNKNOWN_TYPE_2 + returnType);
+ }
+
+ private Object evaluateArithmeticBinary(
+ ArithmeticBinaryExpression.Operator operator,
+ Object left,
+ Type leftType,
+ Object right,
+ Type returnType) {
+ if (returnType.equals(INT32)) {
+ return evaluateIntArithmetic(operator, toInt(left), toInt(right));
+ }
+ if (returnType.equals(INT64)) {
+ return evaluateLongArithmetic(operator, toLong(left), leftType, toLong(right));
+ }
+ if (returnType.equals(FLOAT)) {
+ return evaluateFloatArithmetic(operator, toFloat(left), toFloat(right));
+ }
+ if (returnType.equals(DOUBLE)) {
+ return evaluateDoubleArithmetic(operator, toDouble(left), toDouble(right));
+ }
+ throw new SemanticException(DataNodeQueryMessages.UNKNOWN_TYPE_2 + returnType);
+ }
+
+ private int evaluateIntArithmetic(
+ ArithmeticBinaryExpression.Operator operator, int left, int right) {
+ try {
+ switch (operator) {
+ case ADD:
+ return Math.addExact(left, right);
+ case SUBTRACT:
+ return Math.subtractExact(left, right);
+ case MULTIPLY:
+ return Math.multiplyExact(left, right);
+ case DIVIDE:
+ if (left == Integer.MIN_VALUE && right == -1) {
+ throw new SemanticException(
+ String.format(
+ DataNodeQueryMessages.EXCEPTION_INT_OVERFLOW_ARG_ARG_BB287017, left, right));
+ }
+ return left / right;
+ case MODULUS:
+ return left % right;
+ default:
+ throw new UnsupportedOperationException(
+ DataNodeQueryMessages.UNSUPPORTED_EXPRESSION + operator);
+ }
+ } catch (ArithmeticException e) {
+ throw new SemanticException(e.getMessage());
+ }
+ }
+
+ private long evaluateLongArithmetic(
+ ArithmeticBinaryExpression.Operator operator, long left, Type leftType, long right) {
+ try {
+ switch (operator) {
+ case ADD:
+ return Math.addExact(left, right);
+ case SUBTRACT:
+ return Math.subtractExact(left, right);
+ case MULTIPLY:
+ return Math.multiplyExact(left, right);
+ case DIVIDE:
+ if ((leftType.equals(INT32) && left == Integer.MIN_VALUE && right == -1)
+ || (leftType.equals(INT64) && left == Long.MIN_VALUE && right == -1)) {
+ throw new SemanticException(
+ String.format(
+ DataNodeQueryMessages.EXCEPTION_LONG_OVERFLOW_ARG_ARG_46CC95E2, left, right));
+ }
+ return left / right;
+ case MODULUS:
+ return left % right;
+ default:
+ throw new UnsupportedOperationException(
+ DataNodeQueryMessages.UNSUPPORTED_EXPRESSION + operator);
+ }
+ } catch (ArithmeticException e) {
+ throw new SemanticException(e.getMessage());
+ }
+ }
+
+ private float evaluateFloatArithmetic(
+ ArithmeticBinaryExpression.Operator operator, float left, float right) {
+ switch (operator) {
+ case ADD:
+ return left + right;
+ case SUBTRACT:
+ return left - right;
+ case MULTIPLY:
+ return left * right;
+ case DIVIDE:
+ return left / right;
+ case MODULUS:
+ return left % right;
+ default:
+ throw new UnsupportedOperationException(
+ DataNodeQueryMessages.UNSUPPORTED_EXPRESSION + operator);
+ }
+ }
+
+ private double evaluateDoubleArithmetic(
+ ArithmeticBinaryExpression.Operator operator, double left, double right) {
+ switch (operator) {
+ case ADD:
+ return left + right;
+ case SUBTRACT:
+ return left - right;
+ case MULTIPLY:
+ return left * right;
+ case DIVIDE:
+ return left / right;
+ case MODULUS:
+ return left % right;
+ default:
+ throw new UnsupportedOperationException(
+ DataNodeQueryMessages.UNSUPPORTED_EXPRESSION + operator);
+ }
+ }
+
+ private Object normalizeArithmeticValue(Object value, Type type) {
+ if (type.equals(INT32)) {
+ return toInt(value);
+ }
+ if (type.equals(INT64) || type.equals(TIMESTAMP)) {
+ return toLong(value);
+ }
+ if (type.equals(FLOAT)) {
+ return toFloat(value);
+ }
+ if (type.equals(DOUBLE)) {
+ return toDouble(value);
+ }
+ return value;
+ }
+
+ private Boolean evaluateNumericComparison(
+ ComparisonExpression.Operator operator, Number left, Number right) {
+ if (Double.isNaN(left.doubleValue()) || Double.isNaN(right.doubleValue())) {
+ return false;
+ }
+ int comparison =
+ (left instanceof Float
+ || left instanceof Double
+ || right instanceof Float
+ || right instanceof Double)
+ ? Double.compare(left.doubleValue(), right.doubleValue())
+ : Long.compare(left.longValue(), right.longValue());
+ switch (operator) {
+ case LESS_THAN:
+ return comparison < 0;
+ case LESS_THAN_OR_EQUAL:
+ return comparison <= 0;
+ case EQUAL:
+ return comparison == 0;
+ case NOT_EQUAL:
+ return comparison != 0;
+ default:
+ return null;
Review Comment:
Changed the numeric-comparison fallback to throw `UnsupportedOperationException` using the existing localized error message instead of returning `null`. Greater-than operators are normalized before this helper, and `IS DISTINCT FROM` is handled separately. Fixed in `05899a3a9c2aca79861ede7bc2d2e5560021dc99`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support constant folding for insert values [iotdb]
Posted by "Caideyipi (via GitHub) via reviews" <re...@iotdb.apache.org>.
Caideyipi commented on PR #17850:
URL: https://github.com/apache/iotdb/pull/17850#issuecomment-6785276618
Addressed both review comments in `05899a3a9c2aca79861ede7bc2d2e5560021dc99`.
- All four numeric arithmetic helpers now use exhaustive switch expressions without a default.
- Unexpected numeric comparison operators throw an exception instead of returning `null`.
Validation passed: Spotless, the clean English DataNode dependency reactor with `InsertValuesTest` (6 passed), and the clean Chinese DataNode dependency-reactor test compilation. Build-result caching was disabled. Integration tests were not rerun for this update.
Regarding the [Codecov report](https://github.com/apache/iotdb/pull/17850#issuecomment-4628424016): it reports coverage for the earlier `5960402` revision. The checks above do not establish a patch coverage percentage for this commit; updated coverage is tracked by CI.
Comment-handling baseline: `266968aeb16d094b94dcca0182b8a156a94225b1`. Final local, source-branch, and PR heads were verified as `05899a3a9c2aca79861ede7bc2d2e5560021dc99`. This was a focused comment update, not a full independent self-review. The PR remains a draft pending an independent review of the latest full diff. I left the review discussions unresolved.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org