-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fix truncate() function #188
Changes from 5 commits
2ee64f3
ca87242
10ae053
a9e18e5
ba76b90
d91ec92
21619b4
8599dbd
5622094
3cde7ce
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 | ||||
---|---|---|---|---|---|---|
|
@@ -500,26 +500,30 @@ private static DefaultFunctionResolver truncate() { | |||||
FunctionDSL.impl( | ||||||
FunctionDSL.nullMissingHandling( | ||||||
(x, y) -> new ExprLongValue( | ||||||
new BigDecimal(x.integerValue()).setScale(y.integerValue(), | ||||||
RoundingMode.DOWN).longValue())), | ||||||
new BigDecimal(String.valueOf(x.integerValue())).setScale(y.integerValue(), | ||||||
x.integerValue() > 0 ? RoundingMode.FLOOR : RoundingMode.CEILING) | ||||||
.longValue())), | ||||||
LONG, INTEGER, INTEGER), | ||||||
FunctionDSL.impl( | ||||||
FunctionDSL.nullMissingHandling( | ||||||
(x, y) -> new ExprLongValue( | ||||||
new BigDecimal(x.integerValue()).setScale(y.integerValue(), | ||||||
RoundingMode.DOWN).longValue())), | ||||||
new BigDecimal(String.valueOf(x.longValue())).setScale(y.integerValue(), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 21619b4 |
||||||
x.longValue() > 0 ? RoundingMode.FLOOR : RoundingMode.CEILING) | ||||||
.longValue())), | ||||||
LONG, LONG, INTEGER), | ||||||
FunctionDSL.impl( | ||||||
FunctionDSL.nullMissingHandling( | ||||||
(x, y) -> new ExprDoubleValue( | ||||||
new BigDecimal(x.floatValue()).setScale(y.integerValue(), | ||||||
RoundingMode.DOWN).doubleValue())), | ||||||
new BigDecimal(String.valueOf(x.floatValue())).setScale(y.integerValue(), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 21619b4 |
||||||
x.floatValue() > 0 ? RoundingMode.FLOOR : RoundingMode.CEILING) | ||||||
.doubleValue())), | ||||||
DOUBLE, FLOAT, INTEGER), | ||||||
FunctionDSL.impl( | ||||||
FunctionDSL.nullMissingHandling( | ||||||
(x, y) -> new ExprDoubleValue( | ||||||
new BigDecimal(x.doubleValue()).setScale(y.integerValue(), | ||||||
RoundingMode.DOWN).doubleValue())), | ||||||
new BigDecimal(String.valueOf(x.doubleValue())).setScale(y.integerValue(), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 21619b4 |
||||||
x.doubleValue() > 0 ? RoundingMode.FLOOR : RoundingMode.CEILING) | ||||||
.doubleValue())), | ||||||
DOUBLE, DOUBLE, INTEGER)); | ||||||
} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -192,12 +192,12 @@ public void ceil_int_value(Integer value) { | |||||
assertThat( | ||||||
ceil.valueOf(valueEnv()), | ||||||
allOf(hasType(INTEGER), hasValue((int) Math.ceil(value)))); | ||||||
assertEquals(String.format("ceil(%s)", value.toString()), ceil.toString()); | ||||||
assertEquals(String.format("ceil(%s)", value), ceil.toString()); | ||||||
|
||||||
FunctionExpression ceiling = DSL.ceiling(DSL.literal(value)); | ||||||
assertThat( | ||||||
ceiling.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.ceil(value)))); | ||||||
assertEquals(String.format("ceiling(%s)", value.toString()), ceiling.toString()); | ||||||
assertEquals(String.format("ceiling(%s)", value), ceiling.toString()); | ||||||
} | ||||||
|
||||||
/** | ||||||
|
@@ -209,12 +209,12 @@ public void ceil_long_value(Long value) { | |||||
FunctionExpression ceil = DSL.ceil(DSL.literal(value)); | ||||||
assertThat( | ||||||
ceil.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.ceil(value)))); | ||||||
assertEquals(String.format("ceil(%s)", value.toString()), ceil.toString()); | ||||||
assertEquals(String.format("ceil(%s)", value), ceil.toString()); | ||||||
|
||||||
FunctionExpression ceiling = DSL.ceiling(DSL.literal(value)); | ||||||
assertThat( | ||||||
ceiling.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.ceil(value)))); | ||||||
assertEquals(String.format("ceiling(%s)", value.toString()), ceiling.toString()); | ||||||
assertEquals(String.format("ceiling(%s)", value), ceiling.toString()); | ||||||
} | ||||||
|
||||||
/** | ||||||
|
@@ -226,12 +226,12 @@ public void ceil_float_value(Float value) { | |||||
FunctionExpression ceil = DSL.ceil(DSL.literal(value)); | ||||||
assertThat( | ||||||
ceil.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.ceil(value)))); | ||||||
assertEquals(String.format("ceil(%s)", value.toString()), ceil.toString()); | ||||||
assertEquals(String.format("ceil(%s)", value), ceil.toString()); | ||||||
|
||||||
FunctionExpression ceiling = DSL.ceiling(DSL.literal(value)); | ||||||
assertThat( | ||||||
ceiling.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.ceil(value)))); | ||||||
assertEquals(String.format("ceiling(%s)", value.toString()), ceiling.toString()); | ||||||
assertEquals(String.format("ceiling(%s)", value), ceiling.toString()); | ||||||
} | ||||||
|
||||||
/** | ||||||
|
@@ -243,12 +243,12 @@ public void ceil_double_value(Double value) { | |||||
FunctionExpression ceil = DSL.ceil(DSL.literal(value)); | ||||||
assertThat( | ||||||
ceil.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.ceil(value)))); | ||||||
assertEquals(String.format("ceil(%s)", value.toString()), ceil.toString()); | ||||||
assertEquals(String.format("ceil(%s)", value), ceil.toString()); | ||||||
|
||||||
FunctionExpression ceiling = DSL.ceiling(DSL.literal(value)); | ||||||
assertThat( | ||||||
ceiling.valueOf(valueEnv()), allOf(hasType(INTEGER), hasValue((int) Math.ceil(value)))); | ||||||
assertEquals(String.format("ceiling(%s)", value.toString()), ceiling.toString()); | ||||||
assertEquals(String.format("ceiling(%s)", value), ceiling.toString()); | ||||||
} | ||||||
|
||||||
/** | ||||||
|
@@ -1721,51 +1721,55 @@ public void sqrt_missing_value() { | |||||
* Test truncate with integer value. | ||||||
*/ | ||||||
@ParameterizedTest(name = "truncate({0}, {1})") | ||||||
@ValueSource(ints = {2, -2}) | ||||||
@ValueSource(ints = {2, -2, Integer.MAX_VALUE, Integer.MIN_VALUE}) | ||||||
public void truncate_int_value(Integer value) { | ||||||
FunctionExpression truncate = DSL.truncate(DSL.literal(value), DSL.literal(1)); | ||||||
assertThat( | ||||||
truncate.valueOf(valueEnv()), allOf(hasType(LONG), | ||||||
hasValue(new BigDecimal(value).setScale(1, RoundingMode.DOWN).longValue()))); | ||||||
hasValue(new BigDecimal(String.valueOf(value)).setScale(1, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 21619b4 |
||||||
value > 0 ? RoundingMode.FLOOR : RoundingMode.CEILING).longValue()))); | ||||||
assertEquals(String.format("truncate(%s, 1)", value), truncate.toString()); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Test truncate with long value. | ||||||
*/ | ||||||
@ParameterizedTest(name = "truncate({0}, {1})") | ||||||
@ValueSource(longs = {2L, -2L}) | ||||||
@ValueSource(longs = {2L, -2L, Long.MAX_VALUE, Long.MIN_VALUE}) | ||||||
public void truncate_long_value(Long value) { | ||||||
FunctionExpression truncate = DSL.truncate(DSL.literal(value), DSL.literal(1)); | ||||||
assertThat( | ||||||
truncate.valueOf(valueEnv()), allOf(hasType(LONG), | ||||||
hasValue(new BigDecimal(value).setScale(1, RoundingMode.DOWN).longValue()))); | ||||||
hasValue(new BigDecimal(String.valueOf(value)).setScale(1, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 21619b4 |
||||||
value > 0 ? RoundingMode.FLOOR : RoundingMode.CEILING).longValue()))); | ||||||
assertEquals(String.format("truncate(%s, 1)", value), truncate.toString()); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Test truncate with float value. | ||||||
*/ | ||||||
@ParameterizedTest(name = "truncate({0}, {1})") | ||||||
@ValueSource(floats = {2F, -2F}) | ||||||
@ValueSource(floats = {2F, -2F, Float.MAX_VALUE, Float.MIN_VALUE}) | ||||||
public void truncate_float_value(Float value) { | ||||||
FunctionExpression truncate = DSL.truncate(DSL.literal(value), DSL.literal(1)); | ||||||
assertThat( | ||||||
truncate.valueOf(valueEnv()), allOf(hasType(DOUBLE), | ||||||
hasValue(new BigDecimal(value).setScale(1, RoundingMode.DOWN).doubleValue()))); | ||||||
hasValue(new BigDecimal(String.valueOf(value)).setScale(1, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 21619b4 |
||||||
value > 0 ? RoundingMode.FLOOR : RoundingMode.CEILING).doubleValue()))); | ||||||
assertEquals(String.format("truncate(%s, 1)", value), truncate.toString()); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Test truncate with double value. | ||||||
*/ | ||||||
@ParameterizedTest(name = "truncate({0}, {1})") | ||||||
@ValueSource(doubles = {2D, -2D}) | ||||||
@ValueSource(doubles = {2D, -1.2D, Double.MAX_VALUE, Double.MIN_VALUE}) | ||||||
acarbonetto marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
public void truncate_double_value(Double value) { | ||||||
FunctionExpression truncate = DSL.truncate(DSL.literal(value), DSL.literal(1)); | ||||||
assertThat( | ||||||
truncate.valueOf(valueEnv()), allOf(hasType(DOUBLE), | ||||||
hasValue(new BigDecimal(value).setScale(1, RoundingMode.DOWN).doubleValue()))); | ||||||
hasValue(new BigDecimal(String.valueOf(value)).setScale(1, | ||||||
MaxKsyunz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
value > 0 ? RoundingMode.FLOOR : RoundingMode.CEILING).doubleValue()))); | ||||||
assertEquals(String.format("truncate(%s, 1)", value), truncate.toString()); | ||||||
} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ "index" : { "_id" : "1" } } | ||
{"key": "null", "val": null} | ||
{ "index" : { "_id" : "2" } } | ||
{"key": "001: min long", "val": -9.223372036854776e+18} | ||
{ "index" : { "_id" : "3" } } | ||
{"key": "002: min int minus one", "val": -2147483649.0} | ||
{ "index" : { "_id" : "4" } } | ||
{"key": "003: min int", "val": -2147483648.0} | ||
{ "index" : { "_id" : "5" } } | ||
{"key": "004: min short minus one", "val": -32769.0} | ||
{ "index" : { "_id" : "6" } } | ||
{"key": "005: min short", "val": -32768.0} | ||
{ "index" : { "_id" : "7" } } | ||
{"key": "006: pgtest float8 value 2", "val": -34.84} | ||
{ "index" : { "_id" : "8" } } | ||
{"key": "007: -two", "val": -2.0} | ||
{ "index" : { "_id" : "9" } } | ||
{"key": "008: -1.2", "val": -1.2} | ||
{ "index" : { "_id" : "10" } } | ||
{"key": "009: -one", "val": -1.0} | ||
{ "index" : { "_id" : "11" } } | ||
{"key": "010: zero", "val": 0.0} | ||
{ "index" : { "_id" : "12" } } | ||
{"key": "011: one", "val": 1.0} | ||
{ "index" : { "_id" : "13" } } | ||
{"key": "012: 1.3", "val": 1.3} | ||
{ "index" : { "_id" : "14" } } | ||
{"key": "013: two", "val": 2.0} | ||
{ "index" : { "_id" : "15" } } | ||
{"key": "014: pgtest float8 value 1", "val": 1004.3} | ||
{ "index" : { "_id" : "16" } } | ||
{"key": "015: max short", "val": 32767.0} | ||
{ "index" : { "_id" : "17" } } | ||
{"key": "016: max short plus one", "val": 32768.0} | ||
{ "index" : { "_id" : "18" } } | ||
{"key": "017: max int", "val": 2147483647.0} | ||
{ "index" : { "_id" : "19" } } | ||
{"key": "018: max int plus one", "val": 2147483648.0} | ||
{ "index" : { "_id" : "20" } } | ||
{"key": "019: max long", "val": 9.223372036854776e+18} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"mappings" : { | ||
"properties" : { | ||
"key" : { | ||
"type" : "keyword" | ||
}, | ||
"val" : { | ||
"type" : "double" | ||
} | ||
} | ||
} | ||
} |
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.
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.
Addressed in 21619b4