Search in sources :

Example 1 with ReferenceIdent

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

the class LuceneReferenceResolverTest method testGetImplementationWithColumnsOfTypeCollection.

@Test
public void testGetImplementationWithColumnsOfTypeCollection() {
    Reference arrayRef = new Reference(new ReferenceIdent(new TableIdent("s", "t"), "a"), RowGranularity.DOC, DataTypes.DOUBLE_ARRAY);
    assertThat(luceneReferenceResolver.getImplementation(arrayRef), instanceOf(DocCollectorExpression.ChildDocCollectorExpression.class));
    Reference setRef = new Reference(new ReferenceIdent(new TableIdent("s", "t"), "a"), RowGranularity.DOC, new SetType(DataTypes.DOUBLE));
    assertThat(luceneReferenceResolver.getImplementation(setRef), instanceOf(DocCollectorExpression.ChildDocCollectorExpression.class));
}
Also used : SetType(io.crate.types.SetType) Reference(io.crate.metadata.Reference) TableIdent(io.crate.metadata.TableIdent) ReferenceIdent(io.crate.metadata.ReferenceIdent) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with ReferenceIdent

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

the class OrderedLuceneBatchIteratorBenchmark method createLuceneBatchIterator.

@Setup
public void createLuceneBatchIterator() throws Exception {
    IndexWriter iw = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(new StandardAnalyzer()));
    dummyShardId = new ShardId("dummy", 1);
    columnName = "x";
    for (int i = 0; i < 10_000_000; i++) {
        Document doc = new Document();
        doc.add(new NumericDocValuesField(columnName, i));
        iw.addDocument(doc);
    }
    iw.commit();
    iw.forceMerge(1, true);
    indexSearcher = new IndexSearcher(DirectoryReader.open(iw, true));
    collectorContext = new CollectorContext(mock(IndexFieldDataService.class), new CollectorFieldsVisitor(0));
    fieldTypeLookup = column -> {
        IntegerFieldMapper.IntegerFieldType integerFieldType = new IntegerFieldMapper.IntegerFieldType();
        integerFieldType.setNames(new MappedFieldType.Names(column));
        return integerFieldType;
    };
    reference = new Reference(new ReferenceIdent(new TableIdent(null, "dummyTable"), columnName), RowGranularity.DOC, DataTypes.INTEGER);
    orderBy = new OrderBy(Collections.singletonList(reference), reverseFlags, nullsFirst);
}
Also used : OrderBy(io.crate.analyze.OrderBy) Reference(io.crate.metadata.Reference) TableIdent(io.crate.metadata.TableIdent) Document(org.apache.lucene.document.Document) IntegerFieldMapper(org.elasticsearch.index.mapper.core.IntegerFieldMapper) RAMDirectory(org.apache.lucene.store.RAMDirectory) ReferenceIdent(io.crate.metadata.ReferenceIdent) ShardId(org.elasticsearch.index.shard.ShardId) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) IndexWriter(org.apache.lucene.index.IndexWriter) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) CollectorContext(io.crate.operation.reference.doc.lucene.CollectorContext) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 3 with ReferenceIdent

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

the class NodeStatsIteratorTest method prepare.

@Before
public void prepare() {
    idRef = new Reference(new ReferenceIdent(SysNodesTableInfo.IDENT, SysNodesTableInfo.Columns.ID), RowGranularity.DOC, DataTypes.STRING);
    nameRef = new Reference(new ReferenceIdent(SysNodesTableInfo.IDENT, SysNodesTableInfo.Columns.ID), RowGranularity.DOC, DataTypes.STRING);
    hostnameRef = new Reference(new ReferenceIdent(SysNodesTableInfo.IDENT, SysNodesTableInfo.Columns.HOSTNAME), RowGranularity.DOC, DataTypes.STRING);
    collectPhase = mock(RoutedCollectPhase.class);
    when(collectPhase.whereClause()).thenReturn(WhereClause.NO_MATCH);
    nodes.add(newNode("nodeOne"));
    nodes.add(newNode("nodeTwo"));
}
Also used : Reference(io.crate.metadata.Reference) ReferenceIdent(io.crate.metadata.ReferenceIdent) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Before(org.junit.Before)

Example 4 with ReferenceIdent

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

the class AnalyzedTableElements method buildReference.

private static <T> void buildReference(RelationName relationName, AnalyzedColumnDefinition<T> columnDefinition, List<Reference> references) {
    Reference reference;
    DataType<?> type = columnDefinition.dataType() == null ? DataTypes.UNDEFINED : columnDefinition.dataType();
    DataType<?> realType = ArrayType.NAME.equals(columnDefinition.collectionType()) ? new ArrayType<>(type) : type;
    if (columnDefinition.isGenerated() == false) {
        reference = new Reference(new ReferenceIdent(relationName, columnDefinition.ident()), RowGranularity.DOC, realType, columnDefinition.position, // not required in this context
        null);
    } else {
        reference = new GeneratedReference(columnDefinition.position, new ReferenceIdent(relationName, columnDefinition.ident()), RowGranularity.DOC, realType, "dummy expression, real one not needed here");
    }
    references.add(reference);
    for (AnalyzedColumnDefinition<T> childDefinition : columnDefinition.children()) {
        buildReference(relationName, childDefinition, references);
    }
}
Also used : GeneratedReference(io.crate.metadata.GeneratedReference) GeneratedReference(io.crate.metadata.GeneratedReference) Reference(io.crate.metadata.Reference) ReferenceIdent(io.crate.metadata.ReferenceIdent)

Example 5 with ReferenceIdent

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

the class InternalViewInfoFactory method create.

@Override
public ViewInfo create(RelationName ident, ClusterState state) {
    ViewsMetadata meta = state.metadata().custom(ViewsMetadata.TYPE);
    if (meta == null) {
        return null;
    }
    ViewMetadata view = meta.getView(ident);
    if (view == null) {
        return null;
    }
    List<Reference> columns;
    try {
        AnalyzedRelation relation = analyzerProvider.get().analyze((Query) SqlParser.createStatement(view.stmt()), CoordinatorTxnCtx.systemTransactionContext(), ParamTypeHints.EMPTY);
        final List<Reference> collectedColumns = new ArrayList<>(relation.outputs().size());
        int position = 1;
        for (var field : relation.outputs()) {
            collectedColumns.add(new Reference(new ReferenceIdent(ident, Symbols.pathFromSymbol(field).sqlFqn()), RowGranularity.DOC, field.valueType(), position++, null));
        }
        columns = collectedColumns;
    } catch (Exception e) {
        if (e instanceof ResourceUnknownException) {
            // Return ViewInfo with no columns in case the statement could not be analyzed,
            // because the underlying table of the view could not be found.
            columns = Collections.emptyList();
        } else {
            throw e;
        }
    }
    return new ViewInfo(ident, view.stmt(), columns, view.owner());
}
Also used : Reference(io.crate.metadata.Reference) ArrayList(java.util.ArrayList) ResourceUnknownException(io.crate.exceptions.ResourceUnknownException) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) ResourceUnknownException(io.crate.exceptions.ResourceUnknownException) ReferenceIdent(io.crate.metadata.ReferenceIdent)

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