use of io.confluent.ksql.schema.ksql.types.SqlStruct in project ksql by confluentinc.
the class ExpressionFormatterTest method shouldFormatStructWithColumnWithReservedWordName.
@Test
public void shouldFormatStructWithColumnWithReservedWordName() {
final SqlStruct struct = SqlStruct.builder().field("RESERVED", SqlTypes.INTEGER).build();
assertThat(ExpressionFormatter.formatExpression(new Type(struct), FormatOptions.none()), equalTo("STRUCT<`RESERVED` INTEGER>"));
}
use of io.confluent.ksql.schema.ksql.types.SqlStruct in project ksql by confluentinc.
the class CoercionUtilTest method shouldCoerceStructOfCompatibleLiterals.
@Test
public void shouldCoerceStructOfCompatibleLiterals() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new CreateStructExpression(ImmutableList.of(new Field("a", new IntegerLiteral(10)))), new CreateStructExpression(ImmutableList.of(new Field("a", new StringLiteral("123456789000")))));
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
final SqlStruct sqlStruct = SqlTypes.struct().field("a", SqlTypes.BIGINT).build();
assertThat(result.commonType(), is(Optional.of(sqlStruct)));
assertThat(result.expressions(), is(ImmutableList.of(cast(new CreateStructExpression(ImmutableList.of(new Field("a", new IntegerLiteral(10)))), sqlStruct), cast(new CreateStructExpression(ImmutableList.of(new Field("a", new StringLiteral("123456789000")))), sqlStruct))));
}
use of io.confluent.ksql.schema.ksql.types.SqlStruct in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldThrowGoodErrorMessageForSubscriptOnStruct.
@Test
public void shouldThrowGoodErrorMessageForSubscriptOnStruct() {
// Given:
final SqlStruct structType = SqlTypes.struct().field("IN0", SqlTypes.INTEGER).build();
final LogicalSchema schema = LogicalSchema.builder().keyColumn(SystemColumns.ROWKEY_NAME, SqlTypes.STRING).valueColumn(COL0, structType).build();
expressionTypeManager = new ExpressionTypeManager(schema, functionRegistry);
final Expression expression = new SubscriptExpression(Optional.empty(), TestExpressions.COL0, new StringLiteral("IN0"));
// When:
final UnsupportedOperationException e = assertThrows(UnsupportedOperationException.class, () -> expressionTypeManager.getExpressionSqlType(expression));
// Then:
assertThat(e.getMessage(), is("Subscript expression (COL0['IN0']) do not apply to STRUCT<`IN0` INTEGER>. " + "Use the dereference operator for STRUCTS: COL0->'IN0'"));
}
use of io.confluent.ksql.schema.ksql.types.SqlStruct in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldEvaluateTypeForArrayReferenceInStruct.
@Test
public void shouldEvaluateTypeForArrayReferenceInStruct() {
// Given:
final SqlStruct inner = SqlTypes.struct().field("IN0", SqlTypes.array(SqlTypes.INTEGER)).build();
final LogicalSchema schema = LogicalSchema.builder().keyColumn(SystemColumns.ROWKEY_NAME, SqlTypes.STRING).valueColumn(COL0, inner).build();
expressionTypeManager = new ExpressionTypeManager(schema, functionRegistry);
final Expression structRef = new DereferenceExpression(Optional.empty(), new UnqualifiedColumnReferenceExp(COL0), "IN0");
final Expression expression = new SubscriptExpression(structRef, new IntegerLiteral(1));
// When:
final SqlType result = expressionTypeManager.getExpressionSqlType(expression);
// Then:
assertThat(result, is(SqlTypes.INTEGER));
}
use of io.confluent.ksql.schema.ksql.types.SqlStruct 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));
}
Aggregations