Search in sources :

Example 36 with ReferenceIdent

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

the class TransportAnalyzeActionTest method test_create_stats_for_tables_with_array_columns_with_nulls.

@Test
public void test_create_stats_for_tables_with_array_columns_with_nulls() {
    var rows = new ArrayList<String>();
    rows.add(null);
    var samples = new Samples(List.of(new Row1(rows), new Row1(rows)), List.of(DataTypes.STRING_ARRAY.streamer()), 2, SizeEstimatorFactory.create(DataTypes.STRING_ARRAY).estimateSize(rows));
    var references = List.of(new Reference(new ReferenceIdent(new RelationName(Schemas.DOC_SCHEMA_NAME, "dummy"), "dummy"), RowGranularity.DOC, DataTypes.STRING_ARRAY, 0, null));
    var stats = TransportAnalyzeAction.createTableStats(samples, references);
    assertThat(stats.numDocs, is(2L));
}
Also used : Row1(io.crate.data.Row1) Reference(io.crate.metadata.Reference) ArrayList(java.util.ArrayList) RelationName(io.crate.metadata.RelationName) ReferenceIdent(io.crate.metadata.ReferenceIdent) Test(org.junit.Test)

Example 37 with ReferenceIdent

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

the class DocTableInfo method getDynamic.

@Nullable
public DynamicReference getDynamic(ColumnIdent ident, boolean forWrite, boolean errorOnUnknownObjectKey) {
    boolean parentIsIgnored = false;
    ColumnPolicy parentPolicy = columnPolicy();
    int position = 0;
    if (!ident.isTopLevel()) {
        // see if parent is strict object
        ColumnIdent parentIdent = ident.getParent();
        Reference parentInfo = null;
        while (parentIdent != null) {
            parentInfo = getReference(parentIdent);
            if (parentInfo != null) {
                break;
            }
            parentIdent = parentIdent.getParent();
        }
        if (parentInfo != null) {
            parentPolicy = parentInfo.columnPolicy();
            position = parentInfo.position();
        }
    }
    switch(parentPolicy) {
        case DYNAMIC:
            if (!forWrite) {
                if (!errorOnUnknownObjectKey) {
                    return new VoidReference(new ReferenceIdent(ident(), ident), rowGranularity(), position);
                }
                return null;
            }
            break;
        case STRICT:
            if (forWrite) {
                throw new ColumnUnknownException(ident.sqlFqn(), ident());
            }
            return null;
        case IGNORED:
            parentIsIgnored = true;
            break;
        default:
            break;
    }
    if (parentIsIgnored) {
        return new DynamicReference(new ReferenceIdent(ident(), ident), rowGranularity(), ColumnPolicy.IGNORED, position);
    }
    return new DynamicReference(new ReferenceIdent(ident(), ident), rowGranularity(), position);
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) ColumnPolicy(io.crate.sql.tree.ColumnPolicy) VoidReference(io.crate.expression.symbol.VoidReference) ColumnUnknownException(io.crate.exceptions.ColumnUnknownException) IndexReference(io.crate.metadata.IndexReference) DynamicReference(io.crate.expression.symbol.DynamicReference) GeneratedReference(io.crate.metadata.GeneratedReference) Reference(io.crate.metadata.Reference) VoidReference(io.crate.expression.symbol.VoidReference) DynamicReference(io.crate.expression.symbol.DynamicReference) CheckConstraint(io.crate.sql.tree.CheckConstraint) ReferenceIdent(io.crate.metadata.ReferenceIdent) Nullable(javax.annotation.Nullable)

Example 38 with ReferenceIdent

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

the class ValueNormalizerTest method testNormalizePrimitiveLiteral.

@Test
public void testNormalizePrimitiveLiteral() throws Exception {
    Reference ref = new Reference(new ReferenceIdent(TEST_TABLE_IDENT, new ColumnIdent("bool")), RowGranularity.DOC, DataTypes.BOOLEAN, 0, null);
    Literal<Boolean> trueLiteral = Literal.of(true);
    assertThat(normalizeInputForReference(trueLiteral, ref), Matchers.<Symbol>is(trueLiteral));
    assertThat(normalizeInputForReference(Literal.of("true"), ref), Matchers.<Symbol>is(trueLiteral));
    assertThat(normalizeInputForReference(Literal.of("false"), ref), Matchers.<Symbol>is(Literal.of(false)));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference) ReferenceIdent(io.crate.metadata.ReferenceIdent) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 39 with ReferenceIdent

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

the class IndexWriterProjectorTest method testIndexWriter.

@Test
public void testIndexWriter() throws Throwable {
    execute("create table bulk_import (id int primary key, name string) with (number_of_replicas=0)");
    ensureGreen();
    InputCollectExpression sourceInput = new InputCollectExpression(1);
    List<CollectExpression<Row, ?>> collectExpressions = Collections.<CollectExpression<Row, ?>>singletonList(sourceInput);
    RelationName bulkImportIdent = new RelationName(sqlExecutor.getCurrentSchema(), "bulk_import");
    ClusterState state = clusterService().state();
    Settings tableSettings = TableSettingsResolver.get(state.getMetadata(), bulkImportIdent, false);
    ThreadPool threadPool = internalCluster().getInstance(ThreadPool.class);
    IndexWriterProjector writerProjector = new IndexWriterProjector(clusterService(), new NodeLimits(new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)), new NoopCircuitBreaker("dummy"), RamAccounting.NO_ACCOUNTING, threadPool.scheduler(), threadPool.executor(ThreadPool.Names.SEARCH), CoordinatorTxnCtx.systemTransactionContext(), new NodeContext(internalCluster().getInstance(Functions.class)), Settings.EMPTY, IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.get(tableSettings), NumberOfReplicas.fromSettings(tableSettings, state.getNodes().getSize()), internalCluster().getInstance(TransportCreatePartitionsAction.class), internalCluster().getInstance(TransportShardUpsertAction.class)::execute, IndexNameResolver.forTable(bulkImportIdent), new Reference(new ReferenceIdent(bulkImportIdent, DocSysColumns.RAW), RowGranularity.DOC, DataTypes.STRING, 0, null), Collections.singletonList(ID_IDENT), Collections.<Symbol>singletonList(new InputColumn(0)), null, null, sourceInput, collectExpressions, 20, null, null, false, false, UUID.randomUUID(), UpsertResultContext.forRowCount(), false);
    BatchIterator rowsIterator = InMemoryBatchIterator.of(IntStream.range(0, 100).mapToObj(i -> new RowN(new Object[] { i, "{\"id\": " + i + ", \"name\": \"Arthur\"}" })).collect(Collectors.toList()), SENTINEL, true);
    TestingRowConsumer consumer = new TestingRowConsumer();
    consumer.accept(writerProjector.apply(rowsIterator), null);
    Bucket objects = consumer.getBucket();
    assertThat(objects, contains(isRow(100L)));
    execute("refresh table bulk_import");
    execute("select count(*) from bulk_import");
    assertThat(response.rowCount(), is(1L));
    assertThat(response.rows()[0][0], is(100L));
}
Also used : TransportCreatePartitionsAction(org.elasticsearch.action.admin.indices.create.TransportCreatePartitionsAction) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) NodeContext(io.crate.metadata.NodeContext) Reference(io.crate.metadata.Reference) ThreadPool(org.elasticsearch.threadpool.ThreadPool) BatchIterator(io.crate.data.BatchIterator) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) CollectExpression(io.crate.execution.engine.collect.CollectExpression) InputCollectExpression(io.crate.execution.engine.collect.InputCollectExpression) ReferenceIdent(io.crate.metadata.ReferenceIdent) RowN(io.crate.data.RowN) InputCollectExpression(io.crate.execution.engine.collect.InputCollectExpression) Bucket(io.crate.data.Bucket) InputColumn(io.crate.expression.symbol.InputColumn) NodeLimits(io.crate.execution.jobs.NodeLimits) RelationName(io.crate.metadata.RelationName) NoopCircuitBreaker(org.elasticsearch.common.breaker.NoopCircuitBreaker) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Example 40 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 ByteBuffersDirectory(), new IndexWriterConfig(new StandardAnalyzer()));
    dummyShardId = new ShardId("dummy", UUIDs.randomBase64UUID(), 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, true));
    collectorContext = new CollectorContext();
    reference = new Reference(new ReferenceIdent(new RelationName(Schemas.DOC_SCHEMA_NAME, "dummyTable"), columnName), RowGranularity.DOC, DataTypes.INTEGER, 1, null);
    orderBy = new OrderBy(Collections.singletonList(reference), reverseFlags, nullsFirst);
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) OrderBy(io.crate.analyze.OrderBy) Reference(io.crate.metadata.Reference) Document(org.apache.lucene.document.Document) ReferenceIdent(io.crate.metadata.ReferenceIdent) ShardId(org.elasticsearch.index.shard.ShardId) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) IndexWriter(org.apache.lucene.index.IndexWriter) ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) RelationName(io.crate.metadata.RelationName) CollectorContext(io.crate.expression.reference.doc.lucene.CollectorContext) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Setup(org.openjdk.jmh.annotations.Setup)

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