Search in sources :

Example 31 with MappingField

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"));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) MappingField(com.hazelcast.sql.impl.schema.MappingField) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 32 with MappingField

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"));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationConfig(com.hazelcast.config.SerializationConfig) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) MappingField(com.hazelcast.sql.impl.schema.MappingField) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 33 with MappingField

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");
}
Also used : MappingField(com.hazelcast.sql.impl.schema.MappingField) Test(org.junit.Test)

Example 34 with MappingField

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" });
}
Also used : Mapping(com.hazelcast.sql.impl.schema.Mapping) MappingField(com.hazelcast.sql.impl.schema.MappingField) View(com.hazelcast.sql.impl.schema.view.View) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 35 with MappingField

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();
}
Also used : MappingField(com.hazelcast.sql.impl.schema.MappingField) Test(org.junit.Test)

Aggregations

MappingField (com.hazelcast.sql.impl.schema.MappingField)52 Test (org.junit.Test)23 QueryPath (com.hazelcast.sql.impl.extract.QueryPath)19 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)18 ArrayList (java.util.ArrayList)14 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)10 Mapping (com.hazelcast.sql.impl.schema.Mapping)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 Parameters (junitparams.Parameters)8 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)7 TableField (com.hazelcast.sql.impl.schema.TableField)7 MapTableField (com.hazelcast.sql.impl.schema.map.MapTableField)7 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)6 LinkedHashMap (java.util.LinkedHashMap)6 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)4 KvMetadata (com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata)3 QueryException (com.hazelcast.sql.impl.QueryException)3 SerializationConfig (com.hazelcast.config.SerializationConfig)2 View (com.hazelcast.sql.impl.schema.view.View)2