Search in sources :

Example 1 with SqlArgument

use of io.confluent.ksql.schema.ksql.SqlArgument 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 SqlArgument

use of io.confluent.ksql.schema.ksql.SqlArgument 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 3 with SqlArgument

use of io.confluent.ksql.schema.ksql.SqlArgument in project ksql by confluentinc.

the class GenericsUtilTest method shouldNotIdentifyInstanceOfTypeMismatch.

@Test
public void shouldNotIdentifyInstanceOfTypeMismatch() {
    // Given:
    final MapType map = MapType.of(GenericType.of("A"), GenericType.of("B"));
    final SqlArgument instance = SqlArgument.of(SqlTypes.array(SqlTypes.STRING));
    // When:
    final boolean isInstance = GenericsUtil.reserveGenerics(map, instance, new HashMap<>()).getLeft();
    // Then:
    assertThat("expected not instance of", !isInstance);
}
Also used : SqlArgument(io.confluent.ksql.schema.ksql.SqlArgument) HashMap(java.util.HashMap) MapType(io.confluent.ksql.function.types.MapType) Test(org.junit.Test)

Example 4 with SqlArgument

use of io.confluent.ksql.schema.ksql.SqlArgument 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 SqlArgument

use of io.confluent.ksql.schema.ksql.SqlArgument 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)

Aggregations

SqlArgument (io.confluent.ksql.schema.ksql.SqlArgument)21 Test (org.junit.Test)14 GenericType (io.confluent.ksql.function.types.GenericType)12 LambdaType (io.confluent.ksql.function.types.LambdaType)10 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)10 HashMap (java.util.HashMap)7 MapType (io.confluent.ksql.function.types.MapType)4 KsqlException (io.confluent.ksql.util.KsqlException)4 Expression (io.confluent.ksql.execution.expression.tree.Expression)3 ParamType (io.confluent.ksql.function.types.ParamType)3 ArrayList (java.util.ArrayList)3 Optional (java.util.Optional)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 LambdaFunctionCall (io.confluent.ksql.execution.expression.tree.LambdaFunctionCall)2 UdfUtil (io.confluent.ksql.execution.function.UdfUtil)2 ParamTypes (io.confluent.ksql.function.types.ParamTypes)2 Udf (io.confluent.ksql.function.udf.Udf)2 UdfParameter (io.confluent.ksql.function.udf.UdfParameter)2 UdfSchemaProvider (io.confluent.ksql.function.udf.UdfSchemaProvider)2 SchemaConverters (io.confluent.ksql.schema.ksql.SchemaConverters)2