Search in sources :

Example 6 with SqlType

use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.

the class GenericsUtilTest method shouldIdentifyArrayGeneric.

@Test
public void shouldIdentifyArrayGeneric() {
    // Given:
    final ArrayType a = ArrayType.of(GenericType.of("A"));
    final SqlArgument instance = SqlArgument.of(SqlTypes.array(SqlTypes.STRING));
    // When:
    final Map<GenericType, SqlType> mapping = GenericsUtil.reserveGenerics(a, instance);
    // Then:
    assertThat(mapping, hasEntry(a.element(), SqlTypes.STRING));
}
Also used : ArrayType(io.confluent.ksql.function.types.ArrayType) SqlArgument(io.confluent.ksql.schema.ksql.SqlArgument) GenericType(io.confluent.ksql.function.types.GenericType) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Test(org.junit.Test)

Example 7 with SqlType

use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.

the class DecimalUtilTest method shouldGetSchemaFromDecimal2_0.

@Test
public void shouldGetSchemaFromDecimal2_0() {
    // When:
    final SqlType schema = DecimalUtil.fromValue(new BigDecimal("12."));
    // Then:
    assertThat(schema, is(SqlTypes.decimal(2, 0)));
}
Also used : SqlType(io.confluent.ksql.schema.ksql.types.SqlType) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 8 with SqlType

use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.

the class DecimalUtilTest method shouldGetSchemaFromDecimal10_5.

@Test
public void shouldGetSchemaFromDecimal10_5() {
    // When:
    final SqlType schema = DecimalUtil.fromValue(new BigDecimal("12345.12345"));
    // Then:
    assertThat(schema, is(SqlTypes.decimal(10, 5)));
}
Also used : SqlType(io.confluent.ksql.schema.ksql.types.SqlType) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 9 with SqlType

use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.

the class DecimalUtilTest method shouldGetSchemaFromDecimal4_3.

@Test
public void shouldGetSchemaFromDecimal4_3() {
    // When:
    final SqlType schema = DecimalUtil.fromValue(new BigDecimal("0.005"));
    // Then:
    assertThat(schema, is(SqlTypes.decimal(4, 3)));
}
Also used : SqlType(io.confluent.ksql.schema.ksql.types.SqlType) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 10 with SqlType

use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.

the class DefaultSqlValueCoercerTest method coerce.

private static Optional<?> coerce(final DefaultSqlValueCoercer coercer, final SqlType from, final SqlType to, final Object value) {
    // When:
    final Optional<SqlType> coercedType = coercer.canCoerce(from, to);
    final Result result = coercer.coerce(value, to);
    // Then:
    assertThat("canCoerce(" + from + "," + to + ")", coercedType, is(not(Optional.empty())));
    assertThat("coerce(" + value + "," + to + ")", result, is(not(Result.failure())));
    return result.value();
}
Also used : SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Result(io.confluent.ksql.schema.ksql.SqlValueCoercer.Result)

Aggregations

SqlType (io.confluent.ksql.schema.ksql.types.SqlType)140 Test (org.junit.Test)80 Expression (io.confluent.ksql.execution.expression.tree.Expression)47 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)38 KsqlException (io.confluent.ksql.util.KsqlException)33 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)30 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)29 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)29 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)29 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)29 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)29 NotExpression (io.confluent.ksql.execution.expression.tree.NotExpression)29 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)29 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)29 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)29 Optional (java.util.Optional)20 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)15 Result (io.confluent.ksql.schema.ksql.SqlValueCoercer.Result)14 Struct (org.apache.kafka.connect.data.Struct)14 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)13