Search in sources :

Example 6 with SqlExpressions

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

the class CurrentSchemaFunctionTest method testNormalizeCurrentSchemaCustomSchema.

@Test
public void testNormalizeCurrentSchemaCustomSchema() throws Exception {
    sqlExpressions = new SqlExpressions(tableSources, new SessionContext(0, Option.NONE, "custom_schema"));
    functions = sqlExpressions.getInstance(Functions.class);
    assertNormalize("current_schema()", isLiteral("custom_schema"), false);
}
Also used : SessionContext(io.crate.action.sql.SessionContext) Functions(io.crate.metadata.Functions) SqlExpressions(io.crate.testing.SqlExpressions) AbstractScalarFunctionsTest(io.crate.operation.scalar.AbstractScalarFunctionsTest) Test(org.junit.Test)

Example 7 with SqlExpressions

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

the class ExpressionAnalyzerTest method testBetweenNullIsRewrittenToLteAndGte.

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

Example 8 with SqlExpressions

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

the class SymbolPrinterTest method prepare.

@Before
public void prepare() throws Exception {
    DocTableInfo tableInfo = TestingTableInfo.builder(new TableIdent(DocSchemaInfo.NAME, TABLE_NAME), null).add("foo", DataTypes.STRING).add("bar", DataTypes.LONG).add("CraZy", DataTypes.IP).add("select", DataTypes.BYTE).add("idx", DataTypes.INTEGER).add("s_arr", new ArrayType(DataTypes.STRING)).build();
    Map<QualifiedName, AnalyzedRelation> sources = ImmutableMap.<QualifiedName, AnalyzedRelation>builder().put(QualifiedName.of(TABLE_NAME), new TableRelation(tableInfo)).build();
    sqlExpressions = new SqlExpressions(sources);
    printer = new SymbolPrinter(sqlExpressions.functions());
}
Also used : ArrayType(io.crate.types.ArrayType) DocTableInfo(io.crate.metadata.doc.DocTableInfo) QualifiedName(io.crate.sql.tree.QualifiedName) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) SqlExpressions(io.crate.testing.SqlExpressions) TableRelation(io.crate.analyze.relations.TableRelation) AbstractTableRelation(io.crate.analyze.relations.AbstractTableRelation) Before(org.junit.Before)

Example 9 with SqlExpressions

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

the class AbstractScalarFunctionsTest method prepareFunctions.

@Before
public void prepareFunctions() throws Exception {
    DocTableInfo tableInfo = TestingTableInfo.builder(new TableIdent(DocSchemaInfo.NAME, "users"), null).add("id", DataTypes.INTEGER).add("name", DataTypes.STRING).add("tags", new ArrayType(DataTypes.STRING)).add("age", DataTypes.INTEGER).add("a", DataTypes.INTEGER).add("x", DataTypes.LONG).add("shape", DataTypes.GEO_SHAPE).add("timestamp", DataTypes.TIMESTAMP).add("timezone", DataTypes.STRING).add("interval", DataTypes.STRING).add("time_format", DataTypes.STRING).add("long_array", new ArrayType(DataTypes.LONG)).add("int_array", new ArrayType(DataTypes.INTEGER)).add("long_set", new SetType(DataTypes.LONG)).add("regex_pattern", DataTypes.STRING).add("geoshape", DataTypes.GEO_SHAPE).add("geopoint", DataTypes.GEO_POINT).add("geostring", DataTypes.STRING).add("is_awesome", DataTypes.BOOLEAN).add("double_val", DataTypes.DOUBLE).add("float_val", DataTypes.DOUBLE).add("short_val", DataTypes.SHORT).add("obj", DataTypes.OBJECT, ImmutableList.of()).build();
    DocTableRelation tableRelation = new DocTableRelation(tableInfo);
    tableSources = ImmutableMap.of(new QualifiedName("users"), tableRelation);
    sqlExpressions = new SqlExpressions(tableSources);
    functions = sqlExpressions.getInstance(Functions.class);
}
Also used : ArrayType(io.crate.types.ArrayType) DocTableInfo(io.crate.metadata.doc.DocTableInfo) SetType(io.crate.types.SetType) QualifiedName(io.crate.sql.tree.QualifiedName) DocTableRelation(io.crate.analyze.relations.DocTableRelation) SqlExpressions(io.crate.testing.SqlExpressions) Before(org.junit.Before)

Example 10 with SqlExpressions

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

the class NestedLoopPhaseTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    TopNProjection topNProjection = new TopNProjection(10, 0, Collections.emptyList());
    UUID jobId = UUID.randomUUID();
    MergePhase mp1 = new MergePhase(jobId, 2, "merge", 1, Collections.emptyList(), ImmutableList.<DataType>of(DataTypes.STRING), ImmutableList.of(), DistributionInfo.DEFAULT_BROADCAST, null);
    MergePhase mp2 = new MergePhase(jobId, 3, "merge", 1, Collections.emptyList(), ImmutableList.<DataType>of(DataTypes.STRING), ImmutableList.of(), DistributionInfo.DEFAULT_BROADCAST, null);
    SqlExpressions sqlExpressions = new SqlExpressions(T3.SOURCES, T3.TR_1);
    Symbol joinCondition = sqlExpressions.normalize(sqlExpressions.asSymbol("t1.x = t1.i"));
    NestedLoopPhase node = new NestedLoopPhase(jobId, 1, "nestedLoop", ImmutableList.of(topNProjection), mp1, mp2, Sets.newHashSet("node1", "node2"), JoinType.INNER, joinCondition, 1, 1);
    BytesStreamOutput output = new BytesStreamOutput();
    node.writeTo(output);
    StreamInput input = StreamInput.wrap(output.bytes());
    NestedLoopPhase node2 = new NestedLoopPhase();
    node2.readFrom(input);
    assertThat(node.nodeIds(), Is.is(node2.nodeIds()));
    assertThat(node.jobId(), Is.is(node2.jobId()));
    assertThat(node.name(), is(node2.name()));
    assertThat(node.outputTypes(), is(node2.outputTypes()));
    assertThat(node.joinType(), is(node2.joinType()));
    assertThat(node.numLeftOutputs(), is(node2.numLeftOutputs()));
    assertThat(node.numRightOutputs(), is(node2.numRightOutputs()));
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) StreamInput(org.elasticsearch.common.io.stream.StreamInput) TopNProjection(io.crate.planner.projection.TopNProjection) UUID(java.util.UUID) SqlExpressions(io.crate.testing.SqlExpressions) NestedLoopPhase(io.crate.planner.node.dql.join.NestedLoopPhase) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) 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