Search in sources :

Example 51 with DocTableInfo

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()));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) DocTableInfo(io.crate.metadata.doc.DocTableInfo) Reference(io.crate.metadata.Reference) ReferenceIdent(io.crate.metadata.ReferenceIdent)

Example 52 with DocTableInfo

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);
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) ExpressionAnalysisContext(io.crate.analyze.expressions.ExpressionAnalysisContext) ExpressionAnalyzer(io.crate.analyze.expressions.ExpressionAnalyzer) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) StatementAnalysisContext(io.crate.analyze.relations.StatementAnalysisContext) RelationName(io.crate.metadata.RelationName) DocTableRelation(io.crate.analyze.relations.DocTableRelation) TableInfo(io.crate.metadata.table.TableInfo) DocTableInfo(io.crate.metadata.doc.DocTableInfo) SubqueryAnalyzer(io.crate.analyze.expressions.SubqueryAnalyzer) PgCatalogSchemaInfo(io.crate.metadata.pgcatalog.PgCatalogSchemaInfo) SysSchemaInfo(io.crate.metadata.sys.SysSchemaInfo) BlobSchemaInfo(io.crate.metadata.blob.BlobSchemaInfo) InformationSchemaInfo(io.crate.metadata.information.InformationSchemaInfo) SchemaInfo(io.crate.metadata.table.SchemaInfo) FullQualifiedNameFieldProvider(io.crate.analyze.relations.FullQualifiedNameFieldProvider)

Example 53 with DocTableInfo

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']"))));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) AliasSymbol(io.crate.expression.symbol.AliasSymbol) SQLExecutor(io.crate.testing.SQLExecutor) DocTableRelation(io.crate.analyze.relations.DocTableRelation) TableStats(io.crate.statistics.TableStats) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 54 with DocTableInfo

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()));
}
Also used : SymbolMatchers.isFunction(io.crate.testing.SymbolMatchers.isFunction) Function(io.crate.expression.symbol.Function) DocTableInfo(io.crate.metadata.doc.DocTableInfo) SQLExecutor(io.crate.testing.SQLExecutor) DocTableRelation(io.crate.analyze.relations.DocTableRelation) TableStats(io.crate.statistics.TableStats) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 55 with DocTableInfo

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);
}
Also used : Input(io.crate.data.Input) TransactionContext(io.crate.metadata.TransactionContext) SqlExpressions(io.crate.testing.SqlExpressions) Arrays(java.util.Arrays) Array(java.lang.reflect.Array) RelationName(io.crate.metadata.RelationName) SENTINEL(io.crate.data.SentinelRow.SENTINEL) BatchIterator(io.crate.data.BatchIterator) ReferenceResolver(io.crate.expression.reference.ReferenceResolver) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) RowN(io.crate.data.RowN) Map(java.util.Map) SQLExecutor(io.crate.testing.SQLExecutor) Before(org.junit.Before) DocTableInfo(io.crate.metadata.doc.DocTableInfo) User(io.crate.user.User) AbstractModule(org.elasticsearch.common.inject.AbstractModule) AggregationFunction(io.crate.execution.engine.aggregation.AggregationFunction) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) ColumnIdent(io.crate.metadata.ColumnIdent) Comparators.createComparator(io.crate.execution.engine.sort.Comparators.createComparator) RamAccounting(io.crate.breaker.RamAccounting) Collectors(java.util.stream.Collectors) Lists2(io.crate.common.collections.Lists2) InputCollectExpression(io.crate.execution.engine.collect.InputCollectExpression) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ExpressionsInput(io.crate.expression.ExpressionsInput) List(java.util.List) OrderBy(io.crate.analyze.OrderBy) BatchIterators(io.crate.data.BatchIterators) Version(org.elasticsearch.Version) DocTableRelation(io.crate.analyze.relations.DocTableRelation) Row(io.crate.data.Row) Literal(io.crate.expression.symbol.Literal) Symbol(io.crate.expression.symbol.Symbol) FunctionImplementation(io.crate.metadata.FunctionImplementation) Matcher(org.hamcrest.Matcher) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) InputColumns(io.crate.execution.dsl.projection.builder.InputColumns) OnHeapMemoryManager(io.crate.memory.OnHeapMemoryManager) InputFactory(io.crate.expression.InputFactory) Comparator(java.util.Comparator) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) InputFactory(io.crate.expression.InputFactory) DocTableInfo(io.crate.metadata.doc.DocTableInfo) OnHeapMemoryManager(io.crate.memory.OnHeapMemoryManager) RelationName(io.crate.metadata.RelationName) DocTableRelation(io.crate.analyze.relations.DocTableRelation) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) SqlExpressions(io.crate.testing.SqlExpressions) Before(org.junit.Before)

Aggregations

DocTableInfo (io.crate.metadata.doc.DocTableInfo)127 Test (org.junit.Test)56 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)40 Symbol (io.crate.expression.symbol.Symbol)27 Reference (io.crate.metadata.Reference)27 SQLExecutor (io.crate.testing.SQLExecutor)25 RelationName (io.crate.metadata.RelationName)24 DocTableRelation (io.crate.analyze.relations.DocTableRelation)20 ColumnIdent (io.crate.metadata.ColumnIdent)20 TableInfo (io.crate.metadata.table.TableInfo)18 Assignments (io.crate.expression.symbol.Assignments)16 Row (io.crate.data.Row)14 PlannerContext (io.crate.planner.PlannerContext)13 Before (org.junit.Before)13 RowConsumer (io.crate.data.RowConsumer)12 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)12 PartitionName (io.crate.metadata.PartitionName)12 DependencyCarrier (io.crate.planner.DependencyCarrier)12 ArrayList (java.util.ArrayList)12 Map (java.util.Map)12