Search in sources :

Example 16 with MapTableField

use of com.hazelcast.sql.impl.schema.map.MapTableField in project hazelcast by hazelcast.

the class KvMetadataJavaResolverTest method test_resolvePrimitiveMetadata.

@Test
@Parameters({ "true, __key", "false, this" })
public void test_resolvePrimitiveMetadata(boolean key, String path) {
    Map<String, String> options = ImmutableMap.of((key ? OPTION_KEY_FORMAT : OPTION_VALUE_FORMAT), JAVA_FORMAT, (key ? OPTION_KEY_CLASS : OPTION_VALUE_CLASS), int.class.getName());
    KvMetadata metadata = INSTANCE.resolveMetadata(key, singletonList(field(path, QueryDataType.INT, path)), options, null);
    assertThat(metadata.getFields()).containsExactly(new MapTableField(path, QueryDataType.INT, false, QueryPath.create(path)));
    assertThat(metadata.getQueryTargetDescriptor()).isEqualTo(GenericQueryTargetDescriptor.DEFAULT);
    assertThat(metadata.getUpsertTargetDescriptor()).isEqualTo(PrimitiveUpsertTargetDescriptor.INSTANCE);
}
Also used : MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 17 with MapTableField

use of com.hazelcast.sql.impl.schema.map.MapTableField in project hazelcast by hazelcast.

the class KvMetadataJavaResolverTest method when_noKeyOrThisPrefixInExternalName_then_usesValue.

@Test
@Parameters({ "true", "false" })
public void when_noKeyOrThisPrefixInExternalName_then_usesValue(boolean key) {
    Map<String, String> options = ImmutableMap.of((key ? OPTION_KEY_FORMAT : OPTION_VALUE_FORMAT), JAVA_FORMAT, (key ? OPTION_KEY_CLASS : OPTION_VALUE_CLASS), Object.class.getName());
    KvMetadata metadata = INSTANCE.resolveMetadata(key, singletonList(field("field", QueryDataType.INT, "extField")), options, null);
    assertThat(metadata.getFields()).containsExactly(key ? new MapTableField[] { new MapTableField("__key", QueryDataType.OBJECT, true, QueryPath.KEY_PATH) } : new MapTableField[] { new MapTableField("field", QueryDataType.INT, false, new QueryPath("extField", false)), new MapTableField("this", QueryDataType.OBJECT, true, QueryPath.VALUE_PATH) });
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 18 with MapTableField

use of com.hazelcast.sql.impl.schema.map.MapTableField in project hazelcast by hazelcast.

the class MetadataJsonResolverTest method test_resolveMetadata.

@Test
@Parameters({ "true, __key", "false, this" })
public void test_resolveMetadata(boolean key, String prefix) {
    KvMetadata metadata = INSTANCE.resolveMetadata(key, singletonList(field("field", QueryDataType.INT, prefix + ".field")), emptyMap(), null);
    assertThat(metadata.getFields()).containsExactly(new MapTableField("field", QueryDataType.INT, false, QueryPath.create(prefix + ".field")), new MapTableField(prefix, QueryDataType.OBJECT, true, QueryPath.create(prefix)));
    assertThat(metadata.getQueryTargetDescriptor()).isEqualTo(HazelcastJsonQueryTargetDescriptor.INSTANCE);
    assertThat(metadata.getUpsertTargetDescriptor()).isEqualTo(HazelcastJsonUpsertTargetDescriptor.INSTANCE);
}
Also used : KvMetadata(com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 19 with MapTableField

use of com.hazelcast.sql.impl.schema.map.MapTableField in project hazelcast by hazelcast.

the class MetadataJsonResolverTest method when_noKeyOrThisPrefixInExternalName_then_usesValue.

@Test
@Parameters({ "true", "false" })
public void when_noKeyOrThisPrefixInExternalName_then_usesValue(boolean key) {
    KvMetadata metadata = INSTANCE.resolveMetadata(key, singletonList(field("field", QueryDataType.INT, "extField")), emptyMap(), null);
    assertThat(metadata.getFields()).containsExactly(key ? new MapTableField[] { new MapTableField("__key", QueryDataType.OBJECT, true, QueryPath.KEY_PATH) } : new MapTableField[] { new MapTableField("field", QueryDataType.INT, false, new QueryPath("extField", false)), new MapTableField("this", QueryDataType.OBJECT, true, QueryPath.VALUE_PATH) });
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) KvMetadata(com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 20 with MapTableField

use of com.hazelcast.sql.impl.schema.map.MapTableField in project hazelcast by hazelcast.

the class SqlIndexResolutionTest method checkIndexUsage.

private void checkIndexUsage(SqlStatement statement, String mapName, Usage expectedIndexUsage) {
    List<QueryDataType> parameterTypes = asList(QueryDataType.INT, QueryDataType.OBJECT, QueryDataType.INT);
    List<TableField> mapTableFields = asList(new MapTableField("__key", QueryDataType.INT, false, QueryPath.KEY_PATH), new MapTableField("field1", type1.getFieldConverterType(), false, new QueryPath("field1", false)), new MapTableField("field2", type2.getFieldConverterType(), false, new QueryPath("field2", false)));
    HazelcastTable table = partitionedTable(mapName, mapTableFields, getPartitionedMapIndexes(mapContainer(instance().getMap(mapName)), mapTableFields), // we can place random number, doesn't matter in current case.
    1);
    OptimizerTestSupport.Result optimizationResult = optimizePhysical(statement.getSql(), parameterTypes, table);
    assertPlan(optimizationResult.getLogical(), plan(planRow(0, FullScanLogicalRel.class)));
    switch(expectedIndexUsage) {
        case NONE:
            assertPlan(optimizationResult.getPhysical(), plan(planRow(0, FullScanPhysicalRel.class)));
            break;
        case ONE:
            assertPlan(optimizationResult.getPhysical(), plan(planRow(0, IndexScanMapPhysicalRel.class)));
            assertNotNull(((IndexScanMapPhysicalRel) optimizationResult.getPhysical()).getRemainderExp());
            break;
        case BOTH:
            assertPlan(optimizationResult.getPhysical(), plan(planRow(0, IndexScanMapPhysicalRel.class)));
            assertNull(((IndexScanMapPhysicalRel) optimizationResult.getPhysical()).getRemainderExp());
            break;
    }
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) OptimizerTestSupport(com.hazelcast.jet.sql.impl.opt.OptimizerTestSupport) TableField(com.hazelcast.sql.impl.schema.TableField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField)

Aggregations

MapTableField (com.hazelcast.sql.impl.schema.map.MapTableField)27 QueryPath (com.hazelcast.sql.impl.extract.QueryPath)17 TableField (com.hazelcast.sql.impl.schema.TableField)15 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)13 Parameters (junitparams.Parameters)12 Test (org.junit.Test)12 KvMetadata (com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata)8 HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)8 ArrayList (java.util.ArrayList)8 MappingField (com.hazelcast.sql.impl.schema.MappingField)7 OptimizerTestSupport (com.hazelcast.jet.sql.impl.opt.OptimizerTestSupport)5 FullScanPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.FullScanPhysicalRel)4 IndexScanMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel)4 PortableUpsertTargetDescriptor (com.hazelcast.jet.sql.impl.inject.PortableUpsertTargetDescriptor)3 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)2 AvroUpsertTargetDescriptor (com.hazelcast.jet.sql.impl.inject.AvroUpsertTargetDescriptor)2 CompactUpsertTargetDescriptor (com.hazelcast.jet.sql.impl.inject.CompactUpsertTargetDescriptor)2 PojoUpsertTargetDescriptor (com.hazelcast.jet.sql.impl.inject.PojoUpsertTargetDescriptor)2 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)2 ImmutableList (com.google.common.collect.ImmutableList)1