Search in sources :

Example 41 with JetSqlRow

use of com.hazelcast.sql.impl.row.JetSqlRow in project hazelcast by hazelcast.

the class SlidingWindowAggregatePhysicalRel method outputValueMapping.

@SuppressWarnings("checkstyle:MagicNumber")
public KeyedWindowResultFunction<? super Object, ? super JetSqlRow, ?> outputValueMapping() {
    int[] windowBoundsIndexMask = new int[getRowType().getFieldCount()];
    QueryDataType descriptorType = HazelcastTypeUtils.toHazelcastType(timestampExpression.getType());
    for (Integer index : windowStartIndexes) {
        windowBoundsIndexMask[index] = -1;
    }
    for (Integer index : windowEndIndexes) {
        windowBoundsIndexMask[index] = -2;
    }
    for (int i = 0, j = 0; i < windowBoundsIndexMask.length; i++) {
        if (windowBoundsIndexMask[i] >= 0) {
            windowBoundsIndexMask[i] = j++;
        }
    }
    return (start, end, ignoredKey, result, isEarly) -> insertWindowBound(result, start, end, descriptorType, windowBoundsIndexMask);
}
Also used : WatermarkedFields(com.hazelcast.jet.sql.impl.opt.metadata.WatermarkedFields) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) HashMap(java.util.HashMap) QueryParameterMetadata(com.hazelcast.sql.impl.QueryParameterMetadata) ArrayList(java.util.ArrayList) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) ObjectArrayKey(com.hazelcast.jet.sql.impl.ObjectArrayKey) SlidingWindowPolicy(com.hazelcast.jet.core.SlidingWindowPolicy) HazelcastRelOptCluster(org.apache.calcite.plan.HazelcastRelOptCluster) AggregateOperation(com.hazelcast.jet.aggregate.AggregateOperation) RexNode(org.apache.calcite.rex.RexNode) Map(java.util.Map) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Expression(com.hazelcast.sql.impl.expression.Expression) RelTraitSet(org.apache.calcite.plan.RelTraitSet) RelOptCluster(org.apache.calcite.plan.RelOptCluster) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) FunctionEx(com.hazelcast.function.FunctionEx) KeyedWindowResultFunction(com.hazelcast.jet.core.function.KeyedWindowResultFunction) HazelcastTypeUtils(com.hazelcast.jet.sql.impl.validate.types.HazelcastTypeUtils) RexBuilder(org.apache.calcite.rex.RexBuilder) PlanNodeSchema(com.hazelcast.sql.impl.plan.node.PlanNodeSchema) OptUtils(com.hazelcast.jet.sql.impl.opt.OptUtils) RelNode(org.apache.calcite.rel.RelNode) Aggregate(org.apache.calcite.rel.core.Aggregate) ConstantFunctionEx(com.hazelcast.jet.impl.util.ConstantFunctionEx) Vertex(com.hazelcast.jet.core.Vertex) List(java.util.List) ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) RexVisitor(org.apache.calcite.rex.RexVisitor) WindowUtils.insertWindowBound(com.hazelcast.jet.sql.impl.aggregate.WindowUtils.insertWindowBound) AggregateCall(org.apache.calcite.rel.core.AggregateCall) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType)

Example 42 with JetSqlRow

use of com.hazelcast.sql.impl.row.JetSqlRow in project hazelcast by hazelcast.

the class JoinScanProcessorSupplier method join.

private static boolean join(@Nonnull List<JetSqlRow> rows, @Nonnull JetSqlRow left, @Nonnull List<JetSqlRow> rights, @Nonnull Expression<Boolean> condition, @Nonnull ExpressionEvalContext evalContext) {
    boolean matched = false;
    for (JetSqlRow right : rights) {
        JetSqlRow joined = ExpressionUtil.join(left, right, condition, evalContext);
        if (joined != null) {
            rows.add(joined);
            matched = true;
        }
    }
    return matched;
}
Also used : JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow)

Example 43 with JetSqlRow

use of com.hazelcast.sql.impl.row.JetSqlRow in project hazelcast by hazelcast.

the class JoinByPrimitiveKeyProcessorSupplier method get.

@Nonnull
@Override
public Collection<? extends Processor> get(int count) {
    List<Processor> processors = new ArrayList<>(count);
    for (int i = 0; i < count; i++) {
        String mapName = this.mapName;
        KvRowProjector projector = rightRowProjectorSupplier.get(evalContext, extractors);
        Processor processor = new AsyncTransformUsingServiceOrderedP<>(ServiceFactories.nonSharedService(SecuredFunctions.iMapFn(mapName)), null, MAX_CONCURRENT_OPS, (IMap<Object, Object> map, JetSqlRow left) -> {
            Object key = left.get(leftEquiJoinIndex);
            if (key == null) {
                return inner ? null : completedFuture(null);
            }
            return map.getAsync(key).toCompletableFuture();
        }, (left, value) -> {
            JetSqlRow joined = join(left, left.get(leftEquiJoinIndex), value, projector, condition, evalContext);
            return joined != null ? singleton(joined) : inner ? null : singleton(left.extendedRow(projector.getColumnCount()));
        });
        processors.add(processor);
    }
    return processors;
}
Also used : IMap(com.hazelcast.map.IMap) KvRowProjector(com.hazelcast.jet.sql.impl.connector.keyvalue.KvRowProjector) Processor(com.hazelcast.jet.core.Processor) AsyncTransformUsingServiceOrderedP(com.hazelcast.jet.impl.processor.AsyncTransformUsingServiceOrderedP) ArrayList(java.util.ArrayList) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) Nonnull(javax.annotation.Nonnull)

Example 44 with JetSqlRow

use of com.hazelcast.sql.impl.row.JetSqlRow in project hazelcast by hazelcast.

the class UpdatingEntryProcessor method process.

@Override
public Long process(Map.Entry<Object, Object> entry) {
    if (entry.getValue() == null) {
        return 0L;
    } else {
        JetSqlRow row = rowProjectorSupplier.get(evalContext, extractors).project(entry.getKey(), entry.getValue());
        Object value = valueProjectorSupplier.get(evalContext).project(row);
        if (value == null) {
            throw QueryException.error("Cannot assign null to value");
        } else {
            entry.setValue(value);
            return 1L;
        }
    }
}
Also used : JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow)

Example 45 with JetSqlRow

use of com.hazelcast.sql.impl.row.JetSqlRow in project hazelcast by hazelcast.

the class RowProjectorProcessorSupplier method get.

@Nonnull
@Override
public Collection<? extends Processor> get(int count) {
    List<Processor> processors = new ArrayList<>(count);
    for (int i = 0; i < count; i++) {
        ResettableSingletonTraverser<JetSqlRow> traverser = new ResettableSingletonTraverser<>();
        KvRowProjector projector = projectorSupplier.get(evalContext, extractors);
        Processor processor = new TransformP<LazyMapEntry<Object, Object>, JetSqlRow>(entry -> {
            traverser.accept(projector.project(entry.getKeyData(), entry.getValueData()));
            return traverser;
        });
        processors.add(processor);
    }
    return processors;
}
Also used : ResettableSingletonTraverser(com.hazelcast.jet.core.ResettableSingletonTraverser) KvRowProjector(com.hazelcast.jet.sql.impl.connector.keyvalue.KvRowProjector) Processor(com.hazelcast.jet.core.Processor) TransformP(com.hazelcast.jet.impl.processor.TransformP) ArrayList(java.util.ArrayList) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) Nonnull(javax.annotation.Nonnull)

Aggregations

JetSqlRow (com.hazelcast.sql.impl.row.JetSqlRow)50 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)16 QuickTest (com.hazelcast.test.annotation.QuickTest)16 Test (org.junit.Test)16 ExpressionEvalContext (com.hazelcast.sql.impl.expression.ExpressionEvalContext)15 ArrayList (java.util.ArrayList)14 Vertex (com.hazelcast.jet.core.Vertex)13 List (java.util.List)9 IndexConfig (com.hazelcast.config.IndexConfig)8 JobConfig (com.hazelcast.jet.config.JobConfig)8 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)8 NodeEngine (com.hazelcast.spi.impl.NodeEngine)8 Expression (com.hazelcast.sql.impl.expression.Expression)8 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)8 FunctionEx (com.hazelcast.function.FunctionEx)7 QueryParameterMetadata (com.hazelcast.sql.impl.QueryParameterMetadata)7 DAG (com.hazelcast.jet.core.DAG)6 ObjectArrayKey (com.hazelcast.jet.sql.impl.ObjectArrayKey)6 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)5 Traverser (com.hazelcast.jet.Traverser)5