Search in sources :

Example 11 with ReferenceIdent

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

the class TestingHelpers method refInfo.

public static Reference refInfo(String fqColumnName, DataType dataType, RowGranularity rowGranularity, String... nested) {
    String[] parts = fqColumnName.split("\\.");
    ReferenceIdent refIdent;
    List<String> nestedParts = null;
    if (nested.length > 0) {
        nestedParts = Arrays.asList(nested);
    }
    switch(parts.length) {
        case 2:
            refIdent = new ReferenceIdent(new RelationName(Schemas.DOC_SCHEMA_NAME, parts[0]), parts[1], nestedParts);
            break;
        case 3:
            refIdent = new ReferenceIdent(new RelationName(parts[0], parts[1]), parts[2], nestedParts);
            break;
        default:
            throw new IllegalArgumentException("fqColumnName must contain <table>.<column> or <schema>.<table>.<column>");
    }
    return new Reference(refIdent, rowGranularity, dataType, 0, null);
}
Also used : Reference(io.crate.metadata.Reference) RelationName(io.crate.metadata.RelationName) ReferenceIdent(io.crate.metadata.ReferenceIdent)

Example 12 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_many_keys.

@Test
public void test_group_by_doc_values_optimized_iterator_for_many_keys() 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 BytesRefColumnReference("x"), new LongColumnReference("y"));
    var keyRefs = List.of(new Reference(new ReferenceIdent(RelationName.fromIndexName("test"), "x"), RowGranularity.DOC, DataTypes.STRING, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 1, null), new Reference(new ReferenceIdent(RelationName.fromIndexName("test"), "y"), RowGranularity.DOC, DataTypes.LONG, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 2, null));
    var it = DocValuesGroupByOptimizedIterator.GroupByIterator.forManyKeys(List.of(sumDocValuesAggregator), indexSearcher, keyRefs, keyExpressions, RamAccounting.NO_ACCOUNTING, null, null, new MatchAllDocsQuery(), new CollectorContext());
    var rowConsumer = new TestingRowConsumer();
    rowConsumer.accept(it, null);
    assertThat(rowConsumer.getResult(), containsInAnyOrder(new Object[] { "0", 0L, 6L }, new Object[] { "1", 1L, 4L }));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) BytesRefColumnReference(io.crate.expression.reference.doc.lucene.BytesRefColumnReference) 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)

Example 13 with ReferenceIdent

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

the class SymbolPrinterTest method testDocReference.

@Test
public void testDocReference() throws Exception {
    Reference r = new Reference(new ReferenceIdent(new RelationName("doc", "table"), new ColumnIdent("column", Arrays.asList("path", "nested"))), RowGranularity.DOC, DataTypes.STRING, 0, null);
    assertPrint(r, "doc.\"table\".\"column\"['path']['nested']");
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) DynamicReference(io.crate.expression.symbol.DynamicReference) FetchReference(io.crate.expression.symbol.FetchReference) Reference(io.crate.metadata.Reference) SymbolMatchers.isReference(io.crate.testing.SymbolMatchers.isReference) VoidReference(io.crate.expression.symbol.VoidReference) RelationName(io.crate.metadata.RelationName) ReferenceIdent(io.crate.metadata.ReferenceIdent) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 14 with ReferenceIdent

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

the class InsertPlannerTest method testInsertFromQueryWithPartitionedColumn.

@Test
public void testInsertFromQueryWithPartitionedColumn() {
    Merge planNode = e.plan("insert into users (id, date) (select id, date from parted_pks)");
    Collect queryAndFetch = (Collect) planNode.subPlan();
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) queryAndFetch.collectPhase());
    List<Symbol> toCollect = collectPhase.toCollect();
    assertThat(toCollect.size(), is(2));
    assertThat(toCollect.get(0), isReference("_doc['id']"));
    assertThat(toCollect.get(1), equalTo(new Reference(new ReferenceIdent(new RelationName(Schemas.DOC_SCHEMA_NAME, "parted_pks"), "date"), RowGranularity.PARTITION, DataTypes.TIMESTAMPZ, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 3, null)));
}
Also used : Collect(io.crate.planner.node.dql.Collect) Symbol(io.crate.expression.symbol.Symbol) Reference(io.crate.metadata.Reference) SymbolMatchers.isReference(io.crate.testing.SymbolMatchers.isReference) RelationName(io.crate.metadata.RelationName) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) ReferenceIdent(io.crate.metadata.ReferenceIdent) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 15 with ReferenceIdent

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

the class ExpressionAnalyzerTest method testAnalyzeArraySliceFunctionCall.

@Test
public void testAnalyzeArraySliceFunctionCall() {
    ReferenceIdent arrayRefIdent = new ReferenceIdent(new RelationName("doc", "tarr"), "xs");
    Reference arrayRef = new Reference(arrayRefIdent, RowGranularity.DOC, DataTypes.INTEGER_ARRAY, ColumnPolicy.DYNAMIC, Reference.IndexType.PLAIN, true, true, 1, null);
    CoordinatorTxnCtx txnCtx = CoordinatorTxnCtx.systemTransactionContext();
    ExpressionAnalysisContext localContext = new ExpressionAnalysisContext(txnCtx.sessionContext());
    Symbol function = ExpressionAnalyzer.allocateFunction(ArraySliceFunction.NAME, List.of(arrayRef, Literal.of(1), Literal.of(3)), null, localContext, txnCtx, expressions.nodeCtx);
    var result = executor.asSymbol("tarr.xs[1:3]");
    assertThat(result, is(equalTo(function)));
}
Also used : CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) SymbolMatchers.isReference(io.crate.testing.SymbolMatchers.isReference) Reference(io.crate.metadata.Reference) ParameterSymbol(io.crate.expression.symbol.ParameterSymbol) ScopedSymbol(io.crate.expression.symbol.ScopedSymbol) Symbol(io.crate.expression.symbol.Symbol) RelationName(io.crate.metadata.RelationName) ReferenceIdent(io.crate.metadata.ReferenceIdent) 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