Search in sources :

Example 1 with DocSchemaInfo

use of io.crate.metadata.doc.DocSchemaInfo in project crate by crate.

the class SelectStatementAnalyzerTest method init.

@Before
public void init() throws Exception {
    DocTableInfo fooUserTableInfo = TestingTableInfo.builder(new TableIdent("foo", "users"), SHARD_ROUTING).add("id", DataTypes.LONG, null).add("name", DataTypes.STRING, null).addPrimaryKey("id").build();
    DocTableInfoFactory fooTableFactory = new TestingDocTableInfoFactory(ImmutableMap.of(fooUserTableInfo.ident(), fooUserTableInfo));
    ClusterService clusterService = new NoopClusterService();
    sqlExecutor = SQLExecutor.builder(clusterService).enableDefaultTables().addSchema(new DocSchemaInfo("foo", clusterService, fooTableFactory)).build();
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) DocSchemaInfo(io.crate.metadata.doc.DocSchemaInfo) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ClusterService(org.elasticsearch.cluster.ClusterService) TestingDocTableInfoFactory(io.crate.metadata.doc.TestingDocTableInfoFactory) TableIdent(io.crate.metadata.TableIdent) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) DocTableInfoFactory(io.crate.metadata.doc.DocTableInfoFactory) TestingDocTableInfoFactory(io.crate.metadata.doc.TestingDocTableInfoFactory) Before(org.junit.Before)

Example 2 with DocSchemaInfo

use of io.crate.metadata.doc.DocSchemaInfo in project crate by crate.

the class TransportAnalyzeAction method fetchSamplesThenGenerateAndPublishStats.

@SuppressWarnings("unchecked")
public CompletableFuture<AcknowledgedResponse> fetchSamplesThenGenerateAndPublishStats() {
    ArrayList<CompletableFuture<Map.Entry<RelationName, Stats>>> futures = new ArrayList<>();
    for (SchemaInfo schema : schemas) {
        if (!(schema instanceof DocSchemaInfo)) {
            continue;
        }
        for (TableInfo table : schema.getTables()) {
            List<Reference> primitiveColumns = StreamSupport.stream(table.spliterator(), false).filter(x -> !x.column().isSystemColumn()).filter(x -> DataTypes.isPrimitive(x.valueType())).map(x -> table.getReadReference(x.column())).collect(Collectors.toList());
            futures.add(fetchSamples(table.ident(), primitiveColumns).thenApply(samples -> Map.entry(table.ident(), createTableStats(samples, primitiveColumns))));
        }
    }
    return CompletableFutures.allAsList(futures).thenCompose(entries -> publishTableStats(Map.ofEntries(entries.toArray(new Map.Entry[0]))));
}
Also used : Arrays(java.util.Arrays) RelationName(io.crate.metadata.RelationName) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ClusterService(org.elasticsearch.cluster.service.ClusterService) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Inject(org.elasticsearch.common.inject.Inject) ArrayList(java.util.ArrayList) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ActionListenerResponseHandler(org.elasticsearch.action.ActionListenerResponseHandler) Symbols(io.crate.expression.symbol.Symbols) Map(java.util.Map) ThreadPool(org.elasticsearch.threadpool.ThreadPool) StreamSupport(java.util.stream.StreamSupport) TransportService(org.elasticsearch.transport.TransportService) FutureActionListener(io.crate.action.FutureActionListener) SchemaInfo(io.crate.metadata.table.SchemaInfo) TableInfo(io.crate.metadata.table.TableInfo) Streamer(io.crate.Streamer) NodeActionRequestHandler(io.crate.execution.support.NodeActionRequestHandler) ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference) DataType(io.crate.types.DataType) CompletableFutures(io.crate.concurrent.CompletableFutures) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) Collectors(java.util.stream.Collectors) MultiActionListener(io.crate.execution.support.MultiActionListener) List(java.util.List) Version(org.elasticsearch.Version) Row(io.crate.data.Row) AnalyzeRequest(io.crate.execution.ddl.AnalyzeRequest) DocSchemaInfo(io.crate.metadata.doc.DocSchemaInfo) DataTypes(io.crate.types.DataTypes) Singleton(org.elasticsearch.common.inject.Singleton) Schemas(io.crate.metadata.Schemas) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) Reference(io.crate.metadata.Reference) ArrayList(java.util.ArrayList) CompletableFuture(java.util.concurrent.CompletableFuture) DocSchemaInfo(io.crate.metadata.doc.DocSchemaInfo) RelationName(io.crate.metadata.RelationName) TableInfo(io.crate.metadata.table.TableInfo) HashMap(java.util.HashMap) Map(java.util.Map) SchemaInfo(io.crate.metadata.table.SchemaInfo) DocSchemaInfo(io.crate.metadata.doc.DocSchemaInfo)

Example 3 with DocSchemaInfo

use of io.crate.metadata.doc.DocSchemaInfo in project crate by crate.

the class DocLevelExpressionsTest method prepare.

@Before
public void prepare() throws Exception {
    SQLExecutor e = SQLExecutor.builder(clusterService).addTable(createTableStatement).build();
    indexEnv = new IndexEnv(THREAD_POOL, (DocTableInfo) StreamSupport.stream(e.schemas().spliterator(), false).filter(x -> x instanceof DocSchemaInfo).map(x -> (DocSchemaInfo) x).findFirst().orElseThrow(() -> new IllegalStateException("No doc schema found")).getTables().iterator().next(), clusterService.state(), Version.CURRENT, createTempDir());
    IndexWriter writer = indexEnv.writer();
    insertValues(writer);
    DirectoryReader directoryReader = DirectoryReader.open(writer, true, true);
    readerContext = directoryReader.leaves().get(0);
    ctx = new CollectorContext();
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) CollectorContext(io.crate.expression.reference.doc.lucene.CollectorContext) IndexEnv(io.crate.testing.IndexEnv) DirectoryReader(org.apache.lucene.index.DirectoryReader) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) IndexWriter(org.apache.lucene.index.IndexWriter) Version(org.elasticsearch.Version) DocSchemaInfo(io.crate.metadata.doc.DocSchemaInfo) After(org.junit.After) StreamSupport(java.util.stream.StreamSupport) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) SQLExecutor(io.crate.testing.SQLExecutor) Before(org.junit.Before) DocTableInfo(io.crate.metadata.doc.DocTableInfo) DocSchemaInfo(io.crate.metadata.doc.DocSchemaInfo) SQLExecutor(io.crate.testing.SQLExecutor) IndexEnv(io.crate.testing.IndexEnv) IndexWriter(org.apache.lucene.index.IndexWriter) DirectoryReader(org.apache.lucene.index.DirectoryReader) CollectorContext(io.crate.expression.reference.doc.lucene.CollectorContext) Before(org.junit.Before)

Aggregations

DocSchemaInfo (io.crate.metadata.doc.DocSchemaInfo)3 DocTableInfo (io.crate.metadata.doc.DocTableInfo)2 StreamSupport (java.util.stream.StreamSupport)2 Version (org.elasticsearch.Version)2 Before (org.junit.Before)2 Streamer (io.crate.Streamer)1 FutureActionListener (io.crate.action.FutureActionListener)1 VisibleForTesting (io.crate.common.annotations.VisibleForTesting)1 CompletableFutures (io.crate.concurrent.CompletableFutures)1 Row (io.crate.data.Row)1 AnalyzeRequest (io.crate.execution.ddl.AnalyzeRequest)1 MultiActionListener (io.crate.execution.support.MultiActionListener)1 NodeActionRequestHandler (io.crate.execution.support.NodeActionRequestHandler)1 CollectorContext (io.crate.expression.reference.doc.lucene.CollectorContext)1 Symbols (io.crate.expression.symbol.Symbols)1 ColumnIdent (io.crate.metadata.ColumnIdent)1 Reference (io.crate.metadata.Reference)1 RelationName (io.crate.metadata.RelationName)1 Schemas (io.crate.metadata.Schemas)1 TableIdent (io.crate.metadata.TableIdent)1