use of com.hazelcast.sql.impl.expression.Expression in project hazelcast by hazelcast.
the class IndexResolver method composeRangeFilter.
/**
* Create the composite range filter from the given per-column filters.
* <p>
* If the number of per-column filters if less than the number of index components, then infinite ranges are added
* to the missing components.
* <p>
* Consider that we have two per-column filter as input: {@code {a=1}, {b>2 AND b<3}}.
* <p>
* If the index is defined as {@code {a, b}}, then the resulting filter would be {@code {a=1, b>2 AND a=1, b<3}}.
* <p>
* If the index is defined as {@code {a, b, c}}, then the resulting filter would be
* {@code {a=1, b>2, c>NEGATIVE_INFINITY AND a=1, b<3, c<POSITIVE_INFINITY}}.
*
* @param filters all per-column filters
* @param lastFilter the last filter (range)
* @param componentsCount number of components in the filter
* @return range filter
*/
private static IndexFilter composeRangeFilter(List<IndexFilter> filters, IndexRangeFilter lastFilter, int componentsCount) {
// Flatten non-terminal components.
List<Expression> components = new ArrayList<>(filters.size());
List<Boolean> allowNulls = new ArrayList<>();
fillNonTerminalComponents(filters, components, allowNulls);
// Add value of the current filter.
List<Expression> fromComponents = components;
List<Expression> toComponents = new ArrayList<>(components);
List<Boolean> fromAllowNulls = allowNulls;
List<Boolean> toAllowNulls = new ArrayList<>(fromAllowNulls);
if (lastFilter.getFrom() != null) {
fromComponents.add(lastFilter.getFrom().getComponents().get(0));
fromAllowNulls.add(false);
} else {
if (componentsCount == 1) {
fromComponents.add(ConstantExpression.create(NEGATIVE_INFINITY, QueryDataType.OBJECT));
fromAllowNulls.add(false);
} else {
// In composite indexes null values are not stored separately. Therefore, we need to filter them out.
fromComponents.add(ConstantExpression.create(null, QueryDataType.OBJECT));
fromAllowNulls.add(true);
}
}
if (lastFilter.getTo() != null) {
toComponents.add(lastFilter.getTo().getComponents().get(0));
} else {
toComponents.add(ConstantExpression.create(POSITIVE_INFINITY, QueryDataType.OBJECT));
}
toAllowNulls.add(false);
// Fill missing part of the range request.
addInfiniteRanges(fromComponents, fromAllowNulls, lastFilter.isFromInclusive(), toComponents, toAllowNulls, lastFilter.isToInclusive(), componentsCount);
return new IndexRangeFilter(new IndexFilterValue(fromComponents, fromAllowNulls), lastFilter.isFromInclusive(), new IndexFilterValue(toComponents, toAllowNulls), lastFilter.isToInclusive());
}
use of com.hazelcast.sql.impl.expression.Expression in project hazelcast by hazelcast.
the class IndexFilterValueTest method testContent.
@Test
public void testContent() {
List<Expression> components = singletonList(constant(1, QueryDataType.INT));
List<Boolean> allowNulls = singletonList(true);
IndexFilterValue value = new IndexFilterValue(components, allowNulls);
assertSame(components, value.getComponents());
assertSame(allowNulls, value.getAllowNulls());
}
use of com.hazelcast.sql.impl.expression.Expression 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.Expression 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);
}
use of com.hazelcast.sql.impl.expression.Expression 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