Search in sources :

Example 26 with GenericType

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

the class GenericsUtilTest method shouldFailToIdentifySqlLambdaResolvedWithDifferentSchema.

@Test
public void shouldFailToIdentifySqlLambdaResolvedWithDifferentSchema() {
    // 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(SqlLambdaResolved.of(ImmutableList.of(SqlTypes.DOUBLE), SqlTypes.BIGINT));
    // 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 (DOUBLE) => BIGINT " + "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 27 with GenericType

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

the class GenericsUtilTest method shouldIdentifyGenericCorrectly.

@Test
public void shouldIdentifyGenericCorrectly() {
    // Given:
    final GenericType generic = GenericType.of("T");
    // Then:
    assertThat("should be a generic", GenericsUtil.isGeneric(generic));
}
Also used : GenericType(io.confluent.ksql.function.types.GenericType) Test(org.junit.Test)

Example 28 with GenericType

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

the class GenericsUtilTest method shouldFindAllConstituentGenericsInLambdaType.

@Test
public void shouldFindAllConstituentGenericsInLambdaType() {
    // Given:
    final GenericType a = GenericType.of("A");
    final GenericType b = GenericType.of("B");
    final GenericType c = GenericType.of("C");
    final GenericType d = GenericType.of("D");
    final ParamType lambda = LambdaType.of(ImmutableList.of(GenericType.of("C"), GenericType.of("A"), GenericType.of("B")), GenericType.of("D"));
    // When:
    final Set<ParamType> generics = GenericsUtil.constituentGenerics(lambda);
    // Then:
    assertThat(generics, containsInAnyOrder(a, b, c, d));
}
Also used : GenericType(io.confluent.ksql.function.types.GenericType) ParamType(io.confluent.ksql.function.types.ParamType) Test(org.junit.Test)

Example 29 with GenericType

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

the class GenericsUtilTest method shouldResolveMapSchemaWithMapping.

@Test
public void shouldResolveMapSchemaWithMapping() {
    // Given:
    final GenericType a = GenericType.of("A");
    final GenericType b = GenericType.of("B");
    final ParamType map = MapType.of(a, b);
    final ImmutableMap<GenericType, SqlType> mapping = ImmutableMap.of(a, SqlTypes.INTEGER, b, SqlTypes.DOUBLE);
    // When:
    final SqlType resolved = GenericsUtil.applyResolved(map, mapping);
    // Then:
    assertThat(resolved, is(SqlTypes.map(SqlTypes.INTEGER, SqlTypes.DOUBLE)));
}
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 30 with GenericType

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

the class GenericsUtilTest method shouldIdentifySqlLambdaResolvedGenerics.

@Test
public void shouldIdentifySqlLambdaResolvedGenerics() {
    // Given:
    final GenericType typeA = GenericType.of("A");
    final GenericType typeB = GenericType.of("B");
    final LambdaType a = LambdaType.of(ImmutableList.of(typeA, typeB), typeB);
    final SqlArgument instance = SqlArgument.of(SqlLambdaResolved.of(ImmutableList.of(SqlTypes.DOUBLE, SqlTypes.BIGINT), SqlTypes.BIGINT));
    // When:
    final Map<GenericType, SqlType> mapping = GenericsUtil.reserveGenerics(a, instance);
    // Then:
    assertThat(mapping, hasEntry(typeA, SqlTypes.DOUBLE));
    assertThat(mapping, hasEntry(typeB, SqlTypes.BIGINT));
}
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)

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