Search in sources :

Example 1 with ParamType

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

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

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

the class GenericsUtilTest method shouldNotIdentifyGenericIncorrectly.

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

Example 4 with ParamType

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

the class SchemaConvertersTest method shouldGetSqlTypeForAllParamTypes.

@Test
public void shouldGetSqlTypeForAllParamTypes() {
    for (Entry<ParamType, SqlType> entry : SQL_TO_FUNCTION.inverse().entrySet()) {
        ParamType param = entry.getKey();
        if (REQUIRES_SCHEMA_SPEC.contains(param)) {
            continue;
        }
        SqlType sqlType = entry.getValue();
        assertThat(SchemaConverters.functionToSqlConverter().toSqlType(param), is(sqlType));
    }
}
Also used : SqlType(io.confluent.ksql.schema.ksql.types.SqlType) ParamType(io.confluent.ksql.function.types.ParamType) Test(org.junit.Test)

Example 5 with ParamType

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

the class SchemaConvertersTest method shouldGetParamTypesForAllSqlTypes.

@Test
public void shouldGetParamTypesForAllSqlTypes() {
    for (final Entry<SqlType, ParamType> entry : SQL_TO_FUNCTION.entrySet()) {
        final SqlType sqlType = entry.getKey();
        final ParamType javaType = entry.getValue();
        final ParamType result = SchemaConverters.sqlToFunctionConverter().toFunctionType(sqlType);
        assertThat(result, equalTo(javaType));
    }
}
Also used : SqlType(io.confluent.ksql.schema.ksql.types.SqlType) ParamType(io.confluent.ksql.function.types.ParamType) Test(org.junit.Test)

Aggregations

ParamType (io.confluent.ksql.function.types.ParamType)35 GenericType (io.confluent.ksql.function.types.GenericType)26 Test (org.junit.Test)22 LambdaType (io.confluent.ksql.function.types.LambdaType)20 StructType (io.confluent.ksql.function.types.StructType)20 ArrayType (io.confluent.ksql.function.types.ArrayType)19 Type (java.lang.reflect.Type)19 MapType (io.confluent.ksql.function.types.MapType)18 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)11 HashMap (java.util.HashMap)5 KsqlException (io.confluent.ksql.util.KsqlException)4 ParameterizedType (java.lang.reflect.ParameterizedType)4 ArrayList (java.util.ArrayList)4 GenericArrayType (java.lang.reflect.GenericArrayType)3 TypeVariable (java.lang.reflect.TypeVariable)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Expression (io.confluent.ksql.execution.expression.tree.Expression)2 KsqlScalarFunction (io.confluent.ksql.function.KsqlScalarFunction)2 ParamTypes (io.confluent.ksql.function.types.ParamTypes)2 Kudf (io.confluent.ksql.function.udf.Kudf)2