Search in sources :

Example 6 with ExpressionEvalContext

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

the class InsertMapPhysicalRel method entriesFn.

public Function<ExpressionEvalContext, List<Entry<Object, Object>>> entriesFn() {
    PartitionedMapTable table = table();
    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.toValues(evalContext).map(projector::project).collect(toList());
    };
}
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) Collectors.toList(java.util.stream.Collectors.toList) ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) KvProjector(com.hazelcast.jet.sql.impl.connector.keyvalue.KvProjector) UpsertTargetDescriptor(com.hazelcast.jet.sql.impl.inject.UpsertTargetDescriptor) 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) KvProjector(com.hazelcast.jet.sql.impl.connector.keyvalue.KvProjector) PartitionedMapTable(com.hazelcast.sql.impl.schema.map.PartitionedMapTable)

Example 7 with ExpressionEvalContext

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

the class RootResultConsumerSink method init.

@Override
public void init(@Nonnull Outbox outbox, @Nonnull Context context) {
    rootResultConsumer = getNodeEngine(context.hazelcastInstance()).getSqlService().getInternalService().getResultRegistry().remove(context.jobId());
    assert rootResultConsumer != null;
    ExpressionEvalContext evalContext = ExpressionEvalContext.from(context);
    Number limit = evaluate(limitExpression, evalContext);
    if (limit == null) {
        throw QueryException.error("LIMIT value cannot be null");
    }
    if (limit.longValue() < 0L) {
        throw QueryException.error("LIMIT value cannot be negative: " + limit);
    }
    Number offset = evaluate(offsetExpression, evalContext);
    if (offset == null) {
        throw QueryException.error("OFFSET value cannot be null");
    }
    if (offset.longValue() < 0L) {
        throw QueryException.error("OFFSET value cannot be negative: " + offset);
    }
    rootResultConsumer.init(limit.longValue(), offset.longValue());
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext)

Example 8 with ExpressionEvalContext

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

the class IndexFilterValueTest method testValueComposite.

@Test
public void testValueComposite() {
    ExpressionEvalContext evalContext = createExpressionEvalContext();
    IndexFilterValue value = new IndexFilterValue(asList(constant(1, QueryDataType.BIGINT), constant("2", QueryDataType.VARCHAR)), asList(true, true));
    assertEquals(composite(1L, "2"), value.getValue(evalContext));
    value = new IndexFilterValue(asList(constant(null, QueryDataType.BIGINT), constant("2", QueryDataType.VARCHAR)), asList(true, true));
    assertEquals(composite(AbstractIndex.NULL, "2"), value.getValue(evalContext));
    value = new IndexFilterValue(asList(constant(null, QueryDataType.BIGINT), constant("2", QueryDataType.VARCHAR)), asList(false, true));
    assertNull(value.getValue(evalContext));
    value = new IndexFilterValue(asList(constant(1L, QueryDataType.BIGINT), constant(null, QueryDataType.VARCHAR)), asList(true, false));
    assertNull(value.getValue(evalContext));
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) IndexFilterValue(com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with ExpressionEvalContext

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

the class IndexFilterValueTest method testValueSimple.

@Test
public void testValueSimple() {
    ExpressionEvalContext evalContext = createExpressionEvalContext();
    IndexFilterValue value = new IndexFilterValue(singletonList(constant(1, QueryDataType.BIGINT)), singletonList(true));
    assertEquals(1L, value.getValue(evalContext));
    value = new IndexFilterValue(singletonList(constant(null, QueryDataType.BIGINT)), singletonList(true));
    assertEquals(AbstractIndex.NULL, value.getValue(evalContext));
    value = new IndexFilterValue(singletonList(constant(null, QueryDataType.BIGINT)), singletonList(false));
    assertNull(value.getValue(evalContext));
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) IndexFilterValue(com.hazelcast.sql.impl.exec.scan.index.IndexFilterValue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with ExpressionEvalContext

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

the class IndexRangeFilterTest method testComparable.

@Test
public void testComparable() {
    ExpressionEvalContext evalContext = createExpressionEvalContext();
    assertEquals(1, new IndexRangeFilter(intValue(1, true), true, intValue(2, true), true).getComparable(evalContext));
    assertEquals(AbstractIndex.NULL, new IndexRangeFilter(intValue(null, true), true, intValue(2, true), true).getComparable(evalContext));
    assertNull(new IndexRangeFilter(intValue(null, false), true, intValue(2, true), true).getComparable(evalContext));
    assertEquals(2, new IndexRangeFilter(null, true, intValue(2, true), true).getComparable(evalContext));
    assertEquals(AbstractIndex.NULL, new IndexRangeFilter(null, true, intValue(null, true), true).getComparable(evalContext));
    assertNull(new IndexRangeFilter(null, true, intValue(null, false), true).getComparable(evalContext));
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

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