Search in sources :

Example 21 with ExpressionEvalContext

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));
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) InternalIndex(com.hazelcast.query.impl.InternalIndex) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IndexConfig(com.hazelcast.config.IndexConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 22 with ExpressionEvalContext

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);
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext)

Example 23 with ExpressionEvalContext

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);
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext)

Example 24 with ExpressionEvalContext

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);
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) UpdateSqlResultImpl(com.hazelcast.sql.impl.UpdateSqlResultImpl)

Example 25 with ExpressionEvalContext

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();
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) Expression(com.hazelcast.sql.impl.expression.Expression)

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