Search in sources :

Example 1 with PartitionedMapTable

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

the class IMapSqlConnector method indexScanReader.

@Nonnull
@SuppressWarnings("checkstyle:ParameterNumber")
public Vertex indexScanReader(@Nonnull DAG dag, @Nonnull Address localMemberAddress, @Nonnull Table table0, @Nonnull MapTableIndex tableIndex, @Nullable Expression<Boolean> remainingFilter, @Nonnull List<Expression<?>> projection, @Nullable IndexFilter indexFilter, @Nullable ComparatorEx<JetSqlRow> comparator, boolean descending) {
    PartitionedMapTable table = (PartitionedMapTable) table0;
    MapIndexScanMetadata indexScanMetadata = new MapIndexScanMetadata(table.getMapName(), tableIndex.getName(), table.getKeyDescriptor(), table.getValueDescriptor(), Arrays.asList(table.paths()), Arrays.asList(table.types()), indexFilter, projection, remainingFilter, comparator, descending);
    Vertex scanner = dag.newUniqueVertex("Index(" + toString(table) + ")", readMapIndexSupplier(indexScanMetadata));
    // LP must be 1 - one local index contains all local partitions, if there are 2 local processors,
    // the index will be scanned twice and each time half of the partitions will be thrown out.
    scanner.localParallelism(1);
    if (tableIndex.getType() == IndexType.SORTED) {
        Vertex sorter = dag.newUniqueVertex("SortCombine", ProcessorMetaSupplier.forceTotalParallelismOne(ProcessorSupplier.of(mapP(FunctionEx.identity())), localMemberAddress));
        assert comparator != null;
        dag.edge(between(scanner, sorter).ordered(comparator).distributeTo(localMemberAddress).allToOne(""));
        return sorter;
    }
    return scanner;
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) MapIndexScanMetadata(com.hazelcast.sql.impl.exec.scan.MapIndexScanMetadata) PartitionedMapTable(com.hazelcast.sql.impl.schema.map.PartitionedMapTable) Nonnull(javax.annotation.Nonnull)

Example 2 with PartitionedMapTable

use of com.hazelcast.sql.impl.schema.map.PartitionedMapTable 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 3 with PartitionedMapTable

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

the class IMapSqlConnector method nestedLoopReader.

@Nonnull
@Override
public VertexWithInputConfig nestedLoopReader(@Nonnull DAG dag, @Nonnull Table table0, @Nullable Expression<Boolean> predicate, @Nonnull List<Expression<?>> projections, @Nonnull JetJoinInfo joinInfo) {
    PartitionedMapTable table = (PartitionedMapTable) table0;
    KvRowProjector.Supplier rightRowProjectorSupplier = KvRowProjector.supplier(table.paths(), table.types(), table.getKeyDescriptor(), table.getValueDescriptor(), predicate, projections);
    return Joiner.join(dag, table.getMapName(), toString(table), joinInfo, rightRowProjectorSupplier);
}
Also used : KvRowProjector(com.hazelcast.jet.sql.impl.connector.keyvalue.KvRowProjector) PartitionedMapTable(com.hazelcast.sql.impl.schema.map.PartitionedMapTable) Nonnull(javax.annotation.Nonnull)

Example 4 with PartitionedMapTable

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

the class SinkMapPhysicalRel method entriesFn.

public Function<ExpressionEvalContext, Map<Object, Object>> entriesFn() {
    PartitionedMapTable table = table();
    List<ExpressionValues> values = this.values;
    return evalContext -> {
        KvProjector projector = KvProjector.supplier(table.paths(), table.types(), (UpsertTargetDescriptor) table.getKeyJetMetadata(), (UpsertTargetDescriptor) table.getValueJetMetadata(), true).get(evalContext.getSerializationService());
        return values.stream().flatMap(vs -> vs.toValues(evalContext)).map(projector::project).collect(toMap(Entry::getKey, Entry::getValue));
    };
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlKind(org.apache.calcite.sql.SqlKind) PlanNodeSchema(com.hazelcast.sql.impl.plan.node.PlanNodeSchema) AbstractRelNode(org.apache.calcite.rel.AbstractRelNode) ExpressionValues(com.hazelcast.jet.sql.impl.opt.ExpressionValues) PlanObjectKey(com.hazelcast.sql.impl.optimizer.PlanObjectKey) RelNode(org.apache.calcite.rel.RelNode) RelOptUtil(org.apache.calcite.plan.RelOptUtil) Function(java.util.function.Function) QueryParameterMetadata(com.hazelcast.sql.impl.QueryParameterMetadata) RelOptTable(org.apache.calcite.plan.RelOptTable) RelWriter(org.apache.calcite.rel.RelWriter) Vertex(com.hazelcast.jet.core.Vertex) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) List(java.util.List) ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) Collectors.toMap(java.util.stream.Collectors.toMap) KvProjector(com.hazelcast.jet.sql.impl.connector.keyvalue.KvProjector) UpsertTargetDescriptor(com.hazelcast.jet.sql.impl.inject.UpsertTargetDescriptor) Map(java.util.Map) Entry(java.util.Map.Entry) PartitionedMapTable(com.hazelcast.sql.impl.schema.map.PartitionedMapTable) RelTraitSet(org.apache.calcite.plan.RelTraitSet) ExpressionValues(com.hazelcast.jet.sql.impl.opt.ExpressionValues) Entry(java.util.Map.Entry) KvProjector(com.hazelcast.jet.sql.impl.connector.keyvalue.KvProjector) PartitionedMapTable(com.hazelcast.sql.impl.schema.map.PartitionedMapTable)

Example 5 with PartitionedMapTable

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

the class IndexScanMapPhysicalRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    FullScanLogicalRel logicalScan = call.rel(0);
    PartitionedMapTable table = table(logicalScan);
    for (RelNode indexScan : IndexResolver.createIndexScans(logicalScan, table.getIndexes())) {
        call.transformTo(indexScan);
    }
}
Also used : RelNode(org.apache.calcite.rel.RelNode) PartitionedMapTable(com.hazelcast.sql.impl.schema.map.PartitionedMapTable) FullScanLogicalRel(com.hazelcast.jet.sql.impl.opt.logical.FullScanLogicalRel)

Aggregations

PartitionedMapTable (com.hazelcast.sql.impl.schema.map.PartitionedMapTable)12 Vertex (com.hazelcast.jet.core.Vertex)6 Nonnull (javax.annotation.Nonnull)6 List (java.util.List)5 UpsertTargetDescriptor (com.hazelcast.jet.sql.impl.inject.UpsertTargetDescriptor)4 HazelcastTable (com.hazelcast.jet.sql.impl.schema.HazelcastTable)3 ConstantTableStatistics (com.hazelcast.sql.impl.schema.ConstantTableStatistics)3 TableResolver (com.hazelcast.sql.impl.schema.TableResolver)3 RelNode (org.apache.calcite.rel.RelNode)3 TestTableResolver (com.hazelcast.jet.sql.impl.TestTableResolver)2 KvProjector (com.hazelcast.jet.sql.impl.connector.keyvalue.KvProjector)2 ExpressionValues (com.hazelcast.jet.sql.impl.opt.ExpressionValues)2 FullScanLogicalRel (com.hazelcast.jet.sql.impl.opt.logical.FullScanLogicalRel)2 QueryParameterMetadata (com.hazelcast.sql.impl.QueryParameterMetadata)2 ExpressionEvalContext (com.hazelcast.sql.impl.expression.ExpressionEvalContext)2 PlanObjectKey (com.hazelcast.sql.impl.optimizer.PlanObjectKey)2 PlanNodeSchema (com.hazelcast.sql.impl.plan.node.PlanNodeSchema)2 SqlCatalog (com.hazelcast.sql.impl.schema.SqlCatalog)2 TableField (com.hazelcast.sql.impl.schema.TableField)2 MapTableIndex (com.hazelcast.sql.impl.schema.map.MapTableIndex)2