Skip to content

Commit

Permalink
Fix Data-Correctness Bug in GTE Comparison in BinaryOperatorTransform…
Browse files Browse the repository at this point in the history
…Function (#9461)

* Fix Bug in Handling GTE Comparison in BinaryOperatorTransformFunction

* Add UT

* Fix bug and add another test
  • Loading branch information
ankitsultana authored Sep 27, 2022
1 parent 66a9e0e commit 83b7f15
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ private void fillIntResultArray(ProjectionBlock projectionBlock, float[] leftVal
private void fillLongResultArray(ProjectionBlock projectionBlock, float[] leftValues, int length) {
long[] rightValues = _rightTransformFunction.transformToLongValuesSV(projectionBlock);
for (int i = 0; i < length; i++) {
_results[i] = compare(leftValues[i], rightValues[i]);
_results[i] = getIntResult(compare(leftValues[i], rightValues[i]));
}
}

Expand Down Expand Up @@ -446,7 +446,7 @@ private void fillIntResultArray(ProjectionBlock projectionBlock, double[] leftVa
private void fillLongResultArray(ProjectionBlock projectionBlock, double[] leftValues, int length) {
long[] rightValues = _rightTransformFunction.transformToLongValuesSV(projectionBlock);
for (int i = 0; i < length; i++) {
_results[i] = compare(leftValues[i], rightValues[i]);
_results[i] = getIntResult(compare(leftValues[i], rightValues[i]));
}
}

Expand Down Expand Up @@ -526,17 +526,17 @@ private void fillStringResultArray(ProjectionBlock projectionBlock, BigDecimal[]

private int compare(long left, double right) {
if (Math.abs(left) <= 1L << 53) {
return getIntResult(Double.compare(left, right));
return Double.compare(left, right);
} else {
return getIntResult(BigDecimal.valueOf(left).compareTo(BigDecimal.valueOf(right)));
return BigDecimal.valueOf(left).compareTo(BigDecimal.valueOf(right));
}
}

private int compare(double left, long right) {
if (Math.abs(right) <= 1L << 53) {
return getIntResult(Double.compare(left, right));
return Double.compare(left, right);
} else {
return getIntResult(BigDecimal.valueOf(left).compareTo(BigDecimal.valueOf(right)));
return BigDecimal.valueOf(left).compareTo(BigDecimal.valueOf(right));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ public void testBinaryOperatorTransformFunction() {
expectedValues[i] = getExpectedValue(_stringSVValues[i].compareTo(_stringSVValues[0]));
}
testTransformFunction(transformFunction, expectedValues);

// Test with heterogeneous arguments (long on left-side, double on right-side)
expression = RequestContextUtils.getExpression(
String.format("%s(%s, '%s')", functionName, LONG_SV_COLUMN, _doubleSVValues[0]));
transformFunction = TransformFunctionFactory.get(expression, _dataSourceMap);
for (int i = 0; i < NUM_ROWS; i++) {
expectedValues[i] = getExpectedValue(Double.compare(_longSVValues[i], _doubleSVValues[0]));
}
testTransformFunction(transformFunction, expectedValues);

// Test with heterogeneous arguments (double on left-side, long on right-side)
expression = RequestContextUtils.getExpression(
String.format("%s(%s, '%s')", functionName, DOUBLE_SV_COLUMN, _longSVValues[0]));
transformFunction = TransformFunctionFactory.get(expression, _dataSourceMap);
for (int i = 0; i < NUM_ROWS; i++) {
expectedValues[i] = getExpectedValue(Double.compare(_doubleSVValues[i], _longSVValues[0]));
}
testTransformFunction(transformFunction, expectedValues);
}

@Test(dataProvider = "testIllegalArguments", expectedExceptions = {BadQueryRequestException.class})
Expand Down

0 comments on commit 83b7f15

Please sign in to comment.