Search in sources :

Example 6 with ArithmeticUnaryExpression

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)))"));
}
Also used : ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 7 with ArithmeticUnaryExpression

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));
}
Also used : ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) DecimalLiteral(io.confluent.ksql.execution.expression.tree.DecimalLiteral) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) DoubleLiteral(io.confluent.ksql.execution.expression.tree.DoubleLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 8 with ArithmeticUnaryExpression

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()));
}
Also used : ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 9 with ArithmeticUnaryExpression

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()));
}
Also used : DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Aggregations

ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)9 Test (org.junit.Test)9 Expression (io.confluent.ksql.execution.expression.tree.Expression)6 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)6 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)4 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)4 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)4 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)4 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)4 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)3 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)3 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)2 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)2 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)2 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)2 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 DecimalLiteral (io.confluent.ksql.execution.expression.tree.DecimalLiteral)1 DoubleLiteral (io.confluent.ksql.execution.expression.tree.DoubleLiteral)1 NotExpression (io.confluent.ksql.execution.expression.tree.NotExpression)1