use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class ApiSqlValueCoercerTest method shouldNotCoerceToStruct.
@Test
public void shouldNotCoerceToStruct() {
// Given:
final SqlType structType = SqlTypes.struct().field("foo", SqlTypes.STRING).build();
// When / Then:
assertThat(coercer.coerce(ImmutableMap.of("foo", "bar"), structType), is(Result.failure()));
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class ApiSqlValueCoercerTest method shouldNotCoerceToStructIfAnyFieldFailsToCoerce.
@Test
public void shouldNotCoerceToStructIfAnyFieldFailsToCoerce() {
// Given:
final Schema schema = SchemaBuilder.struct().field("foo", Schema.INT64_SCHEMA);
final Struct struct = new Struct(schema).put("foo", 2L);
final SqlType structType = SqlTypes.struct().field("foo", SqlTypes.array(SqlTypes.INTEGER)).build();
// When:
final Result result = coercer.coerce(struct, structType);
// Then:
assertThat(result, is(Result.failure()));
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class ApiSqlValueCoercerTest method shouldCoerceNestedJsonStructWithCaseInsensitiveFields.
@Test
public void shouldCoerceNestedJsonStructWithCaseInsensitiveFields() {
// Given:
final SqlType structType = SqlTypes.struct().field("F1", SqlTypes.struct().field("FOO", SqlTypes.BIGINT).field("foo", SqlTypes.STRING).field("bar", SqlTypes.STRING).build()).build();
final JsonObject obj = new JsonObject().put("F1", new JsonObject().put("foo", 12).put("`foo`", "v1").put("\"bar\"", "v2"));
// When:
final Result result = coercer.coerce(obj, structType);
// Then:
assertThat("", !result.failed());
final Struct coerced = ((Optional<Struct>) result.value()).get();
final Struct innerStruct = ((Struct) coerced.get("F1"));
assertThat(innerStruct.get("FOO"), is(12L));
assertThat(innerStruct.get("foo"), is("v1"));
assertThat(innerStruct.get("bar"), is("v2"));
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class ApiSqlValueCoercerTest method shouldNotCoerceToMap.
@Test
public void shouldNotCoerceToMap() {
final SqlType mapType = SqlTypes.map(SqlTypes.STRING, SqlTypes.DOUBLE);
assertThat(coercer.coerce(true, mapType), is(Result.failure()));
assertThat(coercer.coerce(1L, mapType), is(Result.failure()));
assertThat(coercer.coerce("foo", mapType), is(Result.failure()));
assertThat(coercer.coerce(new Timestamp(3213), mapType), is(Result.failure()));
assertThat(coercer.coerce(new Time(3213), mapType), is(Result.failure()));
assertThat(coercer.coerce(new Date(3213), mapType), is(Result.failure()));
assertThat(coercer.coerce(ByteBuffer.wrap(new byte[] { 123 }), mapType), is(Result.failure()));
assertThat(coercer.coerce(ImmutableList.of("foo"), mapType), is(Result.failure()));
assertThat(coercer.coerce(new JsonArray().add("foo"), mapType), is(Result.failure()));
}
use of io.confluent.ksql.schema.ksql.types.SqlType in project ksql by confluentinc.
the class ApiSqlValueCoercerTest method getType.
private static SqlType getType(final SqlBaseType baseType) {
final SqlType type = TYPES.get(baseType);
assertThat("invalid test: need type for base type:" + baseType, type, is(notNullValue()));
return type;
}
Aggregations