use of com.hazelcast.sql.impl.QueryParameterMetadata in project hazelcast by hazelcast.
the class SlidingWindow method windowPolicyProvider.
public final FunctionEx<ExpressionEvalContext, SlidingWindowPolicy> windowPolicyProvider() {
QueryParameterMetadata parameterMetadata = ((HazelcastRelOptCluster) getCluster()).getParameterMetadata();
RexToExpressionVisitor visitor = new RexToExpressionVisitor(FAILING_FIELD_TYPE_PROVIDER, parameterMetadata);
if (operator() == HazelcastSqlOperatorTable.TUMBLE) {
Expression<?> windowSizeExpression = operand(2).accept(visitor);
return context -> tumblingWinPolicy(WindowUtils.extractMillis(windowSizeExpression, context));
} else if (operator() == HazelcastSqlOperatorTable.HOP) {
Expression<?> windowSizeExpression = operand(2).accept(visitor);
Expression<?> slideSizeExpression = operand(3).accept(visitor);
return context -> slidingWinPolicy(WindowUtils.extractMillis(windowSizeExpression, context), WindowUtils.extractMillis(slideSizeExpression, context));
} else {
throw new IllegalArgumentException();
}
}
use of com.hazelcast.sql.impl.QueryParameterMetadata in project hazelcast by hazelcast.
the class QueryParser method parse0.
private QueryParseResult parse0(String sql) throws SqlParseException {
SqlParser parser = SqlParser.create(sql, CONFIG);
SqlNodeList statements = parser.parseStmtList();
if (statements.size() != 1) {
throw QueryException.error(SqlErrorCode.PARSING, "The command must contain a single statement");
}
SqlNode topNode = statements.get(0);
SqlNode node = validator.validate(topNode);
SqlVisitor<Void> visitor = new UnsupportedOperationVisitor();
node.accept(visitor);
return new QueryParseResult(node, new QueryParameterMetadata(validator.getParameterConverters(node)), validator.isInfiniteRows());
}
use of com.hazelcast.sql.impl.QueryParameterMetadata in project hazelcast by hazelcast.
the class SlidingWindowAggregatePhysicalRel method timestampExpression.
public Expression<?> timestampExpression() {
QueryParameterMetadata parameterMetadata = ((HazelcastRelOptCluster) getCluster()).getParameterMetadata();
RexVisitor<Expression<?>> visitor = OptUtils.createRexToExpressionVisitor(schema(parameterMetadata), parameterMetadata);
return timestampExpression.accept(visitor);
}
use of com.hazelcast.sql.impl.QueryParameterMetadata in project hazelcast by hazelcast.
the class OptimizerTestSupport method context.
private static OptimizerContext context(HazelcastSchema schema, QueryDataType... parameterTypes) {
OptimizerContext context = OptimizerContext.create(HazelcastSchemaUtils.createCatalog(schema), QueryUtils.prepareSearchPaths(null, null), emptyList(), 1, name -> null);
ParameterConverter[] parameterConverters = IntStream.range(0, parameterTypes.length).mapToObj(i -> new StrictParameterConverter(i, SqlParserPos.ZERO, parameterTypes[i])).toArray(ParameterConverter[]::new);
QueryParameterMetadata parameterMetadata = new QueryParameterMetadata(parameterConverters);
context.setParameterMetadata(parameterMetadata);
return context;
}
use of com.hazelcast.sql.impl.QueryParameterMetadata in project hazelcast by hazelcast.
the class IndexResolver method prepareSingleColumnCandidates.
/**
* Creates a map from the scan column ordinal to expressions that could be potentially used by indexes created over
* this column.
*
* @param expressions CNF nodes
* @param allIndexedFieldOrdinals ordinals of all columns that have some indexes. Helps to filter out candidates that
* definitely cannot be used earlier.
*/
private static Map<Integer, List<IndexComponentCandidate>> prepareSingleColumnCandidates(List<RexNode> expressions, QueryParameterMetadata parameterMetadata, Set<Integer> allIndexedFieldOrdinals) {
Map<Integer, List<IndexComponentCandidate>> res = new HashMap<>();
// Iterate over each CNF component of the expression.
for (RexNode expression : expressions) {
// Try creating a candidate for the expression. The candidate is created iff the expression could be used
// by some index implementation (SORTED, HASH)
IndexComponentCandidate candidate = prepareSingleColumnCandidate(expression, parameterMetadata);
if (candidate == null) {
// Expression cannot be used by any index implementation, skip
continue;
}
if (!allIndexedFieldOrdinals.contains(candidate.getColumnIndex())) {
// Therefore, the expression could not be used, skip
continue;
}
// Group candidates by column. E.g. {a>1 AND a<3} is grouped into a single map entry: a->{>1},{<3}
res.computeIfAbsent(candidate.getColumnIndex(), (k) -> new ArrayList<>()).add(candidate);
}
return res;
}
Aggregations