Search in sources :

Example 1 with GenericType

use of io.confluent.ksql.function.types.GenericType in project ksql by confluentinc.

the class GenericsUtilTest method shouldFailToIdentifyLambdasWithDifferentArgumentList.

@Test
public void shouldFailToIdentifyLambdasWithDifferentArgumentList() {
    // 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(4));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> GenericsUtil.reserveGenerics(a, instance));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot infer generics for LAMBDA (A, C) => B from LAMBDA " + "because they do not have the same schema structure."));
}
Also used : LambdaType(io.confluent.ksql.function.types.LambdaType) GenericType(io.confluent.ksql.function.types.GenericType) SqlArgument(io.confluent.ksql.schema.ksql.SqlArgument) Test(org.junit.Test)

Example 2 with GenericType

use of io.confluent.ksql.function.types.GenericType 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 3 with GenericType

use of io.confluent.ksql.function.types.GenericType in project ksql by confluentinc.

the class GenericsUtilTest method shouldFailToIdentifyMismatchedGenericsInLambda.

@Test
public void shouldFailToIdentifyMismatchedGenericsInLambda() {
    // Given:
    final GenericType typeA = GenericType.of("A");
    final LambdaType a = LambdaType.of(ImmutableList.of(typeA), typeA);
    final SqlArgument instance = SqlArgument.of(SqlLambdaResolved.of(ImmutableList.of(SqlTypes.DOUBLE), SqlTypes.BOOLEAN));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> GenericsUtil.reserveGenerics(a, instance));
    // Then:
    assertThat(e.getMessage(), containsString("Found invalid instance of generic schema when mapping LAMBDA (A) => A to LAMBDA (DOUBLE) => BOOLEAN. " + "Cannot map A to both DOUBLE and BOOLEAN"));
}
Also used : LambdaType(io.confluent.ksql.function.types.LambdaType) GenericType(io.confluent.ksql.function.types.GenericType) SqlArgument(io.confluent.ksql.schema.ksql.SqlArgument) Test(org.junit.Test)

Example 4 with GenericType

use of io.confluent.ksql.function.types.GenericType 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 5 with GenericType

use of io.confluent.ksql.function.types.GenericType 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)

Aggregations

GenericType (io.confluent.ksql.function.types.GenericType)34 Test (org.junit.Test)27 LambdaType (io.confluent.ksql.function.types.LambdaType)17 ParamType (io.confluent.ksql.function.types.ParamType)17 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)16 ArrayType (io.confluent.ksql.function.types.ArrayType)12 MapType (io.confluent.ksql.function.types.MapType)12 StructType (io.confluent.ksql.function.types.StructType)12 SqlArgument (io.confluent.ksql.schema.ksql.SqlArgument)11 Type (java.lang.reflect.Type)10 KsqlException (io.confluent.ksql.util.KsqlException)5 HashMap (java.util.HashMap)5 ArrayList (java.util.ArrayList)2 Optional (java.util.Optional)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Expression (io.confluent.ksql.execution.expression.tree.Expression)1 LambdaFunctionCall (io.confluent.ksql.execution.expression.tree.LambdaFunctionCall)1 UdfUtil (io.confluent.ksql.execution.function.UdfUtil)1 KsqlScalarFunction (io.confluent.ksql.function.KsqlScalarFunction)1 ParamTypes (io.confluent.ksql.function.types.ParamTypes)1