Skip to content

Commit

Permalink
Addressed more PR review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Margarit Hakobyan <margarit.hakobyan@improving.com>
  • Loading branch information
margarit-h committed Dec 14, 2022
1 parent d91ec92 commit 21619b4
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -500,28 +500,28 @@ private static DefaultFunctionResolver truncate() {
FunctionDSL.impl(
FunctionDSL.nullMissingHandling(
(x, y) -> new ExprLongValue(
new BigDecimal(String.valueOf(x.integerValue())).setScale(y.integerValue(),
BigDecimal.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(String.valueOf(x.longValue())).setScale(y.integerValue(),
BigDecimal.valueOf(x.longValue()).setScale(y.integerValue(),
x.longValue() > 0 ? RoundingMode.FLOOR : RoundingMode.CEILING)
.longValue())),
LONG, LONG, INTEGER),
FunctionDSL.impl(
FunctionDSL.nullMissingHandling(
(x, y) -> new ExprDoubleValue(
new BigDecimal(String.valueOf(x.floatValue())).setScale(y.integerValue(),
BigDecimal.valueOf(x.floatValue()).setScale(y.integerValue(),
x.floatValue() > 0 ? RoundingMode.FLOOR : RoundingMode.CEILING)
.doubleValue())),
DOUBLE, FLOAT, INTEGER),
FunctionDSL.impl(
FunctionDSL.nullMissingHandling(
(x, y) -> new ExprDoubleValue(
new BigDecimal(String.valueOf(x.doubleValue())).setScale(y.integerValue(),
BigDecimal.valueOf(x.doubleValue()).setScale(y.integerValue(),
x.doubleValue() > 0 ? RoundingMode.FLOOR : RoundingMode.CEILING)
.doubleValue())),
DOUBLE, DOUBLE, INTEGER));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ 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(String.valueOf(value)).setScale(1,
hasValue(BigDecimal.valueOf(value).setScale(1,
value > 0 ? RoundingMode.FLOOR : RoundingMode.CEILING).longValue())));
assertEquals(String.format("truncate(%s, 1)", value), truncate.toString());
}
Expand All @@ -1740,7 +1740,7 @@ 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(String.valueOf(value)).setScale(1,
hasValue(BigDecimal.valueOf(value).setScale(1,
value > 0 ? RoundingMode.FLOOR : RoundingMode.CEILING).longValue())));
assertEquals(String.format("truncate(%s, 1)", value), truncate.toString());
}
Expand All @@ -1754,7 +1754,7 @@ 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(String.valueOf(value)).setScale(1,
hasValue(BigDecimal.valueOf(value).setScale(1,
value > 0 ? RoundingMode.FLOOR : RoundingMode.CEILING).doubleValue())));
assertEquals(String.format("truncate(%s, 1)", value), truncate.toString());
}
Expand All @@ -1768,7 +1768,7 @@ 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(String.valueOf(value)).setScale(1,
hasValue(BigDecimal.valueOf(value).setScale(1,
value > 0 ? RoundingMode.FLOOR : RoundingMode.CEILING).doubleValue())));
assertEquals(String.format("truncate(%s, 1)", value), truncate.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,10 @@ public enum Index {
"wildcard",
getMappingFile("wildcard_index_mappings.json"),
"src/test/resources/wildcard.json"),
DDOUBLE(TestsConstants.TEST_INDEX_DDOUBLE,
DOUBLE(TestsConstants.TEST_INDEX_DOUBLE,
"ddouble",
getMappingFile("ddouble_index_mapping.json"),
"src/test/resources/ddouble.json"),;
getMappingFile("double_index_mapping.json"),
"src/test/resources/double.json"),;

private final String name;
private final String type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class TestsConstants {
public final static String TEST_INDEX_NULL_MISSING = TEST_INDEX + "_null_missing";
public final static String TEST_INDEX_CALCS = TEST_INDEX + "_calcs";
public final static String TEST_INDEX_WILDCARD = TEST_INDEX + "_wildcard";
public final static String TEST_INDEX_DDOUBLE = TEST_INDEX + "_ddouble";
public final static String TEST_INDEX_DOUBLE = TEST_INDEX + "_double";

public final static String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
public final static String TS_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
package org.opensearch.sql.sql;

import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK;
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DDOUBLE;
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DOUBLE;
import static org.opensearch.sql.legacy.plugin.RestSqlAction.QUERY_API_ENDPOINT;
import static org.opensearch.sql.util.MatcherUtils.rows;
import static org.opensearch.sql.util.MatcherUtils.schema;
Expand All @@ -30,7 +30,7 @@ public class MathematicalFunctionIT extends SQLIntegTestCase {
public void init() throws Exception {
super.init();
loadIndex(Index.BANK);
loadIndex(Index.DDOUBLE);
loadIndex(Index.DOUBLE);
}

@Test
Expand Down Expand Up @@ -170,7 +170,7 @@ public void testTruncate() throws IOException {
verifyDataRows(result, rows(3.141592));

String query = "select val, truncate(val, 1) from %s";
JSONObject response = executeJdbcRequest(String.format(query, TEST_INDEX_DDOUBLE));
JSONObject response = executeJdbcRequest(String.format(query, TEST_INDEX_DOUBLE));
verifySchema(response, schema("val", null, "double"),
schema("truncate(val, 1)", null, "double"));
assertEquals(20, response.getInt("total"));
Expand Down
File renamed without changes.

0 comments on commit 21619b4

Please sign in to comment.