use of io.crate.metadata.Schemas in project crate by crate.
the class CreateTablePlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
BoundCreateTable boundCreateTable = bind(createTable, plannerContext.transactionContext(), dependencies.nodeContext(), params, subQueryResults, numberOfShards, schemas, dependencies.fulltextAnalyzerResolver());
if (boundCreateTable.noOp()) {
consumer.accept(InMemoryBatchIterator.empty(SENTINEL), null);
return;
}
tableCreator.create(boundCreateTable).whenComplete(new OneRowActionListener<>(consumer, rCount -> new Row1(rCount == null ? -1 : rCount)));
}
use of io.crate.metadata.Schemas 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]))));
}
use of io.crate.metadata.Schemas in project crate by crate.
the class SQLIntegrationTestCase method waitForMappingUpdateOnAll.
public void waitForMappingUpdateOnAll(final RelationName relationName, final String... fieldNames) throws Exception {
assertBusy(() -> {
Iterable<Schemas> referenceInfosIterable = internalCluster().getInstances(Schemas.class);
for (Schemas schemas : referenceInfosIterable) {
TableInfo tableInfo = schemas.getTableInfo(relationName);
assertThat(tableInfo, Matchers.notNullValue());
for (String fieldName : fieldNames) {
ColumnIdent columnIdent = ColumnIdent.fromPath(fieldName);
assertThat(tableInfo.getReference(columnIdent), Matchers.notNullValue());
}
}
}, 20L, TimeUnit.SECONDS);
}
use of io.crate.metadata.Schemas in project crate by crate.
the class SysShardsExpressionsTest method prepare.
@Before
public void prepare() {
NodeContext nodeCtx = createNodeContext();
indexShard = mockIndexShard();
CrateSettings crateSettings = new CrateSettings(clusterService, clusterService.getSettings());
UserDefinedFunctionService udfService = new UserDefinedFunctionService(clusterService, nodeCtx);
schemas = new Schemas(Map.of("sys", new SysSchemaInfo(this.clusterService, crateSettings)), clusterService, new DocSchemaInfoFactory(new TestingDocTableInfoFactory(Collections.emptyMap()), (ident, state) -> null, nodeCtx, udfService));
resolver = new ShardReferenceResolver(schemas, new ShardRowContext(indexShard, clusterService));
sysShards = schemas.getTableInfo(SysShardsTableInfo.IDENT);
}
use of io.crate.metadata.Schemas in project crate by crate.
the class InternalCountOperationTest method testCount.
@Test
public void testCount() throws Exception {
execute("create table t (name string) clustered into 1 shards with (number_of_replicas = 0)");
ensureYellow();
execute("insert into t (name) values ('Marvin'), ('Arthur'), ('Trillian')");
execute("refresh table t");
CountOperation countOperation = internalCluster().getDataNodeInstance(CountOperation.class);
assertThat(countOperation.count("t", 0, WhereClause.MATCH_ALL), is(3L));
Schemas schemas = internalCluster().getInstance(Schemas.class);
TableInfo tableInfo = schemas.getTableInfo(new TableIdent(null, "t"));
TableRelation tableRelation = new TableRelation(tableInfo);
Map<QualifiedName, AnalyzedRelation> tableSources = ImmutableMap.<QualifiedName, AnalyzedRelation>of(new QualifiedName(tableInfo.ident().name()), tableRelation);
SqlExpressions sqlExpressions = new SqlExpressions(tableSources, tableRelation);
WhereClause whereClause = new WhereClause(sqlExpressions.normalize(sqlExpressions.asSymbol("name = 'Marvin'")));
assertThat(countOperation.count("t", 0, whereClause), is(1L));
}
Aggregations