use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class MetadataTest method test_merge.
@Test
public void test_merge() {
Metadata first = new Metadata(asList(new MappingField("field1", QueryDataType.INT, "__key.field1"), new MappingField("field2", QueryDataType.INT, "__key.field2")), ImmutableMap.of("key1", "1", "key2", "2"));
Metadata second = new Metadata(asList(new MappingField("field2", QueryDataType.VARCHAR, "this.field2"), new MappingField("field3", QueryDataType.VARCHAR, "this.field3")), ImmutableMap.of("key2", "two", "key3", "three"));
Metadata merged = first.merge(second);
assertThat(merged).isEqualToComparingFieldByField(new Metadata(asList(new MappingField("field1", QueryDataType.INT, "__key.field1"), new MappingField("field2", QueryDataType.INT, "__key.field2"), new MappingField("field3", QueryDataType.VARCHAR, "this.field3")), ImmutableMap.of("key1", "1", "key2", "2", "key3", "three")));
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class MetadataCompactResolverTest method test_resolveFields.
@Test
@Parameters({ "true, __key", "false, this" })
public void test_resolveFields(boolean key, String prefix) {
InternalSerializationService ss = createSerializationService();
Map<String, String> options = ImmutableMap.of((key ? OPTION_KEY_COMPACT_TYPE_NAME : OPTION_VALUE_COMPACT_TYPE_NAME), "testAll");
List<MappingField> fields = asList(field("string", QueryDataType.VARCHAR, prefix + ".string"), field("character", QueryDataType.VARCHAR_CHARACTER, prefix + ".character"), field("boolean", QueryDataType.BOOLEAN, prefix + ".boolean"), field("byte", QueryDataType.TINYINT, prefix + ".byte"), field("short", QueryDataType.SMALLINT, prefix + ".short"), field("int", QueryDataType.INT, prefix + ".int"), field("long", QueryDataType.BIGINT, prefix + ".long"), field("float", QueryDataType.REAL, prefix + ".float"), field("double", QueryDataType.DOUBLE, prefix + ".double"), field("decimal", QueryDataType.DECIMAL, prefix + ".decimal"), field("time", QueryDataType.TIME, prefix + ".time"), field("date", QueryDataType.DATE, prefix + ".date"), field("timestamp", QueryDataType.TIMESTAMP, prefix + ".timestamp"), field("timestampTz", QueryDataType.TIMESTAMP_WITH_TZ_OFFSET_DATE_TIME, prefix + ".timestampTz"));
Stream<MappingField> resolvedFields = MetadataCompactResolver.INSTANCE.resolveAndValidateFields(key, fields, options, ss);
assertThat(resolvedFields).containsExactlyElementsOf(fields);
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class MetadataPortableResolverTest method test_resolveFieldsFromClassDefinition.
@Test
@Parameters({ "true, __key", "false, this" })
public void test_resolveFieldsFromClassDefinition(boolean key, String prefix) {
InternalSerializationService ss = new DefaultSerializationServiceBuilder().build();
ClassDefinition classDefinition = new ClassDefinitionBuilder(1, 2, 3).addStringField("string").addCharField("character").addBooleanField("boolean").addByteField("byte").addShortField("short").addIntField("int").addLongField("long").addFloatField("float").addDoubleField("double").addDecimalField("decimal").addTimeField("time").addDateField("date").addTimestampField("timestamp").addTimestampWithTimezoneField("timestampTz").addPortableField("object", new ClassDefinitionBuilder(4, 5, 6).build()).build();
ss.getPortableContext().registerClassDefinition(classDefinition);
Map<String, String> options = ImmutableMap.of((key ? OPTION_KEY_FACTORY_ID : OPTION_VALUE_FACTORY_ID), String.valueOf(classDefinition.getFactoryId()), (key ? OPTION_KEY_CLASS_ID : OPTION_VALUE_CLASS_ID), String.valueOf(classDefinition.getClassId()), (key ? OPTION_KEY_CLASS_VERSION : OPTION_VALUE_CLASS_VERSION), String.valueOf(classDefinition.getVersion()));
Stream<MappingField> resolvedFields = INSTANCE.resolveAndValidateFields(key, emptyList(), options, ss);
assertThat(resolvedFields).containsExactly(field("string", QueryDataType.VARCHAR, prefix + ".string"), field("character", QueryDataType.VARCHAR_CHARACTER, prefix + ".character"), field("boolean", QueryDataType.BOOLEAN, prefix + ".boolean"), field("byte", QueryDataType.TINYINT, prefix + ".byte"), field("short", QueryDataType.SMALLINT, prefix + ".short"), field("int", QueryDataType.INT, prefix + ".int"), field("long", QueryDataType.BIGINT, prefix + ".long"), field("float", QueryDataType.REAL, prefix + ".float"), field("double", QueryDataType.DOUBLE, prefix + ".double"), field("decimal", QueryDataType.DECIMAL, prefix + ".decimal"), field("time", QueryDataType.TIME, prefix + ".time"), field("date", QueryDataType.DATE, prefix + ".date"), field("timestamp", QueryDataType.TIMESTAMP, prefix + ".timestamp"), field("timestampTz", QueryDataType.TIMESTAMP_WITH_TZ_OFFSET_DATE_TIME, prefix + ".timestampTz"), field("object", QueryDataType.OBJECT, prefix + ".object"));
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class MetadataPortableResolverTest method when_userDeclaresField_then_itsNameHasPrecedenceOverClassDefinitionOne.
@Test
@Parameters({ "true, __key", "false, this" })
public void when_userDeclaresField_then_itsNameHasPrecedenceOverClassDefinitionOne(boolean key, String prefix) {
InternalSerializationService ss = new DefaultSerializationServiceBuilder().build();
ClassDefinition classDefinition = new ClassDefinitionBuilder(1, 2, 3).addIntField("field").build();
ss.getPortableContext().registerClassDefinition(classDefinition);
Map<String, String> options = ImmutableMap.of((key ? OPTION_KEY_FACTORY_ID : OPTION_VALUE_FACTORY_ID), String.valueOf(classDefinition.getFactoryId()), (key ? OPTION_KEY_CLASS_ID : OPTION_VALUE_CLASS_ID), String.valueOf(classDefinition.getClassId()), (key ? OPTION_KEY_CLASS_VERSION : OPTION_VALUE_CLASS_VERSION), String.valueOf(classDefinition.getVersion()));
Stream<MappingField> resolvedFields = INSTANCE.resolveAndValidateFields(key, singletonList(field("renamed_field", QueryDataType.INT, prefix + ".field")), options, ss);
assertThat(resolvedFields).containsExactly(field("renamed_field", QueryDataType.INT, prefix + ".field"));
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class MetadataPortableResolverTest method test_resolveFieldsWithoutClassDefinition.
@Test
@Parameters({ "true, __key", "false, this" })
public void test_resolveFieldsWithoutClassDefinition(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 = asList(field("string", QueryDataType.VARCHAR, prefix + ".string"), field("character", QueryDataType.VARCHAR_CHARACTER, prefix + ".character"), field("boolean", QueryDataType.BOOLEAN, prefix + ".boolean"), field("byte", QueryDataType.TINYINT, prefix + ".byte"), field("short", QueryDataType.SMALLINT, prefix + ".short"), field("int", QueryDataType.INT, prefix + ".int"), field("long", QueryDataType.BIGINT, prefix + ".long"), field("float", QueryDataType.REAL, prefix + ".float"), field("double", QueryDataType.DOUBLE, prefix + ".double"), field("decimal", QueryDataType.DECIMAL, prefix + ".decimal"), field("time", QueryDataType.TIME, prefix + ".time"), field("date", QueryDataType.DATE, prefix + ".date"), field("timestamp", QueryDataType.TIMESTAMP, prefix + ".timestamp"), field("timestampTz", QueryDataType.TIMESTAMP_WITH_TZ_OFFSET_DATE_TIME, prefix + ".timestampTz"));
Stream<MappingField> resolvedFields = INSTANCE.resolveAndValidateFields(key, fields, options, ss);
assertThat(resolvedFields).containsExactlyElementsOf(fields);
}
Aggregations