Search in sources :

Example 1 with ExpressionEvalContext

use of com.hazelcast.sql.impl.expression.ExpressionEvalContext in project hazelcast by hazelcast.

the class PlanExecutor method execute.

SqlResult execute(IMapInsertPlan plan, List<Object> arguments, long timeout) {
    List<Object> args = prepareArguments(plan.parameterMetadata(), arguments);
    ExpressionEvalContext evalContext = new ExpressionEvalContext(args, Util.getSerializationService(hazelcastInstance));
    List<Entry<Object, Object>> entries = plan.entriesFn().apply(evalContext);
    if (!entries.isEmpty()) {
        assert entries.size() == 1;
        Entry<Object, Object> entry = entries.get(0);
        CompletableFuture<Object> future = ((MapProxyImpl<Object, Object>) hazelcastInstance.getMap(plan.mapName())).putIfAbsentAsync(entry.getKey(), entry.getValue()).toCompletableFuture();
        Object previous = await(future, timeout);
        if (previous != null) {
            throw QueryException.error("Duplicate key");
        }
    }
    return UpdateSqlResultImpl.createUpdateCountResult(0);
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) Entry(java.util.Map.Entry)

Example 2 with ExpressionEvalContext

use of com.hazelcast.sql.impl.expression.ExpressionEvalContext in project hazelcast by hazelcast.

the class PlanExecutor method execute.

SqlResult execute(IMapUpdatePlan plan, List<Object> arguments, long timeout) {
    List<Object> args = prepareArguments(plan.parameterMetadata(), arguments);
    ExpressionEvalContext evalContext = new ExpressionEvalContext(args, Util.getSerializationService(hazelcastInstance));
    Object key = plan.keyCondition().eval(EmptyRow.INSTANCE, evalContext);
    CompletableFuture<Long> future = hazelcastInstance.getMap(plan.mapName()).submitToKey(key, plan.updaterSupplier().get(arguments)).toCompletableFuture();
    await(future, timeout);
    return UpdateSqlResultImpl.createUpdateCountResult(0);
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext)

Example 3 with ExpressionEvalContext

use of com.hazelcast.sql.impl.expression.ExpressionEvalContext in project hazelcast by hazelcast.

the class StreamTable method items.

StreamSource<JetSqlRow> items(Expression<Boolean> predicate, List<Expression<?>> projections) {
    List<Expression<?>> argumentExpressions = this.argumentExpressions;
    return SourceBuilder.stream("stream", ctx -> {
        ExpressionEvalContext evalContext = ExpressionEvalContext.from(ctx);
        Integer rate = evaluate(argumentExpressions.get(0), evalContext);
        if (rate == null) {
            throw QueryException.error("Invalid argument of a call to function GENERATE_STREAM" + " - rate cannot be null");
        }
        if (rate < 0) {
            throw QueryException.error("Invalid argument of a call to function GENERATE_STREAM" + " - rate cannot be less than zero");
        }
        return new DataGenerator(rate, predicate, projections, evalContext);
    }).fillBufferFn(DataGenerator::fillBuffer).build();
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) Expression(com.hazelcast.sql.impl.expression.Expression)

Example 4 with ExpressionEvalContext

use of com.hazelcast.sql.impl.expression.ExpressionEvalContext in project hazelcast by hazelcast.

the class SlidingWindow method windowPolicyProvider.

public final FunctionEx<ExpressionEvalContext, SlidingWindowPolicy> windowPolicyProvider() {
    QueryParameterMetadata parameterMetadata = ((HazelcastRelOptCluster) getCluster()).getParameterMetadata();
    RexToExpressionVisitor visitor = new RexToExpressionVisitor(FAILING_FIELD_TYPE_PROVIDER, parameterMetadata);
    if (operator() == HazelcastSqlOperatorTable.TUMBLE) {
        Expression<?> windowSizeExpression = operand(2).accept(visitor);
        return context -> tumblingWinPolicy(WindowUtils.extractMillis(windowSizeExpression, context));
    } else if (operator() == HazelcastSqlOperatorTable.HOP) {
        Expression<?> windowSizeExpression = operand(2).accept(visitor);
        Expression<?> slideSizeExpression = operand(3).accept(visitor);
        return context -> slidingWinPolicy(WindowUtils.extractMillis(windowSizeExpression, context), WindowUtils.extractMillis(slideSizeExpression, context));
    } else {
        throw new IllegalArgumentException();
    }
}
Also used : SlidingWindowPolicy.slidingWinPolicy(com.hazelcast.jet.core.SlidingWindowPolicy.slidingWinPolicy) QueryParameterMetadata(com.hazelcast.sql.impl.QueryParameterMetadata) FAILING_FIELD_TYPE_PROVIDER(com.hazelcast.sql.impl.plan.node.PlanNodeFieldTypeProvider.FAILING_FIELD_TYPE_PROVIDER) SlidingWindowPolicy(com.hazelcast.jet.core.SlidingWindowPolicy) HazelcastRelOptCluster(org.apache.calcite.plan.HazelcastRelOptCluster) RelColumnMapping(org.apache.calcite.rel.metadata.RelColumnMapping) RexNode(org.apache.calcite.rex.RexNode) SqlOperator(org.apache.calcite.sql.SqlOperator) RexToExpressionVisitor(com.hazelcast.jet.sql.impl.opt.physical.visitor.RexToExpressionVisitor) Expression(com.hazelcast.sql.impl.expression.Expression) Preconditions.checkTrue(com.hazelcast.internal.util.Preconditions.checkTrue) RelTraitSet(org.apache.calcite.plan.RelTraitSet) RelOptCluster(org.apache.calcite.plan.RelOptCluster) FunctionEx(com.hazelcast.function.FunctionEx) TableFunctionScan(org.apache.calcite.rel.core.TableFunctionScan) RelDataType(org.apache.calcite.rel.type.RelDataType) Set(java.util.Set) RelNode(org.apache.calcite.rel.RelNode) RexInputRef(org.apache.calcite.rex.RexInputRef) List(java.util.List) ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) Type(java.lang.reflect.Type) HazelcastSqlOperatorTable(com.hazelcast.jet.sql.impl.validate.HazelcastSqlOperatorTable) SlidingWindowPolicy.tumblingWinPolicy(com.hazelcast.jet.core.SlidingWindowPolicy.tumblingWinPolicy) WindowUtils(com.hazelcast.jet.sql.impl.aggregate.WindowUtils) RexCall(org.apache.calcite.rex.RexCall) HazelcastRelOptCluster(org.apache.calcite.plan.HazelcastRelOptCluster) RexToExpressionVisitor(com.hazelcast.jet.sql.impl.opt.physical.visitor.RexToExpressionVisitor) Expression(com.hazelcast.sql.impl.expression.Expression) QueryParameterMetadata(com.hazelcast.sql.impl.QueryParameterMetadata)

Example 5 with ExpressionEvalContext

use of com.hazelcast.sql.impl.expression.ExpressionEvalContext 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)

Aggregations

ExpressionEvalContext (com.hazelcast.sql.impl.expression.ExpressionEvalContext)27 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 Test (org.junit.Test)9 IndexConfig (com.hazelcast.config.IndexConfig)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 InternalIndex (com.hazelcast.query.impl.InternalIndex)7 Expression (com.hazelcast.sql.impl.expression.Expression)6 Vertex (com.hazelcast.jet.core.Vertex)5 IndexRangeFilter (com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter)5 List (java.util.List)5 FunctionEx (com.hazelcast.function.FunctionEx)4 PlanObjectKey (com.hazelcast.sql.impl.optimizer.PlanObjectKey)4 JetSqlRow (com.hazelcast.sql.impl.row.JetSqlRow)4 DAG (com.hazelcast.jet.core.DAG)3 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)3 QueryParameterMetadata (com.hazelcast.sql.impl.QueryParameterMetadata)3 Map (java.util.Map)3 Entry (java.util.Map.Entry)3 RelOptCluster (org.apache.calcite.plan.RelOptCluster)3