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"));
}
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));
}
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));
}
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)));
}
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));
}
Aggregations