Search in sources :

Example 16 with MappingField

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

Example 17 with MappingField

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"));
}
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 18 with MappingField

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

Example 19 with MappingField

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

Example 20 with MappingField

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));
}
Also used : MappingField(com.hazelcast.sql.impl.schema.MappingField) LinkedHashMap(java.util.LinkedHashMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) 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