Search in sources :

Example 11 with QueriedRelation

use of io.crate.analyze.relations.QueriedRelation in project crate by crate.

the class SelectStatementAnalyzerTest method testRewriteRegexpNoMatch.

@Test
public void testRewriteRegexpNoMatch() throws Exception {
    String statement = "select * from sys.nodes where sys.nodes.name !~ '[sS]omething'";
    QueriedRelation relation = analyze(statement).relation();
    WhereClause whereClause = relation.querySpec().where();
    Function notFunction = (Function) whereClause.query();
    assertThat(notFunction.info().ident().name(), is(NotPredicate.NAME));
    assertThat(notFunction.arguments().size(), is(1));
    Function eqFunction = (Function) notFunction.arguments().get(0);
    assertThat(eqFunction.info().ident().name(), is(RegexpMatchOperator.NAME));
    assertThat(eqFunction.arguments().size(), is(2));
    List<Symbol> eqArguments = eqFunction.arguments();
    assertThat(eqArguments.get(0), isReference("name"));
    assertThat(eqArguments.get(1), isLiteral("[sS]omething"));
}
Also used : DistanceFunction(io.crate.operation.scalar.geo.DistanceFunction) SubscriptFunction(io.crate.operation.scalar.SubscriptFunction) MatchesFunction(io.crate.operation.scalar.regex.MatchesFunction) AddFunction(io.crate.operation.scalar.arithmetic.AddFunction) QueriedRelation(io.crate.analyze.relations.QueriedRelation) TestingHelpers.mapToSortedString(io.crate.testing.TestingHelpers.mapToSortedString) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 12 with QueriedRelation

use of io.crate.analyze.relations.QueriedRelation in project crate by crate.

the class SelectStatementAnalyzerTest method testGroupByOnOrdinal.

@Test
public void testGroupByOnOrdinal() throws Exception {
    // just like in postgres access by ordinal starts with 1
    QueriedRelation relation = analyze("select count(*), name as n from sys.nodes group by 2").relation();
    assertThat(relation.querySpec().groupBy().get().size(), is(1));
    assertEquals(relation.querySpec().groupBy().get().get(0), relation.querySpec().outputs().get(1));
}
Also used : QueriedRelation(io.crate.analyze.relations.QueriedRelation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 13 with QueriedRelation

use of io.crate.analyze.relations.QueriedRelation in project crate by crate.

the class SelectStatementAnalyzerTest method testAllColumnCluster.

@Test
public void testAllColumnCluster() throws Exception {
    QueriedRelation relation = analyze("select * from sys.cluster").relation();
    assertThat(relation.fields().size(), is(4));
    assertThat(outputNames(relation), containsInAnyOrder("id", "master_node", "name", "settings"));
    assertThat(relation.querySpec().outputs().size(), is(4));
}
Also used : QueriedRelation(io.crate.analyze.relations.QueriedRelation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

QueriedRelation (io.crate.analyze.relations.QueriedRelation)13 CrateUnitTest (io.crate.test.integration.CrateUnitTest)11 Test (org.junit.Test)11 SubscriptFunction (io.crate.operation.scalar.SubscriptFunction)5 AddFunction (io.crate.operation.scalar.arithmetic.AddFunction)5 DistanceFunction (io.crate.operation.scalar.geo.DistanceFunction)5 MatchesFunction (io.crate.operation.scalar.regex.MatchesFunction)5 TestingHelpers.mapToSortedString (io.crate.testing.TestingHelpers.mapToSortedString)3 QuerySpec (io.crate.analyze.QuerySpec)1 SelectAnalyzedStatement (io.crate.analyze.SelectAnalyzedStatement)1 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)1 SelectSymbol (io.crate.analyze.symbol.SelectSymbol)1 ValidationException (io.crate.exceptions.ValidationException)1 Nullable (javax.annotation.Nullable)1