Search in sources :

Example 46 with SqlType

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

the class KsqlTypesSerdeModuleTest method shouldSerDeSqlMapTypes.

@Test
public void shouldSerDeSqlMapTypes() throws JsonProcessingException {
    // Given:
    final List<SqlType> types = ImmutableList.of(SqlTypes.INTEGER, SqlTypes.BIGINT, SqlTypes.DOUBLE, SqlTypes.STRING);
    for (final SqlType keyType : types) {
        for (final SqlType valueType : Lists.reverse(types)) {
            // When:
            final String serialized = MAPPER.writeValueAsString(SqlMap.of(keyType, valueType));
            final SqlType out = MAPPER.readValue(serialized, SqlType.class);
            // Then
            assertThat(out, is(SqlMap.of(keyType, valueType)));
        }
    }
}
Also used : SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Test(org.junit.Test)

Example 47 with SqlType

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

the class KsqlTypesSerdeModuleTest method shouldSerDeStructType.

@Test
public void shouldSerDeStructType() throws JsonProcessingException {
    // Given:
    SqlStruct struct = SqlStruct.builder().field("foo", SqlArray.of(SqlTypes.STRING)).build();
    // When:
    final SqlType out = MAPPER.readValue(MAPPER.writeValueAsString(struct), SqlType.class);
    // Then:
    assertThat(out, is(struct));
}
Also used : SqlStruct(io.confluent.ksql.schema.ksql.types.SqlStruct) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Test(org.junit.Test)

Example 48 with SqlType

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

the class KsqlTypesSerdeModuleTest method shouldSerDeSqlPrimitiveTypes.

@Test
public void shouldSerDeSqlPrimitiveTypes() throws JsonProcessingException {
    // Given:
    final SqlType[] types = new SqlType[] { SqlTypes.INTEGER, SqlTypes.BIGINT, SqlTypes.DOUBLE, SqlTypes.STRING };
    for (final SqlType type : types) {
        // When:
        final SqlType out = MAPPER.readValue(MAPPER.writeValueAsString(type), SqlType.class);
        // Then
        assertThat(out, is(type));
    }
}
Also used : SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Test(org.junit.Test)

Example 49 with SqlType

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

the class ConnectFormatSchemaTranslator method toColumn.

private static SimpleColumn toColumn(final Field field) {
    final ColumnName name = ColumnName.of(field.name());
    final SqlType type = SchemaConverters.connectToSqlConverter().toSqlType(field.schema());
    return new ConnectColumn(name, type);
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) SqlType(io.confluent.ksql.schema.ksql.types.SqlType)

Example 50 with SqlType

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

the class StepSchemaResolver method handleStreamSelectKeyV1.

private LogicalSchema handleStreamSelectKeyV1(final LogicalSchema sourceSchema, final StreamSelectKeyV1 step) {
    final ExpressionTypeManager expressionTypeManager = new ExpressionTypeManager(sourceSchema, functionRegistry);
    final SqlType keyType = expressionTypeManager.getExpressionSqlType(step.getKeyExpression());
    return LogicalSchema.builder().keyColumn(SystemColumns.ROWKEY_NAME, keyType).valueColumns(sourceSchema.value()).build();
}
Also used : ExpressionTypeManager(io.confluent.ksql.execution.util.ExpressionTypeManager) SqlType(io.confluent.ksql.schema.ksql.types.SqlType)

Aggregations

SqlType (io.confluent.ksql.schema.ksql.types.SqlType)140 Test (org.junit.Test)80 Expression (io.confluent.ksql.execution.expression.tree.Expression)47 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)38 KsqlException (io.confluent.ksql.util.KsqlException)33 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)30 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)29 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)29 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)29 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)29 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)29 NotExpression (io.confluent.ksql.execution.expression.tree.NotExpression)29 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)29 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)29 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)29 Optional (java.util.Optional)20 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)15 Result (io.confluent.ksql.schema.ksql.SqlValueCoercer.Result)14 Struct (org.apache.kafka.connect.data.Struct)14 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)13