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