-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Enhance approx_percentile with strict weight validation, improved error handling and IT coverage #17368
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
Enhance approx_percentile with strict weight validation, improved error handling and IT coverage #17368
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,8 @@ | |
|
|
||
| package org.apache.iotdb.db.queryengine.execution.operator.source.relational.aggregation; | ||
|
|
||
| import org.apache.iotdb.db.exception.sql.SemanticException; | ||
|
|
||
| import org.apache.tsfile.block.column.Column; | ||
| import org.apache.tsfile.enums.TSDataType; | ||
|
|
||
|
|
@@ -32,6 +34,12 @@ public void addIntInput(Column[] arguments, AggregationMask mask) { | |
|
|
||
| if (mask.isSelectAll()) { | ||
| for (int i = 0; i < valueColumn.getPositionCount(); i++) { | ||
| if (weightColumn.isNull(i)) { | ||
| continue; | ||
| } | ||
|
Comment on lines
+37
to
+39
|
||
| if (weightColumn.getInt(i) < 1) { | ||
| throw new SemanticException("weight must be >= 1, was " + weightColumn.getInt(i)); | ||
| } | ||
| if (!valueColumn.isNull(i)) { | ||
| tDigest.add(valueColumn.getInt(i), weightColumn.getInt(i)); | ||
| } | ||
|
Comment on lines
+37
to
45
|
||
|
|
@@ -41,6 +49,12 @@ public void addIntInput(Column[] arguments, AggregationMask mask) { | |
| int position; | ||
| for (int i = 0; i < positionCount; i++) { | ||
| position = selectedPositions[i]; | ||
| if (weightColumn.isNull(position)) { | ||
| continue; | ||
| } | ||
| if (weightColumn.getInt(position) < 1) { | ||
| throw new SemanticException("weight must be >= 1, was " + weightColumn.getInt(position)); | ||
| } | ||
| if (!valueColumn.isNull(position)) { | ||
| tDigest.add(valueColumn.getInt(position), weightColumn.getInt(position)); | ||
| } | ||
|
|
@@ -57,6 +71,12 @@ public void addLongInput(Column[] arguments, AggregationMask mask) { | |
|
|
||
| if (mask.isSelectAll()) { | ||
| for (int i = 0; i < valueColumn.getPositionCount(); i++) { | ||
| if (weightColumn.isNull(i)) { | ||
| continue; | ||
| } | ||
| if (weightColumn.getInt(i) < 1) { | ||
| throw new SemanticException("weight must be >= 1, was " + weightColumn.getInt(i)); | ||
| } | ||
| if (!valueColumn.isNull(i)) { | ||
| tDigest.add(toDoubleExact(valueColumn.getLong(i)), weightColumn.getInt(i)); | ||
| } | ||
|
|
@@ -66,6 +86,12 @@ public void addLongInput(Column[] arguments, AggregationMask mask) { | |
| int position; | ||
| for (int i = 0; i < positionCount; i++) { | ||
| position = selectedPositions[i]; | ||
| if (weightColumn.isNull(position)) { | ||
| continue; | ||
| } | ||
| if (weightColumn.getInt(position) < 1) { | ||
| throw new SemanticException("weight must be >= 1, was " + weightColumn.getInt(position)); | ||
| } | ||
| if (!valueColumn.isNull(position)) { | ||
| tDigest.add(toDoubleExact(valueColumn.getLong(position)), weightColumn.getInt(position)); | ||
| } | ||
|
|
@@ -82,6 +108,12 @@ public void addFloatInput(Column[] arguments, AggregationMask mask) { | |
|
|
||
| if (mask.isSelectAll()) { | ||
| for (int i = 0; i < valueColumn.getPositionCount(); i++) { | ||
| if (weightColumn.isNull(i)) { | ||
| continue; | ||
| } | ||
| if (weightColumn.getInt(i) < 1) { | ||
| throw new SemanticException("weight must be >= 1, was " + weightColumn.getInt(i)); | ||
| } | ||
| if (!valueColumn.isNull(i)) { | ||
| tDigest.add(valueColumn.getFloat(i), weightColumn.getInt(i)); | ||
| } | ||
|
|
@@ -91,6 +123,12 @@ public void addFloatInput(Column[] arguments, AggregationMask mask) { | |
| int position; | ||
| for (int i = 0; i < positionCount; i++) { | ||
| position = selectedPositions[i]; | ||
| if (weightColumn.isNull(position)) { | ||
| continue; | ||
| } | ||
| if (weightColumn.getInt(position) < 1) { | ||
| throw new SemanticException("weight must be >= 1, was " + weightColumn.getInt(position)); | ||
| } | ||
| if (!valueColumn.isNull(position)) { | ||
| tDigest.add(valueColumn.getFloat(position), weightColumn.getInt(position)); | ||
| } | ||
|
|
@@ -107,6 +145,12 @@ public void addDoubleInput(Column[] arguments, AggregationMask mask) { | |
|
|
||
| if (mask.isSelectAll()) { | ||
| for (int i = 0; i < valueColumn.getPositionCount(); i++) { | ||
| if (weightColumn.isNull(i)) { | ||
| continue; | ||
| } | ||
| if (weightColumn.getInt(i) < 1) { | ||
| throw new SemanticException("weight must be >= 1, was " + weightColumn.getInt(i)); | ||
| } | ||
| if (!valueColumn.isNull(i)) { | ||
| tDigest.add(valueColumn.getDouble(i), weightColumn.getInt(i)); | ||
| } | ||
|
|
@@ -116,6 +160,12 @@ public void addDoubleInput(Column[] arguments, AggregationMask mask) { | |
| int position; | ||
| for (int i = 0; i < positionCount; i++) { | ||
| position = selectedPositions[i]; | ||
| if (weightColumn.isNull(position)) { | ||
| continue; | ||
| } | ||
| if (weightColumn.getInt(position) < 1) { | ||
| throw new SemanticException("weight must be >= 1, was " + weightColumn.getInt(position)); | ||
| } | ||
| if (!valueColumn.isNull(position)) { | ||
| tDigest.add(valueColumn.getDouble(position), weightColumn.getInt(position)); | ||
| } | ||
|
|
||
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 new NULL-weight test only covers the non-grouped execution path. Since group-by uses a different (grouped) accumulator, it would be good to add an IT that exercises
approx_percentile(..., null, ...)(and an invalid weight like -1) under GROUP BY to ensure the grouped implementation matches the intended semantics and doesn’t regress.