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);
}
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);
}
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();
}
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();
}
}
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));
};
}
Aggregations