use of io.crate.metadata.RelationName 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.RelationName in project crate by crate.
the class UpdateSourceGenTest method testSetXBasedOnXAndPartitionedColumn.
@Test
public void testSetXBasedOnXAndPartitionedColumn() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addPartitionedTable("create table t (x int, p int) partitioned by (p)", new PartitionName(new RelationName("doc", "t"), Collections.singletonList("1")).asIndexName()).build();
AnalyzedUpdateStatement update = e.analyze("update t set x = x + p");
Assignments assignments = Assignments.convert(update.assignmentByTargetCol(), e.nodeCtx);
DocTableInfo table = (DocTableInfo) update.table().tableInfo();
UpdateSourceGen updateSourceGen = new UpdateSourceGen(txnCtx, e.nodeCtx, table, assignments.targetNames());
Map<String, Object> source = singletonMap("x", 1);
Map<String, Object> updatedSource = updateSourceGen.generateSource(new Doc(1, table.concreteIndices()[0], "1", 1, 1, 1, source, () -> {
try {
return Strings.toString(XContentFactory.jsonBuilder().map(source));
} catch (IOException e1) {
throw new RuntimeException(e1);
}
}), assignments.sources(), new Object[0]);
assertThat(updatedSource, is(Map.of("x", 2)));
}
use of io.crate.metadata.RelationName in project crate by crate.
the class InputColumnsTest method prepare.
@Before
public void prepare() throws Exception {
Map<RelationName, AnalyzedRelation> sources = T3.sources(List.of(T3.T1), clusterService);
DocTableRelation tr1 = (DocTableRelation) sources.get(T3.T1);
sqlExpressions = new SqlExpressions(sources, tr1);
}
use of io.crate.metadata.RelationName in project crate by crate.
the class SubSelectIntegrationTest method testSingleRowSubSelectWorksWithJoins.
@Test
public void testSingleRowSubSelectWorksWithJoins() throws Exception {
execute("create table t (x long primary key)");
ensureYellow();
execute("insert into t (x) values (1), (2)");
execute("refresh table t");
for (TableStats tableStats : internalCluster().getInstances(TableStats.class)) {
Map<RelationName, Stats> newStats = new HashMap<>();
newStats.put(new RelationName(sqlExecutor.getCurrentSchema(), "t"), new Stats(100, 64, Map.of()));
tableStats.updateTableStats(newStats);
}
// Left table is expected to be one row, due to the single row subselect in the where clause.
execute("select * from t as t1, t as t2 where t1.x = (select 1) order by t2.x");
assertThat(printedTable(response.rows()), is("1| 1\n1| 2\n"));
// Left table is expected to be bigger due to the table stats stating it being 100 rows
execute("select * from t as t2, t as t1 where t1.x = (select 1) order by t2.x");
assertThat(printedTable(response.rows()), is("1| 1\n2| 1\n"));
}
use of io.crate.metadata.RelationName in project crate by crate.
the class SQLExecutor method asSymbol.
/**
* Convert a expression to a symbol
* If tables are used here they must also be registered in the SQLExecutor having used {@link Builder#addTable(String)}
*/
public Symbol asSymbol(String expression) {
MapBuilder<RelationName, AnalyzedRelation> sources = MapBuilder.newMapBuilder();
for (SchemaInfo schemaInfo : schemas) {
for (TableInfo tableInfo : schemaInfo.getTables()) {
if (tableInfo instanceof DocTableInfo) {
RelationName relationName = tableInfo.ident();
sources.put(relationName, new DocTableRelation(schemas.getTableInfo(relationName)));
}
}
}
CoordinatorTxnCtx coordinatorTxnCtx = new CoordinatorTxnCtx(sessionContext);
ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(coordinatorTxnCtx, nodeCtx, ParamTypeHints.EMPTY, new FullQualifiedNameFieldProvider(sources.immutableMap(), ParentRelations.NO_PARENTS, sessionContext.searchPath().currentSchema()), new SubqueryAnalyzer(relAnalyzer, new StatementAnalysisContext(ParamTypeHints.EMPTY, Operation.READ, coordinatorTxnCtx)));
ExpressionAnalysisContext expressionAnalysisContext = new ExpressionAnalysisContext(coordinatorTxnCtx.sessionContext());
return expressionAnalyzer.convert(SqlParser.createExpression(expression), expressionAnalysisContext);
}
Aggregations