Search in sources :

Example 1 with SqlType

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

the class GenericsUtilTest method shouldResolveArraySchemaWithMapping.

@Test
public void shouldResolveArraySchemaWithMapping() {
    // Given:
    final GenericType a = GenericType.of("A");
    final ParamType array = ArrayType.of(a);
    final ImmutableMap<GenericType, SqlType> mapping = ImmutableMap.of(a, SqlTypes.STRING);
    // When:
    final SqlType resolved = GenericsUtil.applyResolved(array, mapping);
    // Then:
    assertThat(resolved, is(SqlTypes.array(SqlTypes.STRING)));
}
Also used : GenericType(io.confluent.ksql.function.types.GenericType) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) ParamType(io.confluent.ksql.function.types.ParamType) Test(org.junit.Test)

Example 2 with SqlType

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

the class GenericsUtilTest method shouldIdentifyMapGeneric.

@Test
public void shouldIdentifyMapGeneric() {
    // Given:
    final MapType a = MapType.of(GenericType.of("A"), GenericType.of("B"));
    final SqlArgument instance = SqlArgument.of(SqlTypes.map(SqlTypes.DOUBLE, SqlTypes.BIGINT));
    // When:
    final Map<GenericType, SqlType> mapping = GenericsUtil.reserveGenerics(a, instance);
    // Then:
    assertThat(mapping, hasEntry(a.key(), SqlTypes.DOUBLE));
    assertThat(mapping, hasEntry(a.value(), SqlTypes.BIGINT));
}
Also used : SqlArgument(io.confluent.ksql.schema.ksql.SqlArgument) GenericType(io.confluent.ksql.function.types.GenericType) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) MapType(io.confluent.ksql.function.types.MapType) Test(org.junit.Test)

Example 3 with SqlType

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

the class GenericsUtilTest method shouldFailResolveSchemaWithIncompleteMapping.

@Test(expected = KsqlException.class)
public void shouldFailResolveSchemaWithIncompleteMapping() {
    // Given:
    final GenericType a = GenericType.of("A");
    final Map<GenericType, SqlType> mapping = ImmutableMap.of();
    // When:
    GenericsUtil.applyResolved(a, mapping);
}
Also used : GenericType(io.confluent.ksql.function.types.GenericType) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Test(org.junit.Test)

Example 4 with SqlType

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

the class GenericsUtilTest method shouldNotMapGenericsForNonSqlLambdaResolved.

@Test
public void shouldNotMapGenericsForNonSqlLambdaResolved() {
    // Given:
    final GenericType typeA = GenericType.of("A");
    final GenericType typeB = GenericType.of("B");
    final GenericType typeC = GenericType.of("C");
    final LambdaType a = LambdaType.of(ImmutableList.of(typeA, typeC), typeB);
    final SqlArgument instance = SqlArgument.of(SqlLambda.of(2));
    // When:
    final Map<GenericType, SqlType> mapping = GenericsUtil.reserveGenerics(a, instance);
    // Then:
    // the map should be empty since the instance type was a SqlLambda without any types resolved
    assertThat(mapping.size(), is(0));
}
Also used : LambdaType(io.confluent.ksql.function.types.LambdaType) GenericType(io.confluent.ksql.function.types.GenericType) SqlArgument(io.confluent.ksql.schema.ksql.SqlArgument) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Test(org.junit.Test)

Example 5 with SqlType

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

the class GenericsUtilTest method shouldIdentifyGeneric.

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

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