use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class MetadataPortableResolverTest method when_fieldIsObjectAndClassDefinitionDoesNotExist_then_throws.
@Test
@Parameters({ "true, __key", "false, this" })
public void when_fieldIsObjectAndClassDefinitionDoesNotExist_then_throws(boolean key, String prefix) {
InternalSerializationService ss = new DefaultSerializationServiceBuilder().build();
Map<String, String> options = ImmutableMap.of((key ? OPTION_KEY_FACTORY_ID : OPTION_VALUE_FACTORY_ID), "1", (key ? OPTION_KEY_CLASS_ID : OPTION_VALUE_CLASS_ID), "2", (key ? OPTION_KEY_CLASS_VERSION : OPTION_VALUE_CLASS_VERSION), "3");
List<MappingField> fields = singletonList(field("object", QueryDataType.OBJECT, prefix + ".object"));
// noinspection ResultOfMethodCallIgnored
assertThatThrownBy(() -> INSTANCE.resolveAndValidateFields(key, fields, options, ss).collect(toList())).isInstanceOf(QueryException.class).hasMessageContaining("Cannot derive Portable type for '" + QueryDataTypeFamily.OBJECT + "'");
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class SampleMetadataResolverTest method test_compact.
@Test
public void test_compact() {
SerializationConfig serializationConfig = new SerializationConfig();
serializationConfig.getCompactSerializationConfig().setEnabled(true).register(CompactClass.class, "type-name", new CompactClass.CompactClassSerializer());
InternalSerializationService ss = new DefaultSerializationServiceBuilder().setSchemaService(CompactTestUtil.createInMemorySchemaService()).setConfig(serializationConfig).build();
Metadata metadata = SampleMetadataResolver.resolve(ss, new CompactClass(1), key);
assertThat(metadata.fields()).containsExactly(new MappingField("field", QueryDataType.INT, (key ? KEY : VALUE) + ".field"));
assertThat(metadata.options()).containsExactly(entry(key ? OPTION_KEY_FORMAT : OPTION_VALUE_FORMAT, COMPACT_FORMAT), entry(key ? OPTION_KEY_COMPACT_TYPE_NAME : OPTION_VALUE_COMPACT_TYPE_NAME, "type-name"));
metadata = SampleMetadataResolver.resolve(ss, ss.toData(new CompactClass(1)), key);
assertThat(metadata.fields()).containsExactly(new MappingField("field", QueryDataType.INT, (key ? KEY : VALUE) + ".field"));
assertThat(metadata.options()).containsExactly(entry(key ? OPTION_KEY_FORMAT : OPTION_VALUE_FORMAT, COMPACT_FORMAT), entry(key ? OPTION_KEY_COMPACT_TYPE_NAME : OPTION_VALUE_COMPACT_TYPE_NAME, "type-name"));
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class AvroResolverTest method test_resolveFields.
@Test
public void test_resolveFields() {
// given
Schema schema = SchemaBuilder.record("name").fields().name("boolean").type().booleanType().noDefault().name("int").type().intType().noDefault().name("long").type().longType().noDefault().name("float").type().floatType().noDefault().name("double").type().doubleType().noDefault().name("string").type().stringType().noDefault().name("object").type().record("object").fields().endRecord().noDefault().endRecord();
// when
List<MappingField> fields = AvroResolver.resolveFields(schema);
// then
assertThat(fields).hasSize(7);
assertThat(fields.get(0)).isEqualTo(new MappingField("boolean", QueryDataType.BOOLEAN));
assertThat(fields.get(1)).isEqualTo(new MappingField("int", QueryDataType.INT));
assertThat(fields.get(2)).isEqualTo(new MappingField("long", QueryDataType.BIGINT));
assertThat(fields.get(3)).isEqualTo(new MappingField("float", QueryDataType.REAL));
assertThat(fields.get(4)).isEqualTo(new MappingField("double", QueryDataType.DOUBLE));
assertThat(fields.get(5)).isEqualTo(new MappingField("string", QueryDataType.VARCHAR));
assertThat(fields.get(6)).isEqualTo(new MappingField("object", QueryDataType.OBJECT));
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class CsvResolverTest method test_resolveFields.
@Test
public void test_resolveFields() {
// given
Set<String> headers = ImmutableSet.of("field1", "field2");
// when
List<MappingField> fields = CsvResolver.resolveFields(headers);
// then
assertThat(fields).hasSize(2);
assertThat(fields.get(0)).isEqualTo(new MappingField("field1", QueryDataType.VARCHAR));
assertThat(fields.get(1)).isEqualTo(new MappingField("field2", QueryDataType.VARCHAR));
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class JsonResolverTest method test_resolveFields.
@Test
public void test_resolveFields() {
// given
Map<String, Object> json = new LinkedHashMap<String, Object>() {
{
put("boolean", true);
put("number", 1);
put("string", "string");
put("object", emptyMap());
put("array", emptyList());
put("nullValue", null);
put("null", null);
}
};
// when
List<MappingField> fields = JsonResolver.resolveFields(json);
// then
assertThat(fields).hasSize(7);
assertThat(fields.get(0)).isEqualTo(new MappingField("boolean", QueryDataType.BOOLEAN));
assertThat(fields.get(1)).isEqualTo(new MappingField("number", QueryDataType.DOUBLE));
assertThat(fields.get(2)).isEqualTo(new MappingField("string", QueryDataType.VARCHAR));
assertThat(fields.get(3)).isEqualTo(new MappingField("object", QueryDataType.OBJECT));
assertThat(fields.get(4)).isEqualTo(new MappingField("array", QueryDataType.OBJECT));
assertThat(fields.get(5)).isEqualTo(new MappingField("nullValue", QueryDataType.OBJECT));
assertThat(fields.get(6)).isEqualTo(new MappingField("null", QueryDataType.OBJECT));
}
Aggregations