Search in sources :

Example 1 with TableField

use of com.hazelcast.sql.impl.schema.TableField in project hazelcast by hazelcast.

the class IMapSqlConnector method createTable.

@Nonnull
@Override
public Table createTable(@Nonnull NodeEngine nodeEngine, @Nonnull String schemaName, @Nonnull String mappingName, @Nonnull String externalName, @Nonnull Map<String, String> options, @Nonnull List<MappingField> resolvedFields) {
    InternalSerializationService ss = (InternalSerializationService) nodeEngine.getSerializationService();
    KvMetadata keyMetadata = METADATA_RESOLVERS.resolveMetadata(true, resolvedFields, options, ss);
    KvMetadata valueMetadata = METADATA_RESOLVERS.resolveMetadata(false, resolvedFields, options, ss);
    List<TableField> fields = concat(keyMetadata.getFields().stream(), valueMetadata.getFields().stream()).collect(toList());
    MapService service = nodeEngine.getService(MapService.SERVICE_NAME);
    MapServiceContext context = service.getMapServiceContext();
    MapContainer container = context.getExistingMapContainer(externalName);
    long estimatedRowCount = estimatePartitionedMapRowCount(nodeEngine, context, externalName);
    boolean hd = container != null && container.getMapConfig().getInMemoryFormat() == InMemoryFormat.NATIVE;
    List<MapTableIndex> indexes = container != null ? MapTableUtils.getPartitionedMapIndexes(container, fields) : emptyList();
    return new PartitionedMapTable(schemaName, mappingName, externalName, fields, new ConstantTableStatistics(estimatedRowCount), keyMetadata.getQueryTargetDescriptor(), valueMetadata.getQueryTargetDescriptor(), keyMetadata.getUpsertTargetDescriptor(), valueMetadata.getUpsertTargetDescriptor(), indexes, hd);
}
Also used : TableField(com.hazelcast.sql.impl.schema.TableField) KvMetadata(com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata) ConstantTableStatistics(com.hazelcast.sql.impl.schema.ConstantTableStatistics) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) MapContainer(com.hazelcast.map.impl.MapContainer) MapTableIndex(com.hazelcast.sql.impl.schema.map.MapTableIndex) PartitionedMapTable(com.hazelcast.sql.impl.schema.map.PartitionedMapTable) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) MapService(com.hazelcast.map.impl.MapService) Nonnull(javax.annotation.Nonnull)

Example 2 with TableField

use of com.hazelcast.sql.impl.schema.TableField in project hazelcast by hazelcast.

the class MetadataCompactResolver method resolveMetadata.

@Override
public KvMetadata resolveMetadata(boolean isKey, List<MappingField> resolvedFields, Map<String, String> options, InternalSerializationService serializationService) {
    Map<QueryPath, MappingField> fieldsByPath = extractFields(resolvedFields, isKey);
    String typeNameProperty = isKey ? OPTION_KEY_COMPACT_TYPE_NAME : OPTION_VALUE_COMPACT_TYPE_NAME;
    String typeName = options.get(typeNameProperty);
    List<TableField> fields = new ArrayList<>(fieldsByPath.size());
    for (Entry<QueryPath, MappingField> entry : fieldsByPath.entrySet()) {
        QueryPath path = entry.getKey();
        QueryDataType type = entry.getValue().type();
        String name = entry.getValue().name();
        fields.add(new MapTableField(name, type, false, path));
    }
    maybeAddDefaultField(isKey, resolvedFields, fields, QueryDataType.OBJECT);
    Schema schema = resolveSchema(typeName, fieldsByPath);
    return new KvMetadata(fields, GenericQueryTargetDescriptor.DEFAULT, new CompactUpsertTargetDescriptor(schema));
}
Also used : QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) Schema(com.hazelcast.internal.serialization.impl.compact.Schema) ArrayList(java.util.ArrayList) CompactUpsertTargetDescriptor(com.hazelcast.jet.sql.impl.inject.CompactUpsertTargetDescriptor) MappingField(com.hazelcast.sql.impl.schema.MappingField) TableField(com.hazelcast.sql.impl.schema.TableField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) KvMetadata(com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) QueryPath(com.hazelcast.sql.impl.extract.QueryPath)

Example 3 with TableField

use of com.hazelcast.sql.impl.schema.TableField in project hazelcast by hazelcast.

the class KafkaSqlConnector method createTable.

@Nonnull
@Override
public Table createTable(@Nonnull NodeEngine nodeEngine, @Nonnull String schemaName, @Nonnull String mappingName, @Nonnull String externalName, @Nonnull Map<String, String> options, @Nonnull List<MappingField> resolvedFields) {
    KvMetadata keyMetadata = METADATA_RESOLVERS.resolveMetadata(true, resolvedFields, options, null);
    KvMetadata valueMetadata = METADATA_RESOLVERS.resolveMetadata(false, resolvedFields, options, null);
    List<TableField> fields = concat(keyMetadata.getFields().stream(), valueMetadata.getFields().stream()).collect(toList());
    return new KafkaTable(this, schemaName, mappingName, fields, new ConstantTableStatistics(0), externalName, options, keyMetadata.getQueryTargetDescriptor(), keyMetadata.getUpsertTargetDescriptor(), valueMetadata.getQueryTargetDescriptor(), valueMetadata.getUpsertTargetDescriptor());
}
Also used : TableField(com.hazelcast.sql.impl.schema.TableField) KvMetadata(com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata) ConstantTableStatistics(com.hazelcast.sql.impl.schema.ConstantTableStatistics) Nonnull(javax.annotation.Nonnull)

Example 4 with TableField

use of com.hazelcast.sql.impl.schema.TableField in project hazelcast by hazelcast.

the class KvMetadataAvroResolver method resolveMetadata.

@Override
public KvMetadata resolveMetadata(boolean isKey, List<MappingField> resolvedFields, Map<String, String> options, InternalSerializationService serializationService) {
    Map<QueryPath, MappingField> fieldsByPath = extractFields(resolvedFields, isKey);
    List<TableField> fields = new ArrayList<>();
    for (Entry<QueryPath, MappingField> entry : fieldsByPath.entrySet()) {
        QueryPath path = entry.getKey();
        QueryDataType type = entry.getValue().type();
        String name = entry.getValue().name();
        fields.add(new MapTableField(name, type, false, path));
    }
    maybeAddDefaultField(isKey, resolvedFields, fields, QueryDataType.OBJECT);
    return new KvMetadata(fields, AvroQueryTargetDescriptor.INSTANCE, new AvroUpsertTargetDescriptor(schema(fields).toString()));
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) ArrayList(java.util.ArrayList) AvroUpsertTargetDescriptor(com.hazelcast.jet.sql.impl.inject.AvroUpsertTargetDescriptor) MappingField(com.hazelcast.sql.impl.schema.MappingField) TableField(com.hazelcast.sql.impl.schema.TableField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField)

Example 5 with TableField

use of com.hazelcast.sql.impl.schema.TableField in project hazelcast by hazelcast.

the class KvMetadataJavaResolver method resolvePrimitiveMetadata.

private KvMetadata resolvePrimitiveMetadata(boolean isKey, List<MappingField> resolvedFields, Map<QueryPath, MappingField> fieldsByPath, QueryDataType type) {
    List<TableField> fields = new ArrayList<>();
    QueryPath path = isKey ? QueryPath.KEY_PATH : QueryPath.VALUE_PATH;
    MappingField field = fieldsByPath.get(path);
    if (field != null) {
        fields.add(new MapTableField(field.name(), field.type(), false, path));
    }
    maybeAddDefaultField(isKey, resolvedFields, fields, type);
    return new KvMetadata(fields, GenericQueryTargetDescriptor.DEFAULT, PrimitiveUpsertTargetDescriptor.INSTANCE);
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) ArrayList(java.util.ArrayList) TableField(com.hazelcast.sql.impl.schema.TableField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) MappingField(com.hazelcast.sql.impl.schema.MappingField) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField)

Aggregations

TableField (com.hazelcast.sql.impl.schema.TableField)22 MapTableField (com.hazelcast.sql.impl.schema.map.MapTableField)15 QueryPath (com.hazelcast.sql.impl.extract.QueryPath)13 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)12 ArrayList (java.util.ArrayList)10 HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)8 MappingField (com.hazelcast.sql.impl.schema.MappingField)7 KvMetadata (com.hazelcast.jet.sql.impl.connector.keyvalue.KvMetadata)5 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 Nonnull (javax.annotation.Nonnull)3 Test (org.junit.Test)3 ConstantTableStatistics (com.hazelcast.sql.impl.schema.ConstantTableStatistics)2 Parameters (junitparams.Parameters)2 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)2 ImmutableList (com.google.common.collect.ImmutableList)1 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1 Schema (com.hazelcast.internal.serialization.impl.compact.Schema)1 FilePlanObjectKey (com.hazelcast.jet.sql.impl.connector.file.FileTable.FilePlanObjectKey)1