Search in sources :

Example 21 with ReferenceIdent

use of io.crate.metadata.ReferenceIdent in project crate by crate.

the class EvaluatingNormalizerTest method prepareFunctionTree.

/**
 * prepare the following where clause as function symbol tree:
 * <p>
 * where test.dummy.load = 0.08 or name != 'x' and name != 'y'
 * <p>
 * test.dummy.load is a expression that can be evaluated on node level
 * name would be a doc level reference and is untouched
 */
private Function prepareFunctionTree() {
    Reference load_1 = dummyLoadInfo;
    Literal<Double> d01 = Literal.of(0.08);
    Function load_eq_01 = new Function(EqOperator.SIGNATURE, List.of(load_1, d01), EqOperator.RETURN_TYPE);
    Symbol name_ref = new Reference(new ReferenceIdent(new RelationName(Schemas.DOC_SCHEMA_NAME, "foo"), "name"), RowGranularity.DOC, DataTypes.STRING, 0, null);
    Symbol x_literal = Literal.of("x");
    Symbol y_literal = Literal.of("y");
    Function name_eq_x = new Function(EqOperator.SIGNATURE, List.of(name_ref, x_literal), EqOperator.RETURN_TYPE);
    Function nameNeqX = new Function(NotPredicate.SIGNATURE, Collections.singletonList(name_eq_x), NotPredicate.SIGNATURE.getReturnType().createType());
    Function name_eq_y = new Function(EqOperator.SIGNATURE, List.of(name_ref, y_literal), EqOperator.RETURN_TYPE);
    Function nameNeqY = new Function(NotPredicate.SIGNATURE, Collections.singletonList(name_eq_y), NotPredicate.SIGNATURE.getReturnType().createType());
    Function op_and = new Function(AndOperator.SIGNATURE, List.of(nameNeqX, nameNeqY), AndOperator.RETURN_TYPE);
    return new Function(OrOperator.SIGNATURE, List.of(load_eq_01, op_and), OrOperator.RETURN_TYPE);
}
Also used : Function(io.crate.expression.symbol.Function) Reference(io.crate.metadata.Reference) Symbol(io.crate.expression.symbol.Symbol) RelationName(io.crate.metadata.RelationName) ReferenceIdent(io.crate.metadata.ReferenceIdent)

Example 22 with ReferenceIdent

use of io.crate.metadata.ReferenceIdent in project crate by crate.

the class GroupByAnalyzerTest method testGroupByLiteralAliasedWithRealColumnNameGroupsByColumnValue.

@Test
public void testGroupByLiteralAliasedWithRealColumnNameGroupsByColumnValue() {
    QueriedSelectRelation relation = analyze("select 58 as age from foo.users group by age;");
    assertThat(relation.groupBy().isEmpty(), is(false));
    List<Symbol> groupBySymbols = relation.groupBy();
    ReferenceIdent groupByIdent = ((Reference) groupBySymbols.get(0)).ident();
    assertThat(groupByIdent.columnIdent().fqn(), is("age"));
    assertThat(groupByIdent.tableIdent().fqn(), is("foo.users"));
}
Also used : Symbol(io.crate.expression.symbol.Symbol) Reference(io.crate.metadata.Reference) SymbolMatchers.isReference(io.crate.testing.SymbolMatchers.isReference) ReferenceIdent(io.crate.metadata.ReferenceIdent) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 23 with ReferenceIdent

use of io.crate.metadata.ReferenceIdent in project crate by crate.

the class NodeStatsTest method prepare.

@Before
public void prepare() {
    idRef = new Reference(new ReferenceIdent(SysNodesTableInfo.IDENT, SysNodesTableInfo.Columns.ID), RowGranularity.DOC, DataTypes.STRING, 1, null);
    nameRef = new Reference(new ReferenceIdent(SysNodesTableInfo.IDENT, SysNodesTableInfo.Columns.ID), RowGranularity.DOC, DataTypes.STRING, 2, null);
    hostnameRef = new Reference(new ReferenceIdent(SysNodesTableInfo.IDENT, SysNodesTableInfo.Columns.HOSTNAME), RowGranularity.DOC, DataTypes.STRING, 3, null);
    collectPhase = mock(RoutedCollectPhase.class);
    when(collectPhase.where()).thenReturn(Literal.BOOLEAN_FALSE);
    nodes.add(newNode("nodeOne"));
    nodes.add(newNode("nodeTwo"));
    nodeCtx = createNodeContext();
}
Also used : Reference(io.crate.metadata.Reference) ReferenceIdent(io.crate.metadata.ReferenceIdent) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Before(org.junit.Before)

Example 24 with ReferenceIdent

use of io.crate.metadata.ReferenceIdent in project crate by crate.

the class LuceneOrderedDocCollectorTest method testSearchAfterWithSystemColumn.

@Test
public void testSearchAfterWithSystemColumn() {
    Reference sysColReference = new Reference(new ReferenceIdent(new RelationName(Schemas.DOC_SCHEMA_NAME, "table"), DocSysColumns.SCORE), RowGranularity.DOC, DataTypes.FLOAT, 0, null);
    OrderBy orderBy = new OrderBy(List.of(sysColReference, REFERENCE), new boolean[] { false, false }, new boolean[] { false, false });
    FieldDoc lastCollected = new FieldDoc(0, 0, new Object[] { 2L });
    OptimizeQueryForSearchAfter queryForSearchAfter = new OptimizeQueryForSearchAfter(orderBy, mock(QueryShardContext.class), name -> valueFieldType);
    Query nextPageQuery = queryForSearchAfter.apply(lastCollected);
    // returns null which leads to reuse of old query without paging optimization
    assertNull(nextPageQuery);
}
Also used : OrderBy(io.crate.analyze.OrderBy) FieldDoc(org.apache.lucene.search.FieldDoc) Query(org.apache.lucene.search.Query) FuzzyQuery(org.apache.lucene.search.FuzzyQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) TermQuery(org.apache.lucene.search.TermQuery) Reference(io.crate.metadata.Reference) RelationName(io.crate.metadata.RelationName) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) ReferenceIdent(io.crate.metadata.ReferenceIdent) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest) Test(org.junit.Test)

Example 25 with ReferenceIdent

use of io.crate.metadata.ReferenceIdent in project crate by crate.

the class DocValuesGroupByOptimizedIteratorTest method test_group_by_doc_values_optimized_iterator_for_single_numeric_key.

@Test
public void test_group_by_doc_values_optimized_iterator_for_single_numeric_key() throws Exception {
    SumAggregation<?> sumAggregation = (SumAggregation<?>) functions.getQualified(Signature.aggregate(SumAggregation.NAME, DataTypes.LONG.getTypeSignature(), DataTypes.LONG.getTypeSignature()), List.of(DataTypes.LONG), DataTypes.LONG);
    var sumDocValuesAggregator = sumAggregation.getDocValueAggregator(List.of(new Reference(new ReferenceIdent(RelationName.fromIndexName("test"), "z"), RowGranularity.DOC, DataTypes.LONG, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 0, null)), mock(DocTableInfo.class), List.of());
    var keyExpressions = List.of(new LongColumnReference("y"));
    var it = DocValuesGroupByOptimizedIterator.GroupByIterator.forSingleKey(List.of(sumDocValuesAggregator), indexSearcher, new Reference(new ReferenceIdent(RelationName.fromIndexName("test"), "y"), RowGranularity.DOC, DataTypes.LONG, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 0, null), keyExpressions, RamAccounting.NO_ACCOUNTING, null, null, new MatchAllDocsQuery(), new CollectorContext());
    var rowConsumer = new TestingRowConsumer();
    rowConsumer.accept(it, null);
    assertThat(rowConsumer.getResult(), containsInAnyOrder(new Object[] { 0L, 6L }, new Object[] { 1L, 4L }));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) BytesRefColumnReference(io.crate.expression.reference.doc.lucene.BytesRefColumnReference) AtomicReference(java.util.concurrent.atomic.AtomicReference) LongColumnReference(io.crate.expression.reference.doc.lucene.LongColumnReference) Reference(io.crate.metadata.Reference) SumAggregation(io.crate.execution.engine.aggregation.impl.SumAggregation) LongColumnReference(io.crate.expression.reference.doc.lucene.LongColumnReference) CollectorContext(io.crate.expression.reference.doc.lucene.CollectorContext) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ReferenceIdent(io.crate.metadata.ReferenceIdent) TestingRowConsumer(io.crate.testing.TestingRowConsumer) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

Reference (io.crate.metadata.Reference)44 ReferenceIdent (io.crate.metadata.ReferenceIdent)44 Test (org.junit.Test)31 RelationName (io.crate.metadata.RelationName)21 ColumnIdent (io.crate.metadata.ColumnIdent)19 DynamicReference (io.crate.expression.symbol.DynamicReference)12 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)12 SymbolMatchers.isReference (io.crate.testing.SymbolMatchers.isReference)9 VoidReference (io.crate.expression.symbol.VoidReference)8 DocTableInfo (io.crate.metadata.doc.DocTableInfo)8 Symbol (io.crate.expression.symbol.Symbol)6 FetchReference (io.crate.expression.symbol.FetchReference)5 OrderBy (io.crate.analyze.OrderBy)4 RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)4 CollectorContext (io.crate.expression.reference.doc.lucene.CollectorContext)3 TestingRowConsumer (io.crate.testing.TestingRowConsumer)3 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)3 Before (org.junit.Before)3 Bucket (io.crate.data.Bucket)2 SumAggregation (io.crate.execution.engine.aggregation.impl.SumAggregation)2