Search in sources :

Example 1 with BOOLEAN

use of io.confluent.ksql.schema.ksql.types.SqlTypes.BOOLEAN in project ksql by confluentinc.

the class OperatorTest method shouldWorkUsingSameRulesAsBaseTypeUpCastRules.

@Test
public void shouldWorkUsingSameRulesAsBaseTypeUpCastRules() {
    allOperations().forEach(op -> {
        for (final SqlBaseType leftBaseType : SqlBaseType.values()) {
            // Given:
            final Map<Boolean, List<SqlBaseType>> partitioned = Arrays.stream(SqlBaseType.values()).collect(Collectors.partitioningBy(rightBaseType -> shouldBeSupported(op, leftBaseType, rightBaseType)));
            final List<SqlBaseType> shouldUpCast = partitioned.getOrDefault(true, ImmutableList.of());
            final List<SqlBaseType> shouldNotUpCast = partitioned.getOrDefault(false, ImmutableList.of());
            // Then:
            shouldUpCast.forEach(rightBaseType -> assertThat("should support " + op + " on (" + leftBaseType + ", " + rightBaseType + ")", op.resultType(getType(leftBaseType), getType(rightBaseType)), is(notNullValue())));
            shouldNotUpCast.forEach(rightBaseType -> {
                try {
                    op.resultType(getType(leftBaseType), getType(rightBaseType));
                    fail("should not support " + op + " on (" + leftBaseType + ", " + rightBaseType + ")");
                } catch (final KsqlException e) {
                // Expected
                }
            });
        }
    });
}
Also used : DIVIDE(io.confluent.ksql.schema.Operator.DIVIDE) Arrays(java.util.Arrays) Assert.assertThrows(org.junit.Assert.assertThrows) SqlBaseType(io.confluent.ksql.schema.ksql.types.SqlBaseType) BOOLEAN(io.confluent.ksql.schema.ksql.types.SqlTypes.BOOLEAN) INTEGER(io.confluent.ksql.schema.ksql.types.SqlTypes.INTEGER) ADD(io.confluent.ksql.schema.Operator.ADD) ImmutableList(com.google.common.collect.ImmutableList) DOUBLE(io.confluent.ksql.schema.ksql.types.SqlTypes.DOUBLE) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) TIME(io.confluent.ksql.schema.ksql.types.SqlTypes.TIME) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SUBTRACT(io.confluent.ksql.schema.Operator.SUBTRACT) TIMESTAMP(io.confluent.ksql.schema.ksql.types.SqlTypes.TIMESTAMP) BinaryOperator(java.util.function.BinaryOperator) BYTES(io.confluent.ksql.schema.ksql.types.SqlTypes.BYTES) List(java.util.List) STRING(io.confluent.ksql.schema.ksql.types.SqlTypes.STRING) SqlDecimal(io.confluent.ksql.schema.ksql.types.SqlDecimal) KsqlException(io.confluent.ksql.util.KsqlException) Matchers.is(org.hamcrest.Matchers.is) MULTIPLY(io.confluent.ksql.schema.Operator.MULTIPLY) BIGINT(io.confluent.ksql.schema.ksql.types.SqlTypes.BIGINT) DATE(io.confluent.ksql.schema.ksql.types.SqlTypes.DATE) MODULUS(io.confluent.ksql.schema.Operator.MODULUS) SqlTypes(io.confluent.ksql.schema.ksql.types.SqlTypes) Assert.assertEquals(org.junit.Assert.assertEquals) SqlBaseType(io.confluent.ksql.schema.ksql.types.SqlBaseType) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ADD (io.confluent.ksql.schema.Operator.ADD)1 DIVIDE (io.confluent.ksql.schema.Operator.DIVIDE)1 MODULUS (io.confluent.ksql.schema.Operator.MODULUS)1 MULTIPLY (io.confluent.ksql.schema.Operator.MULTIPLY)1 SUBTRACT (io.confluent.ksql.schema.Operator.SUBTRACT)1 SqlBaseType (io.confluent.ksql.schema.ksql.types.SqlBaseType)1 SqlDecimal (io.confluent.ksql.schema.ksql.types.SqlDecimal)1 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)1 SqlTypes (io.confluent.ksql.schema.ksql.types.SqlTypes)1 BIGINT (io.confluent.ksql.schema.ksql.types.SqlTypes.BIGINT)1 BOOLEAN (io.confluent.ksql.schema.ksql.types.SqlTypes.BOOLEAN)1 BYTES (io.confluent.ksql.schema.ksql.types.SqlTypes.BYTES)1 DATE (io.confluent.ksql.schema.ksql.types.SqlTypes.DATE)1 DOUBLE (io.confluent.ksql.schema.ksql.types.SqlTypes.DOUBLE)1 INTEGER (io.confluent.ksql.schema.ksql.types.SqlTypes.INTEGER)1 STRING (io.confluent.ksql.schema.ksql.types.SqlTypes.STRING)1 TIME (io.confluent.ksql.schema.ksql.types.SqlTypes.TIME)1 TIMESTAMP (io.confluent.ksql.schema.ksql.types.SqlTypes.TIMESTAMP)1