use of io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForDecimalNegation.
@Test
public void shouldGenerateCorrectCodeForDecimalNegation() {
// Given:
final ArithmeticUnaryExpression binExp = new ArithmeticUnaryExpression(Optional.empty(), Sign.MINUS, new UnqualifiedColumnReferenceExp(ColumnName.of("COL8")));
// When:
final String java = sqlToJavaVisitor.process(binExp);
// Then:
assertThat(java, is("(COL8.negate(new MathContext(2, RoundingMode.UNNECESSARY)))"));
}
use of io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateUnaryArithmetic.
@Test
public void shouldEvaluateUnaryArithmetic() {
// Given:
final Expression expression1 = new ArithmeticUnaryExpression(Optional.empty(), Sign.PLUS, new IntegerLiteral(1));
final Expression expression2 = new ArithmeticUnaryExpression(Optional.empty(), Sign.MINUS, new IntegerLiteral(1));
final Expression expression3 = new ArithmeticUnaryExpression(Optional.empty(), Sign.MINUS, new DecimalLiteral(new BigDecimal("345.5")));
final Expression expression4 = new ArithmeticUnaryExpression(Optional.empty(), Sign.MINUS, new DoubleLiteral(45.5d));
// When:
InterpretedExpression interpreter1 = interpreter(expression1);
InterpretedExpression interpreter2 = interpreter(expression2);
InterpretedExpression interpreter3 = interpreter(expression3);
InterpretedExpression interpreter4 = interpreter(expression4);
// Then:
assertThat(interpreter1.evaluate(ROW), is(1));
assertThat(interpreter2.evaluate(ROW), is(-1));
assertThat(interpreter3.evaluate(ROW), is(new BigDecimal("-345.5")));
assertThat(interpreter4.evaluate(ROW), is(-45.5d));
}
use of io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression in project ksql by confluentinc.
the class PartitionByParamsFactoryTest method shouldBuildResultSchemaWhenPartitioningByOtherExpressionType.
@Test
public void shouldBuildResultSchemaWhenPartitioningByOtherExpressionType() {
// Given:
final List<Expression> partitionBy = ImmutableList.of(new ArithmeticUnaryExpression(Optional.empty(), Sign.MINUS, new UnqualifiedColumnReferenceExp(COL1)));
// When:
final LogicalSchema resultSchema = PartitionByParamsFactory.buildSchema(SCHEMA, partitionBy, functionRegistry);
// Then:
assertThat(resultSchema, is(LogicalSchema.builder().keyColumn(ColumnName.of("KSQL_COL_0"), SqlTypes.INTEGER).valueColumn(COL1, SqlTypes.INTEGER).valueColumn(COL2, SqlTypes.INTEGER).valueColumn(COL3, COL3_TYPE).valueColumn(SystemColumns.ROWTIME_NAME, SqlTypes.BIGINT).valueColumn(COL0, SqlTypes.STRING).valueColumn(ColumnName.of("KSQL_COL_0"), SqlTypes.INTEGER).build()));
}
use of io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression in project ksql by confluentinc.
the class PartitionByParamsFactoryTest method shouldBuildResultSchemaWhenPartitioningByMultipleFields.
@Test
public void shouldBuildResultSchemaWhenPartitioningByMultipleFields() {
// Given:
final List<Expression> partitionBy = ImmutableList.of(new UnqualifiedColumnReferenceExp(COL1), new DereferenceExpression(Optional.empty(), new UnqualifiedColumnReferenceExp(COL3), "someField"), new ArithmeticUnaryExpression(Optional.empty(), Sign.MINUS, new UnqualifiedColumnReferenceExp(COL1)));
// When:
final LogicalSchema resultSchema = PartitionByParamsFactory.buildSchema(SCHEMA, partitionBy, functionRegistry);
// Then:
assertThat(resultSchema, is(LogicalSchema.builder().keyColumn(COL1, SqlTypes.INTEGER).keyColumn(ColumnName.of("someField"), SqlTypes.BIGINT).keyColumn(ColumnName.of("KSQL_COL_0"), SqlTypes.INTEGER).valueColumn(COL1, SqlTypes.INTEGER).valueColumn(COL2, SqlTypes.INTEGER).valueColumn(COL3, COL3_TYPE).valueColumn(SystemColumns.ROWTIME_NAME, SqlTypes.BIGINT).valueColumn(COL0, SqlTypes.STRING).valueColumn(ColumnName.of("someField"), SqlTypes.BIGINT).valueColumn(ColumnName.of("KSQL_COL_0"), SqlTypes.INTEGER).build()));
}
Aggregations