use of com.hazelcast.sql.impl.expression.ExpressionEvalContext in project hazelcast by hazelcast.
the class IndexRangeFilterIteratorTest method testIterator_simple_to.
@Test
public void testIterator_simple_to() {
HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
IMap<Integer, Value> map = instance.getMap(MAP_NAME);
map.addIndex(new IndexConfig().setName(INDEX_NAME).setType(SORTED).addAttribute("value1"));
InternalIndex index = getIndex(instance);
ExpressionEvalContext evalContext = createExpressionEvalContext();
// Check missing value.
map.put(0, new Value(10));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(null, false, intValue(2), false).getEntries(index, descendingDirection, evalContext));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(null, false, intValue(2), true).getEntries(index, descendingDirection, evalContext));
// Check single value.
map.put(1, new Value(2));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(null, false, intValue(2), false).getEntries(index, descendingDirection, evalContext));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(null, false, intValue(2), true).getEntries(index, descendingDirection, evalContext), 1);
// Check multiple values.
map.put(2, new Value(2));
map.put(3, new Value(1));
map.put(4, new Value(1));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(null, false, intValue(2), false).getEntries(index, descendingDirection, evalContext), 3, 4);
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(null, false, intValue(2), true).getEntries(index, descendingDirection, evalContext), 1, 2, 3, 4);
// Check null value.
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(null, false, intValue(null, false), false).getEntries(index, descendingDirection, evalContext));
checkIterator(SORTED, descendingDirection, new IndexRangeFilter(null, false, intValue(null, false), true).getEntries(index, descendingDirection, evalContext));
}
use of com.hazelcast.sql.impl.expression.ExpressionEvalContext in project hazelcast by hazelcast.
the class PlanExecutor method execute.
SqlResult execute(IMapSinkPlan plan, List<Object> arguments, long timeout) {
List<Object> args = prepareArguments(plan.parameterMetadata(), arguments);
ExpressionEvalContext evalContext = new ExpressionEvalContext(args, Util.getSerializationService(hazelcastInstance));
Map<Object, Object> entries = plan.entriesFn().apply(evalContext);
CompletableFuture<Void> future = hazelcastInstance.getMap(plan.mapName()).putAllAsync(entries).toCompletableFuture();
await(future, timeout);
return UpdateSqlResultImpl.createUpdateCountResult(0);
}
use of com.hazelcast.sql.impl.expression.ExpressionEvalContext in project hazelcast by hazelcast.
the class PlanExecutor method execute.
SqlResult execute(IMapDeletePlan 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<Void> future = hazelcastInstance.getMap(plan.mapName()).submitToKey(key, EntryRemovingProcessor.ENTRY_REMOVING_PROCESSOR).toCompletableFuture();
await(future, timeout);
return UpdateSqlResultImpl.createUpdateCountResult(0);
}
use of com.hazelcast.sql.impl.expression.ExpressionEvalContext in project hazelcast by hazelcast.
the class PlanExecutor method execute.
SqlResult execute(IMapSelectPlan plan, QueryId queryId, List<Object> arguments, long timeout) {
List<Object> args = prepareArguments(plan.parameterMetadata(), arguments);
InternalSerializationService serializationService = Util.getSerializationService(hazelcastInstance);
ExpressionEvalContext evalContext = new ExpressionEvalContext(args, serializationService);
Object key = plan.keyCondition().eval(EmptyRow.INSTANCE, evalContext);
CompletableFuture<JetSqlRow> future = hazelcastInstance.getMap(plan.mapName()).getAsync(key).toCompletableFuture().thenApply(value -> plan.rowProjectorSupplier().get(evalContext, Extractors.newBuilder(serializationService).build()).project(key, value));
JetSqlRow row = await(future, timeout);
return new SqlResultImpl(queryId, new StaticQueryResultProducerImpl(row), plan.rowMetadata(), false);
}
use of com.hazelcast.sql.impl.expression.ExpressionEvalContext in project hazelcast by hazelcast.
the class SeriesTable method items.
BatchSource<JetSqlRow> items(Expression<Boolean> predicate, List<Expression<?>> projections) {
List<Expression<?>> argumentExpressions = this.argumentExpressions;
return SourceBuilder.batch("series", ctx -> {
ExpressionEvalContext evalContext = ExpressionEvalContext.from(ctx);
Integer start = evaluate(argumentExpressions.get(0), null, evalContext);
Integer stop = evaluate(argumentExpressions.get(1), null, evalContext);
Integer step = evaluate(argumentExpressions.get(2), 1, evalContext);
if (start == null || stop == null || step == null) {
throw QueryException.error("Invalid argument of a call to function GENERATE_SERIES" + " - null argument(s)");
}
if (step == 0) {
throw QueryException.error("Invalid argument of a call to function GENERATE_SERIES" + " - step cannot be equal to zero");
}
return new DataGenerator(start, stop, step, predicate, projections, evalContext);
}).fillBufferFn(DataGenerator::fillBuffer).build();
}
Aggregations