use of org.apache.druid.sql.calcite.expression.builtin.TruncateOperatorConversion in project druid by druid-io.
the class ExpressionsTest method testTruncate.
@Test
public void testTruncate() {
final SqlFunction truncateFunction = new TruncateOperatorConversion().calciteOperator();
testHelper.testExpression(truncateFunction, testHelper.makeInputRef("a"), DruidExpression.ofExpression(ColumnType.LONG, (args) -> "(cast(cast(" + args.get(0).getExpression() + " * 1,'long'),'double') / 1)", ImmutableList.of(DruidExpression.ofColumn(ColumnType.LONG, "a"))), 10.0);
testHelper.testExpression(truncateFunction, testHelper.makeInputRef("x"), DruidExpression.ofExpression(ColumnType.FLOAT, (args) -> "(cast(cast(" + args.get(0).getExpression() + " * 1,'long'),'double') / 1)", ImmutableList.of(DruidExpression.ofColumn(ColumnType.FLOAT, "x"))), 2.0);
testHelper.testExpression(truncateFunction, testHelper.makeInputRef("y"), DruidExpression.ofExpression(ColumnType.LONG, (args) -> "(cast(cast(" + args.get(0).getExpression() + " * 1,'long'),'double') / 1)", ImmutableList.of(DruidExpression.ofColumn(ColumnType.LONG, "y"))), 3.0);
testHelper.testExpression(truncateFunction, testHelper.makeInputRef("z"), DruidExpression.ofExpression(ColumnType.FLOAT, (args) -> "(cast(cast(" + args.get(0).getExpression() + " * 1,'long'),'double') / 1)", ImmutableList.of(DruidExpression.ofColumn(ColumnType.FLOAT, "z"))), -2.0);
testHelper.testExpressionString(truncateFunction, ImmutableList.of(testHelper.makeInputRef("x"), testHelper.makeLiteral(1)), DruidExpression.ofExpression(ColumnType.FLOAT, (args) -> "(cast(cast(" + args.get(0).getExpression() + " * 10.0,'long'),'double') / 10.0)", ImmutableList.of(DruidExpression.ofColumn(ColumnType.FLOAT, "x"), DruidExpression.ofLiteral(ColumnType.LONG, DruidExpression.numberLiteral(1)))), 2.2);
testHelper.testExpressionString(truncateFunction, ImmutableList.of(testHelper.makeInputRef("z"), testHelper.makeLiteral(1)), DruidExpression.ofExpression(ColumnType.FLOAT, (args) -> "(cast(cast(" + args.get(0).getExpression() + " * 10.0,'long'),'double') / 10.0)", ImmutableList.of(DruidExpression.ofColumn(ColumnType.FLOAT, "z"), DruidExpression.ofLiteral(ColumnType.LONG, DruidExpression.numberLiteral(1)))), -2.2);
testHelper.testExpressionString(truncateFunction, ImmutableList.of(testHelper.makeInputRef("b"), testHelper.makeLiteral(-1)), DruidExpression.ofExpression(ColumnType.LONG, (args) -> "(cast(cast(" + args.get(0).getExpression() + " * 0.1,'long'),'double') / 0.1)", ImmutableList.of(DruidExpression.ofColumn(ColumnType.LONG, "b"), DruidExpression.ofLiteral(ColumnType.LONG, DruidExpression.numberLiteral(-1)))), 20.0);
testHelper.testExpressionString(truncateFunction, ImmutableList.of(testHelper.makeInputRef("z"), testHelper.makeLiteral(-1)), DruidExpression.ofExpression(ColumnType.FLOAT, (args) -> "(cast(cast(" + args.get(0).getExpression() + " * 0.1,'long'),'double') / 0.1)", ImmutableList.of(DruidExpression.ofColumn(ColumnType.FLOAT, "z"), DruidExpression.ofLiteral(ColumnType.LONG, DruidExpression.numberLiteral(-1)))), 0.0);
}
Aggregations