use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class CountAggregationTest method helper_count_on_object_with_not_null_immediate_child.
private void helper_count_on_object_with_not_null_immediate_child(DataType<?> childType, Class<?> expectedAggregatorClass) {
Reference notNullImmediateChild = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_object", "not_null_subcol")), RowGranularity.DOC, childType, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 0, null);
Reference countedObject = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_object")), RowGranularity.DOC, ObjectType.builder().setInnerType(notNullImmediateChild.column().leafName(), notNullImmediateChild.valueType()).build(), ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 0, null);
DocTableInfo sourceTable = mock(DocTableInfo.class);
when(sourceTable.notNullColumns()).thenReturn(List.of(notNullImmediateChild.column()));
when(sourceTable.getReference(eq(notNullImmediateChild.column()))).thenReturn(notNullImmediateChild);
assertHasDocValueAggregator(List.of(countedObject), sourceTable, expectedAggregatorClass);
verify(sourceTable, times(1)).notNullColumns();
verify(sourceTable, times(1)).getReference(eq(notNullImmediateChild.column()));
}
use of io.crate.metadata.doc.DocTableInfo 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);
}
use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class FetchRewriteTest method test_fetchrewrite_on_eval_with_nested_source_outputs.
@Test
public void test_fetchrewrite_on_eval_with_nested_source_outputs() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table tbl (x int)").build();
DocTableInfo tableInfo = e.resolveTableInfo("tbl");
var x = new AliasSymbol("x_alias", e.asSymbol("x"));
var relation = new DocTableRelation(tableInfo);
var collect = new Collect(relation, List.of(x), WhereClause.MATCH_ALL, 1L, DataTypes.INTEGER.fixedSize());
var eval = new Eval(collect, List.of(x));
FetchRewrite fetchRewrite = eval.rewriteToFetch(new TableStats(), List.of());
assertThat(fetchRewrite, Matchers.notNullValue());
assertThat(fetchRewrite.newPlan(), isPlan("Collect[doc.tbl | [_fetchid] | true]"));
assertThat(fetchRewrite.replacedOutputs(), Matchers.hasEntry(is(x), isAlias("x_alias", isFetchStub("_doc['x']"))));
}
use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class FetchRewriteTest method test_fetch_rewrite_on_eval_removes_eval_and_extends_replaced_outputs.
@Test
public void test_fetch_rewrite_on_eval_removes_eval_and_extends_replaced_outputs() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table tbl (x int)").build();
DocTableInfo tableInfo = e.resolveTableInfo("tbl");
var x = e.asSymbol("x");
var relation = new DocTableRelation(tableInfo);
var collect = new Collect(relation, List.of(x), WhereClause.MATCH_ALL, 1L, DataTypes.INTEGER.fixedSize());
var eval = new Eval(collect, List.of(new Function(Signature.scalar("add", DataTypes.INTEGER.getTypeSignature(), DataTypes.INTEGER.getTypeSignature(), DataTypes.INTEGER.getTypeSignature()), List.of(x, x), DataTypes.INTEGER)));
FetchRewrite fetchRewrite = eval.rewriteToFetch(new TableStats(), List.of());
assertThat(fetchRewrite, Matchers.notNullValue());
assertThat(fetchRewrite.newPlan(), isPlan("Collect[doc.tbl | [_fetchid] | true]"));
assertThat(fetchRewrite.replacedOutputs(), Matchers.hasEntry(isFunction("add", isReference("x"), isReference("x")), isFunction("add", isFetchStub("_doc['x']"), isFetchStub("_doc['x']"))));
assertThat(List.copyOf(fetchRewrite.replacedOutputs().keySet()), is(eval.outputs()));
}
use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class AbstractWindowFunctionTest method prepareFunctions.
@Before
public void prepareFunctions() {
DocTableInfo tableInfo = SQLExecutor.tableInfo(new RelationName("doc", "t1"), "create table doc.t1 (x int, y bigint, z string, d double)", clusterService);
DocTableRelation tableRelation = new DocTableRelation(tableInfo);
Map<RelationName, AnalyzedRelation> tableSources = Map.of(tableInfo.ident(), tableRelation);
memoryManager = new OnHeapMemoryManager(bytes -> {
});
sqlExpressions = new SqlExpressions(tableSources, tableRelation, User.CRATE_USER, additionalModules);
inputFactory = new InputFactory(sqlExpressions.nodeCtx);
}
Aggregations