Search in sources :

Example 6 with OrderBy

use of io.crate.analyze.OrderBy in project crate by crate.

the class QueriedDocTableFetchPushDownTest method testPushDownWithOrder.

@Test
public void testPushDownWithOrder() throws Exception {
    QuerySpec qs = new QuerySpec();
    qs.outputs(Lists.newArrayList(REF_A, REF_I));
    qs.orderBy(new OrderBy(Lists.newArrayList(REF_I), new boolean[] { true }, new Boolean[] { false }));
    QueriedDocTableFetchPushDown pd = new QueriedDocTableFetchPushDown(new QueriedDocTable(TABLE_REL, qs));
    QueriedDocTable sub = pd.pushDown();
    assertThat(qs, isSQL("SELECT FETCH(INPUT(0), s.t._doc['a']), INPUT(1) ORDER BY INPUT(1) DESC NULLS LAST"));
    assertThat(sub.querySpec(), isSQL("SELECT s.t._fetchid, s.t.i ORDER BY s.t.i DESC NULLS LAST"));
}
Also used : OrderBy(io.crate.analyze.OrderBy) QueriedDocTable(io.crate.analyze.relations.QueriedDocTable) QuerySpec(io.crate.analyze.QuerySpec) Test(org.junit.Test)

Example 7 with OrderBy

use of io.crate.analyze.OrderBy in project crate by crate.

the class QueriedDocTableFetchPushDownTest method testScoreDoesNotRequireFetch.

@Test
public void testScoreDoesNotRequireFetch() throws Exception {
    QuerySpec qs = new QuerySpec();
    qs.outputs(Lists.newArrayList(REF_I, REF_SCORE));
    qs.orderBy(new OrderBy(ImmutableList.of(REF_I), new boolean[] { true }, new Boolean[] { false }));
    QueriedDocTableFetchPushDown pd = new QueriedDocTableFetchPushDown(new QueriedDocTable(TABLE_REL, qs));
    assertNull(pd.pushDown());
}
Also used : OrderBy(io.crate.analyze.OrderBy) QueriedDocTable(io.crate.analyze.relations.QueriedDocTable) QuerySpec(io.crate.analyze.QuerySpec) Test(org.junit.Test)

Example 8 with OrderBy

use of io.crate.analyze.OrderBy in project crate by crate.

the class QueriedDocTableFetchPushDownTest method testNoPushDownWithOrder.

@Test
public void testNoPushDownWithOrder() throws Exception {
    QuerySpec qs = new QuerySpec();
    qs.outputs(Lists.newArrayList(REF_I));
    qs.orderBy(new OrderBy(ImmutableList.of(REF_I), new boolean[] { true }, new Boolean[] { false }));
    QueriedDocTableFetchPushDown pd = new QueriedDocTableFetchPushDown(new QueriedDocTable(TABLE_REL, qs));
    assertNull(pd.pushDown());
    assertThat(qs, isSQL("SELECT s.t.i ORDER BY s.t.i DESC NULLS LAST"));
}
Also used : OrderBy(io.crate.analyze.OrderBy) QueriedDocTable(io.crate.analyze.relations.QueriedDocTable) QuerySpec(io.crate.analyze.QuerySpec) Test(org.junit.Test)

Example 9 with OrderBy

use of io.crate.analyze.OrderBy in project crate by crate.

the class RoutedCollectPhaseTest method testNormalizeDoesNotRemoveOrderBy.

@Test
public void testNormalizeDoesNotRemoveOrderBy() throws Exception {
    Symbol toInt10 = CastFunctionResolver.generateCastFunction(Literal.of(10L), DataTypes.INTEGER, false);
    RoutedCollectPhase collect = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(Collections.emptyMap()), RowGranularity.DOC, Collections.singletonList(toInt10), Collections.emptyList(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_SAME_NODE);
    collect.orderBy(new OrderBy(Collections.singletonList(toInt10), new boolean[] { false }, new Boolean[] { null }));
    EvaluatingNormalizer normalizer = EvaluatingNormalizer.functionOnlyNormalizer(getFunctions(), ReplaceMode.COPY);
    RoutedCollectPhase normalizedCollect = collect.normalize(normalizer, new TransactionContext(SessionContext.SYSTEM_SESSION));
    assertThat(normalizedCollect.orderBy(), notNullValue());
}
Also used : OrderBy(io.crate.analyze.OrderBy) EvaluatingNormalizer(io.crate.analyze.EvaluatingNormalizer) Symbol(io.crate.analyze.symbol.Symbol) TransactionContext(io.crate.metadata.TransactionContext) Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 10 with OrderBy

use of io.crate.analyze.OrderBy in project crate by crate.

the class FetchRequiredVisitorTest method context.

private FetchRequiredVisitor.Context context(List<Symbol> orderBySymbols) {
    if (!orderBySymbols.isEmpty()) {
        boolean[] reverseFlags = new boolean[orderBySymbols.size()];
        Arrays.fill(reverseFlags, true);
        Boolean[] nullsFirst = new Boolean[orderBySymbols.size()];
        Arrays.fill(nullsFirst, Boolean.FALSE);
        OrderBy orderBy = new OrderBy(orderBySymbols, reverseFlags, nullsFirst);
        return new FetchRequiredVisitor.Context(new HashSet<>(orderBy.orderBySymbols()));
    }
    return new FetchRequiredVisitor.Context();
}
Also used : OrderBy(io.crate.analyze.OrderBy)

Aggregations

OrderBy (io.crate.analyze.OrderBy)27 Test (org.junit.Test)14 QuerySpec (io.crate.analyze.QuerySpec)13 QueriedDocTable (io.crate.analyze.relations.QueriedDocTable)8 Symbol (io.crate.analyze.symbol.Symbol)8 CrateUnitTest (io.crate.test.integration.CrateUnitTest)5 InputFactory (io.crate.operation.InputFactory)4 WhereClause (io.crate.analyze.WhereClause)3 Row (io.crate.data.Row)3 Reference (io.crate.metadata.Reference)3 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ShardId (org.elasticsearch.index.shard.ShardId)3 Function (io.crate.analyze.symbol.Function)2 AbsFunction (io.crate.operation.scalar.arithmetic.AbsFunction)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)2 Document (org.apache.lucene.document.Document)2