Search in sources :

Example 11 with ExpressionEvalContext

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

the class IndexEqualsFilterTest method testComparable.

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

Example 12 with ExpressionEvalContext

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

the class IndexInFilterIterationTest method check.

private void check(IndexType indexType) {
    HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
    IMap<Integer, Value> map = instance.getMap(MAP_NAME);
    map.addIndex(new IndexConfig().setName(INDEX_NAME).setType(indexType).addAttribute("value1"));
    InternalIndex index = getIndex(instance);
    ExpressionEvalContext evalContext = createExpressionEvalContext();
    map.put(1, new Value(null));
    map.put(2, new Value(0));
    map.put(3, new Value(1));
    // No values from both filters
    checkIterator(indexType, descendingDirection, in(equals(2), equals(3)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, in(equals(3), equals(2)).getEntries(index, descendingDirection, evalContext));
    // No values from one filter
    checkIterator(indexType, descendingDirection, in(equals(1), equals(2)).getEntries(index, descendingDirection, evalContext), 3);
    checkIterator(indexType, descendingDirection, in(equals(2), equals(1)).getEntries(index, descendingDirection, evalContext), 3);
    checkIterator(indexType, descendingDirection, in(equals(null, true), equals(2)).getEntries(index, descendingDirection, evalContext), 1);
    checkIterator(indexType, descendingDirection, in(equals(2), equals(null, true)).getEntries(index, descendingDirection, evalContext), 1);
    // Values from both filters
    checkIterator(indexType, descendingDirection, in(equals(0), equals(1)).getEntries(index, descendingDirection, evalContext), 2, 3);
    checkIterator(indexType, descendingDirection, in(equals(1), equals(0)).getEntries(index, descendingDirection, evalContext), 2, 3);
    checkIterator(indexType, descendingDirection, in(equals(null, true), equals(0)).getEntries(index, descendingDirection, evalContext), 1, 2);
    checkIterator(indexType, descendingDirection, in(equals(0), equals(null, true)).getEntries(index, descendingDirection, evalContext), 1, 2);
    // One distinct value
    checkIterator(indexType, descendingDirection, in(equals(0), equals(0)).getEntries(index, descendingDirection, evalContext), 2);
    checkIterator(indexType, descendingDirection, in(equals(null, true), equals(null, true)).getEntries(index, descendingDirection, evalContext), 1);
    // One null value
    checkIterator(indexType, descendingDirection, in(equals(0), equals(null, false)).getEntries(index, descendingDirection, evalContext), 2);
    checkIterator(indexType, descendingDirection, in(equals(null, false), equals(0)).getEntries(index, descendingDirection, evalContext), 2);
    checkIterator(indexType, descendingDirection, in(equals(null, false), equals(null, true)).getEntries(index, descendingDirection, evalContext), 1);
    checkIterator(indexType, descendingDirection, in(equals(null, true), equals(null, false)).getEntries(index, descendingDirection, evalContext), 1);
    // Two null values
    checkIterator(indexType, descendingDirection, in(equals(null, false), equals(null, false)).getEntries(index, descendingDirection, evalContext));
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) InternalIndex(com.hazelcast.query.impl.InternalIndex) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IndexConfig(com.hazelcast.config.IndexConfig)

Example 13 with ExpressionEvalContext

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

the class IndexRangeFilterIteratorTest method testIterator_simple_between.

@Test
public void testIterator_simple_between() {
    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(0));
    map.put(1, new Value(10));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext));
    // Check left bound
    map.put(2, new Value(1));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2);
    map.put(3, new Value(1));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2, 3);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2, 3);
    map.remove(2);
    map.remove(3);
    // Check right bound
    map.put(2, new Value(5));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2);
    map.put(3, new Value(5));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2, 3);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2, 3);
    map.remove(2);
    map.remove(3);
    // Check middle
    map.put(2, new Value(3));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2);
    map.put(3, new Value(3));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2, 3);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2, 3);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2, 3);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2, 3);
    map.remove(2);
    map.remove(3);
    // Check combined
    map.put(2, new Value(1));
    map.put(3, new Value(1));
    map.put(4, new Value(3));
    map.put(5, new Value(3));
    map.put(6, new Value(5));
    map.put(7, new Value(5));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), false).getEntries(index, descendingDirection, evalContext), 4, 5);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), false).getEntries(index, descendingDirection, evalContext), 2, 3, 4, 5);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(5), true).getEntries(index, descendingDirection, evalContext), 4, 5, 6, 7);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, intValue(5), true).getEntries(index, descendingDirection, evalContext), 2, 3, 4, 5, 6, 7);
    // Check null value.
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(null, false), false, intValue(5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, intValue(null, false), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(null, false), false, intValue(null, false), false).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 14 with ExpressionEvalContext

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

the class TestAbstractSqlConnector method fullScanReader.

@Nonnull
@Override
public Vertex fullScanReader(@Nonnull DAG dag, @Nonnull Table table_, @Nullable Expression<Boolean> predicate, @Nonnull List<Expression<?>> projection, @Nullable FunctionEx<ExpressionEvalContext, EventTimePolicy<JetSqlRow>> eventTimePolicyProvider) {
    TestTable table = (TestTable) table_;
    List<Object[]> rows = table.rows;
    boolean streaming = table.streaming;
    FunctionEx<Context, TestDataGenerator> createContextFn = ctx -> {
        ExpressionEvalContext evalContext = ExpressionEvalContext.from(ctx);
        EventTimePolicy<JetSqlRow> eventTimePolicy = eventTimePolicyProvider == null ? EventTimePolicy.noEventTime() : eventTimePolicyProvider.apply(evalContext);
        return new TestDataGenerator(rows, predicate, projection, evalContext, eventTimePolicy, streaming);
    };
    ProcessorMetaSupplier pms = createProcessorSupplier(createContextFn);
    return dag.newUniqueVertex(table.toString(), pms);
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) Context(com.hazelcast.jet.core.Processor.Context) Traverser(com.hazelcast.jet.Traverser) Arrays(java.util.Arrays) PlanObjectKey(com.hazelcast.sql.impl.optimizer.PlanObjectKey) EventTimePolicy(com.hazelcast.jet.core.EventTimePolicy) QueryDataTypeFamily(com.hazelcast.sql.impl.type.QueryDataTypeFamily) ArrayList(java.util.ArrayList) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) String.join(java.lang.String.join) Map(java.util.Map) ConstantTableStatistics(com.hazelcast.sql.impl.schema.ConstantTableStatistics) SqlConnector(com.hazelcast.jet.sql.impl.connector.SqlConnector) DAG(com.hazelcast.jet.core.DAG) Expression(com.hazelcast.sql.impl.expression.Expression) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) EventTimeMapper(com.hazelcast.jet.core.EventTimeMapper) QueryException(com.hazelcast.sql.impl.QueryException) FunctionEx(com.hazelcast.function.FunctionEx) SqlService(com.hazelcast.sql.SqlService) NodeEngine(com.hazelcast.spi.impl.NodeEngine) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) JetTable(com.hazelcast.jet.sql.impl.schema.JetTable) Traversers(com.hazelcast.jet.Traversers) ExpressionUtil(com.hazelcast.jet.sql.impl.ExpressionUtil) Collectors.joining(java.util.stream.Collectors.joining) Objects(java.util.Objects) Vertex(com.hazelcast.jet.core.Vertex) TableField(com.hazelcast.sql.impl.schema.TableField) List(java.util.List) ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) QueryDataTypeUtils.resolveTypeForTypeFamily(com.hazelcast.sql.impl.type.QueryDataTypeUtils.resolveTypeForTypeFamily) Context(com.hazelcast.jet.core.Processor.Context) MappingField(com.hazelcast.sql.impl.schema.MappingField) SourceBuilder(com.hazelcast.jet.pipeline.SourceBuilder) Table(com.hazelcast.sql.impl.schema.Table) ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) EventTimePolicy(com.hazelcast.jet.core.EventTimePolicy) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Nonnull(javax.annotation.Nonnull)

Example 15 with ExpressionEvalContext

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

the class TestAllTypesSqlConnector method fullScanReader.

@Nonnull
@Override
public Vertex fullScanReader(@Nonnull DAG dag, @Nonnull Table table, @Nullable Expression<Boolean> predicate, @Nonnull List<Expression<?>> projection, @Nullable FunctionEx<ExpressionEvalContext, EventTimePolicy<JetSqlRow>> eventTimePolicyProvider) {
    if (eventTimePolicyProvider != null) {
        throw QueryException.error("Ordering function are not supported for " + TYPE_NAME + " mappings");
    }
    BatchSource<JetSqlRow> source = SourceBuilder.batch("batch", ExpressionEvalContext::from).<JetSqlRow>fillBufferFn((ctx, buf) -> {
        JetSqlRow row = ExpressionUtil.evaluate(predicate, projection, VALUES, ctx);
        if (row != null) {
            buf.add(row);
        }
        buf.close();
    }).build();
    ProcessorMetaSupplier pms = ((BatchSourceTransform<JetSqlRow>) source).metaSupplier;
    return dag.newUniqueVertex(table.toString(), pms);
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) LocalDateTime(java.time.LocalDateTime) PlanObjectKey(com.hazelcast.sql.impl.optimizer.PlanObjectKey) EventTimePolicy(com.hazelcast.jet.core.EventTimePolicy) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) BigDecimal(java.math.BigDecimal) TEST_SS(com.hazelcast.jet.sql.SqlTestSupport.TEST_SS) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ConstantTableStatistics(com.hazelcast.sql.impl.schema.ConstantTableStatistics) LocalTime(java.time.LocalTime) SqlConnector(com.hazelcast.jet.sql.impl.connector.SqlConnector) DAG(com.hazelcast.jet.core.DAG) Expression(com.hazelcast.sql.impl.expression.Expression) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) QueryException(com.hazelcast.sql.impl.QueryException) FunctionEx(com.hazelcast.function.FunctionEx) SqlService(com.hazelcast.sql.SqlService) NodeEngine(com.hazelcast.spi.impl.NodeEngine) BatchSource(com.hazelcast.jet.pipeline.BatchSource) Util.toList(com.hazelcast.jet.impl.util.Util.toList) ImmutableMap(com.google.common.collect.ImmutableMap) BatchSourceTransform(com.hazelcast.jet.impl.pipeline.transform.BatchSourceTransform) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) JetTable(com.hazelcast.jet.sql.impl.schema.JetTable) SqlTestSupport(com.hazelcast.jet.sql.SqlTestSupport) ExpressionUtil(com.hazelcast.jet.sql.impl.ExpressionUtil) Objects(java.util.Objects) Vertex(com.hazelcast.jet.core.Vertex) TableField(com.hazelcast.sql.impl.schema.TableField) List(java.util.List) ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) OffsetDateTime(java.time.OffsetDateTime) LocalDate(java.time.LocalDate) UTC(java.time.ZoneOffset.UTC) MappingField(com.hazelcast.sql.impl.schema.MappingField) SourceBuilder(com.hazelcast.jet.pipeline.SourceBuilder) Table(com.hazelcast.sql.impl.schema.Table) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) BatchSourceTransform(com.hazelcast.jet.impl.pipeline.transform.BatchSourceTransform) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Nonnull(javax.annotation.Nonnull)

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