Search in sources :

Example 11 with DocTableRelation

use of io.crate.analyze.relations.DocTableRelation in project crate by crate.

the class InputFactoryTest 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);
    expressions = new SqlExpressions(sources, tr1);
    factory = new InputFactory(expressions.nodeCtx);
}
Also used : 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)

Example 12 with DocTableRelation

use of io.crate.analyze.relations.DocTableRelation in project crate by crate.

the class CollectTest method test_prune_output_of_collect_updates_estimated_row_size.

@Test
public void test_prune_output_of_collect_updates_estimated_row_size() throws Exception {
    var e = SQLExecutor.builder(clusterService).addTable("create table t (x int, y int)").build();
    TableStats tableStats = new TableStats();
    Symbol x = e.asSymbol("x");
    Collect collect = Collect.create(new DocTableRelation(e.resolveTableInfo("t")), List.of(x, e.asSymbol("y")), WhereClause.MATCH_ALL, tableStats, Row.EMPTY);
    assertThat(collect.estimatedRowSize(), is(DataTypes.INTEGER.fixedSize() * 2L));
    LogicalPlan prunedCollect = collect.pruneOutputsExcept(tableStats, List.of(x));
    assertThat(prunedCollect.estimatedRowSize(), is((long) DataTypes.INTEGER.fixedSize()));
}
Also used : Symbol(io.crate.expression.symbol.Symbol) DocTableRelation(io.crate.analyze.relations.DocTableRelation) TableStats(io.crate.statistics.TableStats) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 13 with DocTableRelation

use of io.crate.analyze.relations.DocTableRelation 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 14 with DocTableRelation

use of io.crate.analyze.relations.DocTableRelation 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 15 with DocTableRelation

use of io.crate.analyze.relations.DocTableRelation 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

DocTableRelation (io.crate.analyze.relations.DocTableRelation)36 DocTableInfo (io.crate.metadata.doc.DocTableInfo)17 RelationName (io.crate.metadata.RelationName)13 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)10 Symbol (io.crate.expression.symbol.Symbol)10 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)10 SqlExpressions (io.crate.testing.SqlExpressions)10 Test (org.junit.Test)10 Before (org.junit.Before)9 ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)7 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)7 EvaluatingNormalizer (io.crate.expression.eval.EvaluatingNormalizer)7 Reference (io.crate.metadata.Reference)6 SQLExecutor (io.crate.testing.SQLExecutor)6 WhereClause (io.crate.analyze.WhereClause)5 TableInfo (io.crate.metadata.table.TableInfo)4 QueriedSelectRelation (io.crate.analyze.QueriedSelectRelation)3 FullQualifiedNameFieldProvider (io.crate.analyze.relations.FullQualifiedNameFieldProvider)3 NameFieldProvider (io.crate.analyze.relations.NameFieldProvider)3 StatementAnalysisContext (io.crate.analyze.relations.StatementAnalysisContext)3