Search in sources :

Example 46 with LongLiteral

use of io.confluent.ksql.execution.expression.tree.LongLiteral 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)

Example 47 with LongLiteral

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

the class ExpressionFormatterTest method shouldFormatCast.

@Test
public void shouldFormatCast() {
    // Given:
    final Cast cast = new Cast(new LongLiteral(1), new Type(SqlTypes.DOUBLE));
    // When:
    final String result = ExpressionFormatter.formatExpression(cast);
    // Then:
    assertThat(result, equalTo("CAST(1 AS DOUBLE)"));
}
Also used : Cast(io.confluent.ksql.execution.expression.tree.Cast) Type(io.confluent.ksql.execution.expression.tree.Type) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) Test(org.junit.Test)

Example 48 with LongLiteral

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

the class ImplicitlyCastResolver method resolveToDecimal.

@SuppressWarnings("CyclomaticComplexiIntegerLiteralty")
private static Expression resolveToDecimal(final Expression expression, final SqlDecimal toDecimalType) {
    final BigDecimal literalValue;
    if (expression instanceof IntegerLiteral) {
        literalValue = BigDecimal.valueOf(((IntegerLiteral) expression).getValue());
    } else if (expression instanceof LongLiteral) {
        literalValue = BigDecimal.valueOf(((LongLiteral) expression).getValue());
    } else if (expression instanceof DoubleLiteral) {
        literalValue = BigDecimal.valueOf(((DoubleLiteral) expression).getValue());
    } else if (expression instanceof DecimalLiteral) {
        literalValue = ((DecimalLiteral) expression).getValue();
    } else {
        return expression;
    }
    final SqlDecimal fromDecimalType = (SqlDecimal) DecimalUtil.fromValue(literalValue);
    if (DecimalUtil.canImplicitlyCast(fromDecimalType, toDecimalType)) {
        return new DecimalLiteral(expression.getLocation(), DecimalUtil.cast(literalValue, toDecimalType.getPrecision(), toDecimalType.getScale()));
    }
    return expression;
}
Also used : LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) DecimalLiteral(io.confluent.ksql.execution.expression.tree.DecimalLiteral) SqlDecimal(io.confluent.ksql.schema.ksql.types.SqlDecimal) DoubleLiteral(io.confluent.ksql.execution.expression.tree.DoubleLiteral) BigDecimal(java.math.BigDecimal) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral)

Example 49 with LongLiteral

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

the class LiteralUtilTest method shouldThrowConvertingOtherLiteralTypesToBoolean.

@Test
public void shouldThrowConvertingOtherLiteralTypesToBoolean() {
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> LiteralUtil.toBoolean(new LongLiteral(10), "bob"));
    // Then:
    assertThat(e.getMessage(), containsString("Property 'bob' is not a boolean value"));
}
Also used : LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 50 with LongLiteral

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

the class GroupByParamsFactoryTest method shouldGenerateKeyNameFromOtherExpressionType.

@Test
public void shouldGenerateKeyNameFromOtherExpressionType() {
    // Given:
    when(groupBy0.getExpression()).thenReturn(new LongLiteral(1));
    // When:
    final LogicalSchema schema = GroupByParamsFactory.buildSchema(SOURCE_SCHEMA, ImmutableList.of(groupBy0, groupBy1));
    // Then:
    assertThat(schema, is(LogicalSchema.builder().keyColumn(ColumnName.of("KSQL_COL_1"), SqlTypes.INTEGER).keyColumn(ColumnName.of("K1"), SqlTypes.INTEGER).valueColumns(SOURCE_SCHEMA.value()).build()));
}
Also used : LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Test(org.junit.Test)

Aggregations

LongLiteral (io.confluent.ksql.execution.expression.tree.LongLiteral)53 Test (org.junit.Test)49 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)35 KsqlException (io.confluent.ksql.util.KsqlException)21 InsertValues (io.confluent.ksql.parser.tree.InsertValues)20 RestClientException (io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException)17 ExecutionException (java.util.concurrent.ExecutionException)17 SerializationException (org.apache.kafka.common.errors.SerializationException)17 TopicAuthorizationException (org.apache.kafka.common.errors.TopicAuthorizationException)17 Expression (io.confluent.ksql.execution.expression.tree.Expression)16 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)15 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)12 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)12 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)12 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)10 DoubleLiteral (io.confluent.ksql.execution.expression.tree.DoubleLiteral)10 DecimalLiteral (io.confluent.ksql.execution.expression.tree.DecimalLiteral)9 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)9 BigDecimal (java.math.BigDecimal)9 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)7