Search in sources :

Example 66 with WhereClause

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)));
}
Also used : Function(io.crate.expression.symbol.Function) EqOperator(io.crate.expression.operator.EqOperator) Bucket(io.crate.data.Bucket) StreamBucket(io.crate.execution.engine.distribution.StreamBucket) Symbol(io.crate.expression.symbol.Symbol) WhereClause(io.crate.analyze.WhereClause) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 67 with WhereClause

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;
    }
}
Also used : EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) DocKeys(io.crate.analyze.where.DocKeys) Collect(io.crate.planner.operators.Collect) Get(io.crate.planner.operators.Get) WhereClause(io.crate.analyze.WhereClause) DocTableRelation(io.crate.analyze.relations.DocTableRelation)

Example 68 with WhereClause

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());
}
Also used : Collect(io.crate.planner.operators.Collect) Stats(io.crate.statistics.Stats) TableStats(io.crate.statistics.TableStats) WhereClause(io.crate.analyze.WhereClause)

Example 69 with WhereClause

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()));
}
Also used : PartitionName(io.crate.metadata.PartitionName) WhereClause(io.crate.analyze.WhereClause) RelationName(io.crate.metadata.RelationName) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 70 with WhereClause

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))));
}
Also used : WhereClause(io.crate.analyze.WhereClause) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

WhereClause (io.crate.analyze.WhereClause)79 Test (org.junit.Test)55 CrateUnitTest (io.crate.test.integration.CrateUnitTest)30 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)20 Symbol (io.crate.analyze.symbol.Symbol)10 PartitionName (io.crate.metadata.PartitionName)8 RelationName (io.crate.metadata.RelationName)8 TableInfo (io.crate.metadata.table.TableInfo)7 Reference (io.crate.metadata.Reference)6 DocTableRelation (io.crate.analyze.relations.DocTableRelation)5 Symbol (io.crate.expression.symbol.Symbol)5 DocTableInfo (io.crate.metadata.doc.DocTableInfo)5 SqlExpressions (io.crate.testing.SqlExpressions)5 QueriedSelectRelation (io.crate.analyze.QueriedSelectRelation)4 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)4 Routing (io.crate.metadata.Routing)4 QualifiedName (io.crate.sql.tree.QualifiedName)4 ImmutableList (com.google.common.collect.ImmutableList)3 OrderBy (io.crate.analyze.OrderBy)3 Function (io.crate.analyze.symbol.Function)3