use of io.crate.expression.symbol.FetchStub 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)));
}
Aggregations