Search in sources :

Example 6 with GenericType

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

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

Example 8 with GenericType

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

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

the class GenericsUtilTest method shouldFindAllConstituentGenerics.

@Test
public void shouldFindAllConstituentGenerics() {
    // 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 map = MapType.of(GenericType.of("C"), GenericType.of("D"));
    final StructType complexSchema = StructType.builder().field("a", a).field("b", b).field("c", map).build();
    // When:
    final Set<ParamType> generics = GenericsUtil.constituentGenerics(complexSchema);
    // Then:
    assertThat(generics, containsInAnyOrder(a, b, c, d));
}
Also used : GenericType(io.confluent.ksql.function.types.GenericType) StructType(io.confluent.ksql.function.types.StructType) ParamType(io.confluent.ksql.function.types.ParamType) Test(org.junit.Test)

Example 10 with GenericType

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

the class GenericsUtilTest method shouldResolveSchemaWithMapping.

@Test
public void shouldResolveSchemaWithMapping() {
    // Given:
    final GenericType a = GenericType.of("A");
    final ImmutableMap<GenericType, SqlType> mapping = ImmutableMap.of(a, SqlTypes.STRING);
    // When:
    final SqlType resolved = GenericsUtil.applyResolved(a, mapping);
    // Then:
    assertThat(resolved, is(SqlTypes.STRING));
}
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