Search in sources :

Example 11 with SqlExpressions

use of io.crate.testing.SqlExpressions in project crate by crate.

the class UnnestFunctionTest method prepareFunctions.

@Before
public void prepareFunctions() throws Exception {
    sqlExpressions = new SqlExpressions(ImmutableMap.of(QualifiedName.of("t"), mock(DocTableRelation.class)));
    functions = sqlExpressions.getInstance(Functions.class);
}
Also used : DocTableRelation(io.crate.analyze.relations.DocTableRelation) Functions(io.crate.metadata.Functions) SqlExpressions(io.crate.testing.SqlExpressions) Before(org.junit.Before)

Example 12 with SqlExpressions

use of io.crate.testing.SqlExpressions in project crate by crate.

the class LuceneQueryBuilderTest method testEqOnArrayWithTooManyClauses.

@Test
public void testEqOnArrayWithTooManyClauses() throws Exception {
    // should trigger the TooManyClauses exception
    Object[] values = new Object[2000];
    Arrays.fill(values, 10L);
    SqlExpressions sqlExpressions = new SqlExpressions(sources, new Object[] { values });
    Query query = convert(new WhereClause(expressions.normalize(sqlExpressions.asSymbol("y_array = ?"))));
    assertThat(query, instanceOf(BooleanQuery.class));
    BooleanQuery booleanQuery = (BooleanQuery) query;
    assertThat(booleanQuery.clauses().get(0).getQuery(), instanceOf(TermsQuery.class));
    assertThat(booleanQuery.clauses().get(1).getQuery(), instanceOf(GenericFunctionQuery.class));
}
Also used : TermsQuery(org.apache.lucene.queries.TermsQuery) CrateRegexQuery(io.crate.lucene.match.CrateRegexQuery) IntersectsPrefixTreeQuery(org.apache.lucene.spatial.prefix.IntersectsPrefixTreeQuery) WithinPrefixTreeQuery(org.apache.lucene.spatial.prefix.WithinPrefixTreeQuery) WhereClause(io.crate.analyze.WhereClause) SqlExpressions(io.crate.testing.SqlExpressions) TermsQuery(org.apache.lucene.queries.TermsQuery) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 13 with SqlExpressions

use of io.crate.testing.SqlExpressions in project crate by crate.

the class ExpressionAnalyzerTest method testSwapFunctionLeftSide.

@Test
public void testSwapFunctionLeftSide() throws Exception {
    SqlExpressions expressions = new SqlExpressions(T3.SOURCES);
    Function cmp = (Function) expressions.normalize(expressions.asSymbol("8 + 5 > t1.x"));
    // the comparison was swapped so the field is on the left side
    assertThat(cmp.info().ident().name(), is("op_<"));
    assertThat(cmp.arguments().get(0), isField("x"));
}
Also used : Function(io.crate.analyze.symbol.Function) SqlExpressions(io.crate.testing.SqlExpressions) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 14 with SqlExpressions

use of io.crate.testing.SqlExpressions in project crate by crate.

the class ExpressionAnalyzerTest method testBetweenIsRewrittenToLteAndGte.

@Test
public void testBetweenIsRewrittenToLteAndGte() throws Exception {
    SqlExpressions expressions = new SqlExpressions(T3.SOURCES);
    Symbol symbol = expressions.asSymbol("10 between 1 and 10");
    assertThat(symbol, isSQL("((10 >= 1) AND (10 <= 10))"));
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) SqlExpressions(io.crate.testing.SqlExpressions) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 15 with SqlExpressions

use of io.crate.testing.SqlExpressions in project crate by crate.

the class LuceneQueryBuilderTest method testEqOnTwoArraysBecomesGenericFunctionQueryAllValuesNull.

@Test
public void testEqOnTwoArraysBecomesGenericFunctionQueryAllValuesNull() throws Exception {
    SqlExpressions sqlExpressions = new SqlExpressions(sources, new Object[] { new Object[] { null, null, null } });
    Query query = convert(new WhereClause(expressions.normalize(sqlExpressions.asSymbol("y_array = ?"))));
    assertThat(query, instanceOf(GenericFunctionQuery.class));
}
Also used : TermsQuery(org.apache.lucene.queries.TermsQuery) CrateRegexQuery(io.crate.lucene.match.CrateRegexQuery) IntersectsPrefixTreeQuery(org.apache.lucene.spatial.prefix.IntersectsPrefixTreeQuery) WithinPrefixTreeQuery(org.apache.lucene.spatial.prefix.WithinPrefixTreeQuery) WhereClause(io.crate.analyze.WhereClause) SqlExpressions(io.crate.testing.SqlExpressions) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

SqlExpressions (io.crate.testing.SqlExpressions)18 Test (org.junit.Test)12 CrateUnitTest (io.crate.test.integration.CrateUnitTest)9 QualifiedName (io.crate.sql.tree.QualifiedName)7 WhereClause (io.crate.analyze.WhereClause)5 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)5 TableRelation (io.crate.analyze.relations.TableRelation)5 Before (org.junit.Before)5 Symbol (io.crate.analyze.symbol.Symbol)4 DocTableInfo (io.crate.metadata.doc.DocTableInfo)4 CrateRegexQuery (io.crate.lucene.match.CrateRegexQuery)3 Functions (io.crate.metadata.Functions)3 TableIdent (io.crate.metadata.TableIdent)3 ArrayType (io.crate.types.ArrayType)3 TermsQuery (org.apache.lucene.queries.TermsQuery)3 IntersectsPrefixTreeQuery (org.apache.lucene.spatial.prefix.IntersectsPrefixTreeQuery)3 WithinPrefixTreeQuery (org.apache.lucene.spatial.prefix.WithinPrefixTreeQuery)3 SessionContext (io.crate.action.sql.SessionContext)2 DocTableRelation (io.crate.analyze.relations.DocTableRelation)2 Function (io.crate.analyze.symbol.Function)2