use of io.crate.expression.symbol.AliasSymbol 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']"))));
}
use of io.crate.expression.symbol.AliasSymbol in project crate by crate.
the class MapBackedSymbolReplacerTest method test_convert_symbol_without_traversing.
@Test
public void test_convert_symbol_without_traversing() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table tbl (x int)").build();
Symbol x = e.asSymbol("x");
Symbol x_source_lookup = e.asSymbol("_doc['x']");
Symbol alias = new AliasSymbol("a_alias", x);
Symbol alias_source_lookup = new AliasSymbol("a_alias", x_source_lookup);
// Mapping contains the requested symbol directly, must not traverse alias symbols
Map<Symbol, Symbol> mapping = Map.of(alias, alias_source_lookup);
assertThat(MapBackedSymbolReplacer.convert(alias, mapping), is(alias_source_lookup));
}
use of io.crate.expression.symbol.AliasSymbol in project crate by crate.
the class CommonQueryBuilderTest method test_eq_on_alias_inner_func_uses_termquery.
@Test
public void test_eq_on_alias_inner_func_uses_termquery() throws Exception {
// Testing expression: f(col as alias) = 'foo'
AliasSymbol alias = new AliasSymbol("aliased", createReference("arr", DataTypes.INTEGER_ARRAY));
var innerFunction = new Function(Signature.scalar("array_length", parseTypeSignature("array(E)"), DataTypes.INTEGER.getTypeSignature(), DataTypes.INTEGER.getTypeSignature()), // 1 is a dummy argument for dimension.
List.of(alias, Literal.of(1)), DataTypes.INTEGER);
var func = new Function(EqOperator.SIGNATURE, List.of(innerFunction, Literal.of(5)), DataTypes.BOOLEAN);
Query query = queryTester.toQuery(func);
assertThat(query, instanceOf(BooleanQuery.class));
}
use of io.crate.expression.symbol.AliasSymbol in project crate by crate.
the class MapBackedSymbolReplacerTest method test_convert_symbol_by_traversing.
@Test
public void test_convert_symbol_by_traversing() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table tbl (x int)").build();
Symbol x = e.asSymbol("x");
Symbol x_source_lookup = e.asSymbol("_doc['x']");
Symbol alias = new AliasSymbol("a_alias", x);
Symbol alias_source_lookup = new AliasSymbol("a_alias", x_source_lookup);
// Mapping does not contain the requested symbol, but a child of it. Fallback to symbol traversing.
Map<Symbol, Symbol> mapping = Map.of(x, x_source_lookup);
assertThat(MapBackedSymbolReplacer.convert(alias, mapping), is(alias_source_lookup));
}
use of io.crate.expression.symbol.AliasSymbol in project crate by crate.
the class CommonQueryBuilderTest method test_eq_on_alias_uses_termquery.
@Test
public void test_eq_on_alias_uses_termquery() throws Exception {
// Testing expression: col as alias = 'foo'
AliasSymbol alias = new AliasSymbol("aliased", createReference("name", DataTypes.STRING));
var literal = Literal.of("foo");
var func = new Function(EqOperator.SIGNATURE, List.of(alias, literal), DataTypes.BOOLEAN);
Query query = queryTester.toQuery(func);
assertThat(query, instanceOf(TermQuery.class));
}
Aggregations