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);
}
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)));
}
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;
}
}
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"));
}
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);
}
Aggregations