Search in sources :

Example 1 with AliasSymbol

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']"))));
}
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 2 with AliasSymbol

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));
}
Also used : AliasSymbol(io.crate.expression.symbol.AliasSymbol) SQLExecutor(io.crate.testing.SQLExecutor) AliasSymbol(io.crate.expression.symbol.AliasSymbol) Symbol(io.crate.expression.symbol.Symbol) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 3 with AliasSymbol

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));
}
Also used : Function(io.crate.expression.symbol.Function) BooleanQuery(org.apache.lucene.search.BooleanQuery) AliasSymbol(io.crate.expression.symbol.AliasSymbol) CrateRegexQuery(io.crate.lucene.match.CrateRegexQuery) Query(org.apache.lucene.search.Query) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) RegexpQuery(org.apache.lucene.search.RegexpQuery) PointInSetQuery(org.apache.lucene.search.PointInSetQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) IntersectsPrefixTreeQuery(org.apache.lucene.spatial.prefix.IntersectsPrefixTreeQuery) PointRangeQuery(org.apache.lucene.search.PointRangeQuery) TermInSetQuery(org.apache.lucene.search.TermInSetQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) DocValuesFieldExistsQuery(org.apache.lucene.search.DocValuesFieldExistsQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) Test(org.junit.Test)

Example 4 with AliasSymbol

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));
}
Also used : AliasSymbol(io.crate.expression.symbol.AliasSymbol) SQLExecutor(io.crate.testing.SQLExecutor) AliasSymbol(io.crate.expression.symbol.AliasSymbol) Symbol(io.crate.expression.symbol.Symbol) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 5 with AliasSymbol

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));
}
Also used : Function(io.crate.expression.symbol.Function) TermQuery(org.apache.lucene.search.TermQuery) AliasSymbol(io.crate.expression.symbol.AliasSymbol) CrateRegexQuery(io.crate.lucene.match.CrateRegexQuery) Query(org.apache.lucene.search.Query) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) RegexpQuery(org.apache.lucene.search.RegexpQuery) PointInSetQuery(org.apache.lucene.search.PointInSetQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) IntersectsPrefixTreeQuery(org.apache.lucene.spatial.prefix.IntersectsPrefixTreeQuery) PointRangeQuery(org.apache.lucene.search.PointRangeQuery) TermInSetQuery(org.apache.lucene.search.TermInSetQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) DocValuesFieldExistsQuery(org.apache.lucene.search.DocValuesFieldExistsQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) Test(org.junit.Test)

Aggregations

AliasSymbol (io.crate.expression.symbol.AliasSymbol)5 Test (org.junit.Test)5 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)3 SQLExecutor (io.crate.testing.SQLExecutor)3 Function (io.crate.expression.symbol.Function)2 Symbol (io.crate.expression.symbol.Symbol)2 CrateRegexQuery (io.crate.lucene.match.CrateRegexQuery)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)2 DocValuesFieldExistsQuery (org.apache.lucene.search.DocValuesFieldExistsQuery)2 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)2 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)2 PointInSetQuery (org.apache.lucene.search.PointInSetQuery)2 PointRangeQuery (org.apache.lucene.search.PointRangeQuery)2 Query (org.apache.lucene.search.Query)2 RegexpQuery (org.apache.lucene.search.RegexpQuery)2 TermInSetQuery (org.apache.lucene.search.TermInSetQuery)2 TermQuery (org.apache.lucene.search.TermQuery)2 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)2 IntersectsPrefixTreeQuery (org.apache.lucene.spatial.prefix.IntersectsPrefixTreeQuery)2