use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class MetadataPortableResolverTest method when_userDeclaresFields_then_fieldsNotAddedFromClassDefinition.
@Test
@Parameters({ "true, __key", "false, this" })
public void when_userDeclaresFields_then_fieldsNotAddedFromClassDefinition(boolean key, String prefix) {
InternalSerializationService ss = new DefaultSerializationServiceBuilder().build();
ClassDefinition classDefinition = new ClassDefinitionBuilder(1, 2, 3).addIntField("field1").addStringField("field2").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("field2", QueryDataType.VARCHAR, prefix + ".field2")), options, ss);
assertThat(resolvedFields).containsExactly(field("field2", QueryDataType.VARCHAR, prefix + ".field2"));
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class SampleMetadataResolverTest method test_compactRecord.
@Test
public void test_compactRecord() {
SerializationConfig serializationConfig = new SerializationConfig();
serializationConfig.getCompactSerializationConfig().setEnabled(true);
InternalSerializationService ss = new DefaultSerializationServiceBuilder().setSchemaService(CompactTestUtil.createInMemorySchemaService()).setConfig(serializationConfig).build();
Metadata metadata = SampleMetadataResolver.resolve(ss, GenericRecordBuilder.compact("type-name").setInt32("field", 1).build(), 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(GenericRecordBuilder.compact("type-name").setInt32("field", 1).build()), 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 KvMetadataResolversTest method when_invalidExternalName_then_throws.
@Test
public void when_invalidExternalName_then_throws() {
MappingField field = field("field_name", QueryDataType.INT, "invalid_prefix.name");
assertThatThrownBy(() -> resolvers.resolveAndValidateFields(singletonList(field), emptyMap(), nodeEngine)).hasMessage("Invalid external name: " + "invalid_prefix.name");
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class MappingColumnsTableTest method test_rows.
@Test
public void test_rows() {
// given
Mapping mapping = new Mapping("table-name", "table-external-name", "table-type", singletonList(new MappingField("table-field-name", INT, "table-field-external-name")), emptyMap());
View view = new View("view-name", "select * from table-name", false, singletonList("col1"), singletonList(INT));
MappingColumnsTable mappingColumnsTable = new MappingColumnsTable("catalog", null, "schema", singletonList(mapping), singletonList(view));
// when
List<Object[]> rows = mappingColumnsTable.rows();
// then
assertThat(rows).containsExactlyInAnyOrder(new Object[] { "catalog", "schema", "table-name", "table-field-name", "table-field-external-name", 1, "true", "INTEGER" }, new Object[] { "catalog", "schema", "view-name", "col1", null, 1, "true", "INTEGER" });
}
use of com.hazelcast.sql.impl.schema.MappingField in project hazelcast by hazelcast.
the class MetadataResolversTest method test_resolveMetadata.
@Test
public void test_resolveMetadata() {
// given
List<MappingField> resolvedFields = singletonList(new MappingField("field", QueryDataType.VARCHAR));
Map<String, String> options = ImmutableMap.of(OPTION_FORMAT, FORMAT, OPTION_PATH, "/path", OPTION_GLOB, "*");
given(resolver.resolveMetadata(resolvedFields, options)).willReturn(metadata);
// when
Metadata metadata = resolvers.resolveMetadata(resolvedFields, options);
// then
assertThat(metadata).isNotNull();
}
Aggregations