Search in sources :

Example 11 with MapTableField

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

the class SqlIndexCastTest method checkIndexUsage.

private void checkIndexUsage(SqlStatement statement, ExpressionType<?> field, boolean expectedIndexUsage) {
    List<QueryDataType> parameterTypes = asList(QueryDataType.INT, field.getFieldConverterType());
    List<TableField> mapTableFields = asList(new MapTableField("__key", QueryDataType.INT, false, QueryPath.KEY_PATH), new MapTableField("field1", field.getFieldConverterType(), false, new QueryPath("field1", false)));
    HazelcastTable table = partitionedTable(MAP_NAME, mapTableFields, getPartitionedMapIndexes(mapContainer(instance().getMap(MAP_NAME)), mapTableFields), 1);
    Result optimizationResult = optimizePhysical(statement.getSql(), parameterTypes, table);
    assertPlan(optimizationResult.getLogical(), plan(planRow(0, FullScanLogicalRel.class)));
    assertPlan(optimizationResult.getPhysical(), plan(planRow(0, expectedIndexUsage ? IndexScanMapPhysicalRel.class : FullScanPhysicalRel.class)));
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) IndexScanMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) FullScanPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.FullScanPhysicalRel) 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)

Example 12 with MapTableField

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

the class MetadataCompactResolverTest method test_resolveMetadata.

@Test
@Parameters({ "true, __key", "false, this" })
public void test_resolveMetadata(boolean key, String prefix) {
    KvMetadata metadata = INSTANCE.resolveMetadata(key, asList(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("string", QueryDataType.VARCHAR, prefix + ".string"), 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")), ImmutableMap.of((key ? OPTION_KEY_COMPACT_TYPE_NAME : OPTION_VALUE_COMPACT_TYPE_NAME), "test"), createSerializationService());
    assertThat(metadata.getFields()).containsExactly(new MapTableField("boolean", QueryDataType.BOOLEAN, false, QueryPath.create(prefix + ".boolean")), new MapTableField("byte", QueryDataType.TINYINT, false, QueryPath.create(prefix + ".byte")), new MapTableField("short", QueryDataType.SMALLINT, false, QueryPath.create(prefix + ".short")), new MapTableField("int", QueryDataType.INT, false, QueryPath.create(prefix + ".int")), new MapTableField("long", QueryDataType.BIGINT, false, QueryPath.create(prefix + ".long")), new MapTableField("float", QueryDataType.REAL, false, QueryPath.create(prefix + ".float")), new MapTableField("double", QueryDataType.DOUBLE, false, QueryPath.create(prefix + ".double")), new MapTableField("decimal", QueryDataType.DECIMAL, false, QueryPath.create(prefix + ".decimal")), new MapTableField("string", QueryDataType.VARCHAR, false, QueryPath.create(prefix + ".string")), new MapTableField("time", QueryDataType.TIME, false, QueryPath.create(prefix + ".time")), new MapTableField("date", QueryDataType.DATE, false, QueryPath.create(prefix + ".date")), new MapTableField("timestamp", QueryDataType.TIMESTAMP, false, QueryPath.create(prefix + ".timestamp")), new MapTableField("timestampTz", QueryDataType.TIMESTAMP_WITH_TZ_OFFSET_DATE_TIME, false, QueryPath.create(prefix + ".timestampTz")), new MapTableField(prefix, QueryDataType.OBJECT, true, QueryPath.create(prefix)));
    assertThat(metadata.getQueryTargetDescriptor()).isEqualTo(GenericQueryTargetDescriptor.DEFAULT);
    SchemaWriter schemaWriter = new SchemaWriter("test");
    schemaWriter.addField(new FieldDescriptor("boolean", FieldKind.NULLABLE_BOOLEAN));
    schemaWriter.addField(new FieldDescriptor("byte", FieldKind.NULLABLE_INT8));
    schemaWriter.addField(new FieldDescriptor("short", FieldKind.NULLABLE_INT16));
    schemaWriter.addField(new FieldDescriptor("int", FieldKind.NULLABLE_INT32));
    schemaWriter.addField(new FieldDescriptor("long", FieldKind.NULLABLE_INT64));
    schemaWriter.addField(new FieldDescriptor("float", FieldKind.NULLABLE_FLOAT32));
    schemaWriter.addField(new FieldDescriptor("double", FieldKind.NULLABLE_FLOAT64));
    schemaWriter.addField(new FieldDescriptor("decimal", FieldKind.DECIMAL));
    schemaWriter.addField(new FieldDescriptor("string", FieldKind.STRING));
    schemaWriter.addField(new FieldDescriptor("time", FieldKind.TIME));
    schemaWriter.addField(new FieldDescriptor("date", FieldKind.DATE));
    schemaWriter.addField(new FieldDescriptor("timestamp", FieldKind.TIMESTAMP));
    schemaWriter.addField(new FieldDescriptor("timestampTz", FieldKind.TIMESTAMP_WITH_TIMEZONE));
    assertEquals(metadata.getUpsertTargetDescriptor(), new CompactUpsertTargetDescriptor(schemaWriter.build()));
}
Also used : CompactUpsertTargetDescriptor(com.hazelcast.jet.sql.impl.inject.CompactUpsertTargetDescriptor) KvMetadata(com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata) SchemaWriter(com.hazelcast.internal.serialization.impl.compact.SchemaWriter) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) FieldDescriptor(com.hazelcast.internal.serialization.impl.compact.FieldDescriptor) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 13 with MapTableField

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

the class MetadataPortableResolverTest method test_resolveMetadata.

@Test
@Parameters({ "true, __key", "false, this" })
public void test_resolveMetadata(boolean key, String prefix) {
    KvMetadata metadata = INSTANCE.resolveMetadata(key, asList(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("string", QueryDataType.VARCHAR, prefix + ".string"), 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")), 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"), new DefaultSerializationServiceBuilder().build());
    assertThat(metadata.getFields()).containsExactly(new MapTableField("boolean", QueryDataType.BOOLEAN, false, QueryPath.create(prefix + ".boolean")), new MapTableField("byte", QueryDataType.TINYINT, false, QueryPath.create(prefix + ".byte")), new MapTableField("short", QueryDataType.SMALLINT, false, QueryPath.create(prefix + ".short")), new MapTableField("int", QueryDataType.INT, false, QueryPath.create(prefix + ".int")), new MapTableField("long", QueryDataType.BIGINT, false, QueryPath.create(prefix + ".long")), new MapTableField("float", QueryDataType.REAL, false, QueryPath.create(prefix + ".float")), new MapTableField("double", QueryDataType.DOUBLE, false, QueryPath.create(prefix + ".double")), new MapTableField("decimal", QueryDataType.DECIMAL, false, QueryPath.create(prefix + ".decimal")), new MapTableField("string", QueryDataType.VARCHAR, false, QueryPath.create(prefix + ".string")), new MapTableField("time", QueryDataType.TIME, false, QueryPath.create(prefix + ".time")), new MapTableField("date", QueryDataType.DATE, false, QueryPath.create(prefix + ".date")), new MapTableField("timestamp", QueryDataType.TIMESTAMP, false, QueryPath.create(prefix + ".timestamp")), new MapTableField("timestampTz", QueryDataType.TIMESTAMP_WITH_TZ_OFFSET_DATE_TIME, false, QueryPath.create(prefix + ".timestampTz")), new MapTableField(prefix, QueryDataType.OBJECT, true, QueryPath.create(prefix)));
    assertThat(metadata.getQueryTargetDescriptor()).isEqualTo(GenericQueryTargetDescriptor.DEFAULT);
    assertThat(metadata.getUpsertTargetDescriptor()).isEqualToComparingFieldByField(new PortableUpsertTargetDescriptor(new ClassDefinitionBuilder(1, 2, 3).addBooleanField("boolean").addByteField("byte").addShortField("short").addIntField("int").addLongField("long").addFloatField("float").addDoubleField("double").addDecimalField("decimal").addStringField("string").addTimeField("time").addDateField("date").addTimestampField("timestamp").addTimestampWithTimezoneField("timestampTz").build()));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) PortableUpsertTargetDescriptor(com.hazelcast.jet.sql.impl.inject.PortableUpsertTargetDescriptor) KvMetadata(com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 14 with MapTableField

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

the class SqlIndexFromSearchFilterTest method table.

private HazelcastTable table() {
    List<TableField> mapTableFields = asList(new MapTableField("__key", QueryDataType.INT, false, QueryPath.KEY_PATH), new MapTableField("field1", INTEGER.getFieldConverterType(), false, new QueryPath("field1", false)), new MapTableField("field2", INTEGER.getFieldConverterType(), false, new QueryPath("field2", false)));
    HazelcastTable table = partitionedTable(mapName, mapTableFields, getPartitionedMapIndexes(mapContainer(instance().getMap(mapName)), mapTableFields), MAP_SIZE);
    return table;
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) 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)

Example 15 with MapTableField

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

the class KvMetadataAvroResolverTest 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) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) Parameters(junitparams.Parameters) Test(org.junit.Test)

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