Search in sources :

Example 16 with DoubleLiteral

use of io.confluent.ksql.execution.expression.tree.DoubleLiteral in project ksql by confluentinc.

the class InsertValuesExecutorTest method shouldFailOnDowncast.

@Test
public void shouldFailOnDowncast() {
    // Given:
    givenSourceStreamWithSchema(BIG_SCHEMA, SerdeFeatures.of(), SerdeFeatures.of());
    final ConfiguredStatement<InsertValues> statement = givenInsertValues(ImmutableList.of(INT_COL), ImmutableList.of(new DoubleLiteral(1.1)));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
    // Then:
    assertThat(e.getCause(), (hasMessage(containsString("Expected type INTEGER for field"))));
}
Also used : InsertValues(io.confluent.ksql.parser.tree.InsertValues) DoubleLiteral(io.confluent.ksql.execution.expression.tree.DoubleLiteral) SerializationException(org.apache.kafka.common.errors.SerializationException) RestClientException(io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException) KsqlException(io.confluent.ksql.util.KsqlException) ExecutionException(java.util.concurrent.ExecutionException) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) Test(org.junit.Test)

Example 17 with DoubleLiteral

use of io.confluent.ksql.execution.expression.tree.DoubleLiteral in project ksql by confluentinc.

the class InterpretedExpressionTest method shouldEvaluateCastToBigint.

@Test
public void shouldEvaluateCastToBigint() {
    // Given:
    final Expression cast1 = new Cast(new IntegerLiteral(10), new Type(SqlPrimitiveType.of("BIGINT")));
    final Expression cast2 = new Cast(new StringLiteral("1234"), new Type(SqlPrimitiveType.of("BIGINT")));
    final Expression cast3 = new Cast(new DoubleLiteral(12.5), new Type(SqlPrimitiveType.of("BIGINT")));
    final Expression cast4 = new Cast(new DecimalLiteral(new BigDecimal("4567.5")), new Type(SqlPrimitiveType.of("BIGINT")));
    // When:
    InterpretedExpression interpreter1 = interpreter(cast1);
    InterpretedExpression interpreter2 = interpreter(cast2);
    InterpretedExpression interpreter3 = interpreter(cast3);
    InterpretedExpression interpreter4 = interpreter(cast4);
    // Then:
    assertThat(interpreter1.evaluate(ROW), is(10L));
    assertThat(interpreter2.evaluate(ROW), is(1234L));
    assertThat(interpreter3.evaluate(ROW), is(12L));
    assertThat(interpreter4.evaluate(ROW), is(4567L));
}
Also used : Cast(io.confluent.ksql.execution.expression.tree.Cast) LambdaType(io.confluent.ksql.function.types.LambdaType) IntegerType(io.confluent.ksql.function.types.IntegerType) GenericType(io.confluent.ksql.function.types.GenericType) SqlPrimitiveType(io.confluent.ksql.schema.ksql.types.SqlPrimitiveType) IntervalUnitType(io.confluent.ksql.function.types.IntervalUnitType) Type(io.confluent.ksql.execution.expression.tree.Type) ArrayType(io.confluent.ksql.function.types.ArrayType) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) 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) 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 18 with DoubleLiteral

use of io.confluent.ksql.execution.expression.tree.DoubleLiteral in project ksql by confluentinc.

the class InterpretedExpressionTest method shouldEvaluateCastToInteger.

@Test
public void shouldEvaluateCastToInteger() {
    // Given:
    final Expression cast1 = new Cast(new LongLiteral(10L), new Type(SqlPrimitiveType.of("INTEGER")));
    final Expression cast2 = new Cast(new StringLiteral("1234"), new Type(SqlPrimitiveType.of("INTEGER")));
    final Expression cast3 = new Cast(new DoubleLiteral(12.5), new Type(SqlPrimitiveType.of("INTEGER")));
    final Expression cast4 = new Cast(new DecimalLiteral(new BigDecimal("4567.5")), new Type(SqlPrimitiveType.of("INTEGER")));
    // When:
    InterpretedExpression interpreter1 = interpreter(cast1);
    InterpretedExpression interpreter2 = interpreter(cast2);
    InterpretedExpression interpreter3 = interpreter(cast3);
    InterpretedExpression interpreter4 = interpreter(cast4);
    // Then:
    assertThat(interpreter1.evaluate(ROW), is(10));
    assertThat(interpreter2.evaluate(ROW), is(1234));
    assertThat(interpreter3.evaluate(ROW), is(12));
    assertThat(interpreter4.evaluate(ROW), is(4567));
}
Also used : Cast(io.confluent.ksql.execution.expression.tree.Cast) LambdaType(io.confluent.ksql.function.types.LambdaType) IntegerType(io.confluent.ksql.function.types.IntegerType) GenericType(io.confluent.ksql.function.types.GenericType) SqlPrimitiveType(io.confluent.ksql.schema.ksql.types.SqlPrimitiveType) IntervalUnitType(io.confluent.ksql.function.types.IntervalUnitType) Type(io.confluent.ksql.execution.expression.tree.Type) ArrayType(io.confluent.ksql.function.types.ArrayType) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) 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) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) DecimalLiteral(io.confluent.ksql.execution.expression.tree.DecimalLiteral) DoubleLiteral(io.confluent.ksql.execution.expression.tree.DoubleLiteral) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 19 with DoubleLiteral

use of io.confluent.ksql.execution.expression.tree.DoubleLiteral 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 20 with DoubleLiteral

use of io.confluent.ksql.execution.expression.tree.DoubleLiteral in project ksql by confluentinc.

the class UdafUtilTest method shouldThrowIfSubsequentParamsAreNotLiteral.

@Test
public void shouldThrowIfSubsequentParamsAreNotLiteral() {
    // Given:
    when(functionCall.getArguments()).thenReturn(ImmutableList.of(new UnqualifiedColumnReferenceExp(ColumnName.of("Bob")), new LongLiteral(10), new DoubleLiteral(1.0), new UnqualifiedColumnReferenceExp(ColumnName.of("Not good!"))));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> UdafUtil.createAggregateFunctionInitArgs(0, functionCall, KsqlConfig.empty()));
    // Then:
    assertThat(e.getMessage(), is("Parameter 4 passed to function AGG must be a literal constant, " + "but was expression: 'Not good!'"));
}
Also used : LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) DoubleLiteral(io.confluent.ksql.execution.expression.tree.DoubleLiteral) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Aggregations

DoubleLiteral (io.confluent.ksql.execution.expression.tree.DoubleLiteral)21 Test (org.junit.Test)20 Expression (io.confluent.ksql.execution.expression.tree.Expression)16 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)15 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)15 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)15 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)15 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)14 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)14 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)14 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)14 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)14 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)11 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)11 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)11 LongLiteral (io.confluent.ksql.execution.expression.tree.LongLiteral)10 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)10 DecimalLiteral (io.confluent.ksql.execution.expression.tree.DecimalLiteral)9 BigDecimal (java.math.BigDecimal)9 Cast (io.confluent.ksql.execution.expression.tree.Cast)6