Search in sources :

Example 26 with DocTableRelation

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

the class UserDefinedFunctionsTest method prepare.

@Before
public void prepare() throws Exception {
    SQLExecutor sqlExecutor = SQLExecutor.builder(clusterService).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
    DocTableInfo users = sqlExecutor.schemas().getTableInfo(new RelationName("doc", "users"));
    sqlExpressions = new SqlExpressions(Map.of(users.ident(), new DocTableRelation(users)));
    udfService.registerLanguage(DUMMY_LANG);
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) SQLExecutor(io.crate.testing.SQLExecutor) RelationName(io.crate.metadata.RelationName) DocTableRelation(io.crate.analyze.relations.DocTableRelation) SqlExpressions(io.crate.testing.SqlExpressions) Before(org.junit.Before)

Example 27 with DocTableRelation

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

the class FetchRewriteTest method test_fetchrewrite_on_rename_puts_fetch_marker_into_alias_scope.

@Test
public void test_fetchrewrite_on_rename_puts_fetch_marker_into_alias_scope() throws Exception {
    SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table tbl (x int)").build();
    DocTableInfo tableInfo = e.resolveTableInfo("tbl");
    Reference x = (Reference) e.asSymbol("x");
    var relation = new DocTableRelation(tableInfo);
    var alias = new AliasedAnalyzedRelation(relation, new RelationName(null, "t1"));
    var collect = new Collect(relation, List.of(x), WhereClause.MATCH_ALL, 1L, DataTypes.INTEGER.fixedSize());
    Symbol t1X = alias.getField(x.column(), Operation.READ, true);
    assertThat(t1X, Matchers.notNullValue());
    var rename = new Rename(List.of(t1X), alias.relationName(), alias, collect);
    FetchRewrite fetchRewrite = rename.rewriteToFetch(new TableStats(), List.of());
    assertThat(fetchRewrite, Matchers.notNullValue());
    LogicalPlan newRename = fetchRewrite.newPlan();
    assertThat(newRename, isPlan("Rename[t1._fetchid] AS t1\n" + "  └ Collect[doc.tbl | [_fetchid] | true]"));
    assertThat("fetchRewrite replacedOutputs.keySet() must always match the outputs of the operator prior to the rewrite", List.copyOf(fetchRewrite.replacedOutputs().keySet()), is(rename.outputs()));
    assertThat(fetchRewrite.replacedOutputs(), Matchers.hasEntry(isField("x", alias.relationName()), isFetchStub("_doc['x']")));
    assertThat(newRename.outputs(), contains(isFetchMarker(alias.relationName(), contains(isReference("_doc['x']")))));
    FetchStub fetchStub = (FetchStub) fetchRewrite.replacedOutputs().entrySet().iterator().next().getValue();
    assertThat("FetchStub fetchMarker must be changed to the aliased marker", fetchStub.fetchMarker(), Matchers.sameInstance(newRename.outputs().get(0)));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) Reference(io.crate.metadata.Reference) SymbolMatchers.isReference(io.crate.testing.SymbolMatchers.isReference) AliasSymbol(io.crate.expression.symbol.AliasSymbol) Symbol(io.crate.expression.symbol.Symbol) TableStats(io.crate.statistics.TableStats) SQLExecutor(io.crate.testing.SQLExecutor) SymbolMatchers.isFetchStub(io.crate.testing.SymbolMatchers.isFetchStub) FetchStub(io.crate.expression.symbol.FetchStub) DocTableRelation(io.crate.analyze.relations.DocTableRelation) RelationName(io.crate.metadata.RelationName) AliasedAnalyzedRelation(io.crate.analyze.relations.AliasedAnalyzedRelation) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 28 with DocTableRelation

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

the class OptimizeCollectWhereClauseAccess method apply.

@Override
public LogicalPlan apply(Collect collect, Captures captures, TableStats tableStats, TransactionContext txnCtx, NodeContext nodeCtx) {
    var relation = (DocTableRelation) collect.relation();
    var normalizer = new EvaluatingNormalizer(nodeCtx, RowGranularity.CLUSTER, null, relation);
    WhereClause where = collect.where();
    var detailedQuery = WhereClauseOptimizer.optimize(normalizer, where.queryOrFallback(), relation.tableInfo(), txnCtx, nodeCtx);
    Optional<DocKeys> docKeys = detailedQuery.docKeys();
    // noinspection OptionalIsPresent no capturing lambda allocation
    if (docKeys.isPresent()) {
        return new Get(relation, docKeys.get(), detailedQuery.query(), collect.outputs(), tableStats.estimatedSizePerRow(relation.relationName()));
    } else if (!detailedQuery.clusteredBy().isEmpty() && collect.detailedQuery() == null) {
        return new Collect(collect, detailedQuery);
    } else {
        return null;
    }
}
Also used : EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) DocKeys(io.crate.analyze.where.DocKeys) Collect(io.crate.planner.operators.Collect) Get(io.crate.planner.operators.Get) WhereClause(io.crate.analyze.WhereClause) DocTableRelation(io.crate.analyze.relations.DocTableRelation)

Example 29 with DocTableRelation

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

the class UpdateAnalyzerTest method testUpdateAssignments.

@Test
public void testUpdateAssignments() throws Exception {
    AnalyzedUpdateStatement update = analyze("update users set name='Trillian'");
    assertThat(update.assignmentByTargetCol().size(), is(1));
    assertThat(((DocTableRelation) update.table()).tableInfo().ident(), is(new RelationName(Schemas.DOC_SCHEMA_NAME, "users")));
    Reference ref = update.assignmentByTargetCol().keySet().iterator().next();
    assertThat(ref.ident().tableIdent().name(), is("users"));
    assertThat(ref.column().name(), is("name"));
    assertTrue(update.assignmentByTargetCol().containsKey(ref));
    Symbol value = update.assignmentByTargetCol().entrySet().iterator().next().getValue();
    assertThat(value, isLiteral("Trillian"));
}
Also used : SymbolMatchers.isReference(io.crate.testing.SymbolMatchers.isReference) DynamicReference(io.crate.expression.symbol.DynamicReference) Reference(io.crate.metadata.Reference) ParameterSymbol(io.crate.expression.symbol.ParameterSymbol) Symbol(io.crate.expression.symbol.Symbol) DocTableRelation(io.crate.analyze.relations.DocTableRelation) RelationName(io.crate.metadata.RelationName) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 30 with DocTableRelation

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

the class EqualityExtractorTest 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);
    normalizer = EvaluatingNormalizer.functionOnlyNormalizer(expressions.nodeCtx);
    ee = new EqualityExtractor(normalizer);
}
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)

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