use of io.crate.analyze.WhereClause in project crate by crate.
the class DocLevelCollectTest method testCollectDocLevelWhereClause.
@Test
public void testCollectDocLevelWhereClause() throws Throwable {
List<Symbol> arguments = Arrays.asList(testDocLevelReference, Literal.of(2));
EqOperator op = (EqOperator) functions.get(null, EqOperator.NAME, arguments, SearchPath.pathWithPGCatalogAndDoc());
List<Symbol> toCollect = Collections.singletonList(testDocLevelReference);
WhereClause whereClause = new WhereClause(new Function(op.signature(), arguments, EqOperator.RETURN_TYPE));
RoutedCollectPhase collectNode = getCollectNode(toCollect, whereClause);
Bucket result = collect(collectNode);
assertThat(result, contains(isRow(2)));
}
use of io.crate.analyze.WhereClause in project crate by crate.
the class OptimizeCollectWhereClauseAccess method apply.
@Override
public LogicalPlan apply(Collect collect, Captures captures, TableStats tableStats, TransactionContext txnCtx, NodeContext nodeCtx) {
var relation = (DocTableRelation) collect.relation();
var normalizer = new EvaluatingNormalizer(nodeCtx, RowGranularity.CLUSTER, null, relation);
WhereClause where = collect.where();
var detailedQuery = WhereClauseOptimizer.optimize(normalizer, where.queryOrFallback(), relation.tableInfo(), txnCtx, nodeCtx);
Optional<DocKeys> docKeys = detailedQuery.docKeys();
// noinspection OptionalIsPresent no capturing lambda allocation
if (docKeys.isPresent()) {
return new Get(relation, docKeys.get(), detailedQuery.query(), collect.outputs(), tableStats.estimatedSizePerRow(relation.relationName()));
} else if (!detailedQuery.clusteredBy().isEmpty() && collect.detailedQuery() == null) {
return new Collect(collect, detailedQuery);
} else {
return null;
}
}
use of io.crate.analyze.WhereClause in project crate by crate.
the class MergeFilterAndCollect method apply.
@Override
public LogicalPlan apply(Filter filter, Captures captures, TableStats tableStats, TransactionContext txnCtx, NodeContext nodeCtx) {
Collect collect = captures.get(collectCapture);
Stats stats = tableStats.getStats(collect.relation().tableInfo().ident());
WhereClause newWhere = collect.where().add(filter.query());
return new Collect(collect.relation(), collect.outputs(), newWhere, SelectivityFunctions.estimateNumRows(stats, newWhere.queryOrFallback(), null), stats.averageSizePerRowInBytes());
}
use of io.crate.analyze.WhereClause in project crate by crate.
the class WhereClauseAnalyzerTest method testEqualGenColOptimization.
@Test
public void testEqualGenColOptimization() throws Exception {
WhereClause whereClause = analyzeSelectWhere("select * from generated_col where y = 1");
assertThat(whereClause.partitions().size(), is(1));
assertThat(whereClause.partitions().get(0), is(new PartitionName(new RelationName("doc", "generated_col"), Arrays.asList("1420070400000", "-1")).asIndexName()));
}
use of io.crate.analyze.WhereClause in project crate by crate.
the class WhereClauseAnalyzerTest method testInConvertedToAnyIfOnlyLiterals.
@Test
public void testInConvertedToAnyIfOnlyLiterals() throws Exception {
StringBuilder sb = new StringBuilder("select id from sys.shards where id in (");
int i = 0;
for (; i < 1500; i++) {
sb.append(i);
sb.append(',');
}
sb.append(i++);
sb.append(')');
String s = sb.toString();
WhereClause whereClause = analyzeSelectWhere(s);
assertThat(whereClause.query(), isFunction(AnyEqOperator.NAME, List.of(DataTypes.INTEGER, new ArrayType<>(DataTypes.INTEGER))));
}
Aggregations