Search in sources :

Example 51 with SQLExecutor

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

the class ValueNormalizerTest method prepare.

@Before
public void prepare() throws Exception {
    SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table doc.test1 (" + " id long primary key," + " name string," + " d double," + " dyn_empty object," + " dyn object as (" + "  d double," + "  inner_strict object(strict) as (" + "   double double" + "  )" + " )," + " strict object(strict) as (" + "  inner_d double" + " )," + " ignored object(ignored)" + ") " + "clustered by (id)").build();
    userTableInfo = e.resolveTableInfo("doc.test1");
    normalizer = EvaluatingNormalizer.functionOnlyNormalizer(e.nodeCtx);
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) Before(org.junit.Before)

Example 52 with SQLExecutor

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

the class SchemasTest method testResolveRelationThrowsRelationUnknownIfRelationIsNotInSearchPath.

@Test
public void testResolveRelationThrowsRelationUnknownIfRelationIsNotInSearchPath() throws IOException {
    SQLExecutor sqlExecutor = getSqlExecutorBuilderForTable(new RelationName("schema", "t"), "doc", "schema").build();
    QualifiedName table = QualifiedName.of("missing_table");
    expectedException.expect(RelationUnknown.class);
    expectedException.expectMessage("Relation 'missing_table' unknown");
    sqlExecutor.schemas().resolveRelation(table, sqlExecutor.getSessionContext().searchPath());
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) QualifiedName(io.crate.sql.tree.QualifiedName) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) ViewsMetadataTest(io.crate.metadata.view.ViewsMetadataTest)

Example 53 with SQLExecutor

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

the class SchemasTest method testResolveTableInfoForInvalidFQNThrowsSchemaUnknownException.

@Test
public void testResolveTableInfoForInvalidFQNThrowsSchemaUnknownException() throws IOException {
    SQLExecutor sqlExecutor = getSqlExecutorBuilderForTable(new RelationName("schema", "t")).build();
    QualifiedName invalidFqn = QualifiedName.of("bogus_schema", "t");
    SessionContext sessionContext = sqlExecutor.getSessionContext();
    expectedException.expect(SchemaUnknownException.class);
    expectedException.expectMessage("Schema 'bogus_schema' unknown");
    sqlExecutor.schemas().resolveTableInfo(invalidFqn, Operation.READ, sessionContext.sessionUser(), sessionContext.searchPath());
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) QualifiedName(io.crate.sql.tree.QualifiedName) SessionContext(io.crate.action.sql.SessionContext) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) ViewsMetadataTest(io.crate.metadata.view.ViewsMetadataTest)

Example 54 with SQLExecutor

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

the class SchemasTest method testResolveTableInfoThrowsRelationUnknownIfRelationIsNotInSearchPath.

@Test
public void testResolveTableInfoThrowsRelationUnknownIfRelationIsNotInSearchPath() throws IOException {
    SQLExecutor sqlExecutor = getSqlExecutorBuilderForTable(new RelationName("schema", "t")).build();
    QualifiedName table = QualifiedName.of("missing_table");
    SessionContext sessionContext = sqlExecutor.getSessionContext();
    expectedException.expect(RelationUnknown.class);
    expectedException.expectMessage("Relation 'missing_table' unknown");
    sqlExecutor.schemas().resolveTableInfo(table, Operation.READ, sessionContext.sessionUser(), sessionContext.searchPath());
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) QualifiedName(io.crate.sql.tree.QualifiedName) SessionContext(io.crate.action.sql.SessionContext) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) ViewsMetadataTest(io.crate.metadata.view.ViewsMetadataTest)

Example 55 with SQLExecutor

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

the class SchemasTest method testResolveRelationForTableAndView.

@Test
public void testResolveRelationForTableAndView() throws IOException {
    SQLExecutor sqlExecutor = getSqlExecutorBuilderForTable(new RelationName("schema", "t"), "doc", "schema").addView(new RelationName("schema", "view"), "select 1").build();
    QualifiedName table = QualifiedName.of("t");
    RelationName tableRelation = sqlExecutor.schemas().resolveRelation(table, sqlExecutor.getSessionContext().searchPath());
    assertThat(tableRelation.schema(), is("schema"));
    assertThat(tableRelation.name(), is("t"));
    QualifiedName view = QualifiedName.of("view");
    RelationName viewRelation = sqlExecutor.schemas().resolveRelation(view, sqlExecutor.getSessionContext().searchPath());
    assertThat(viewRelation.schema(), is("schema"));
    assertThat(viewRelation.name(), is("view"));
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) QualifiedName(io.crate.sql.tree.QualifiedName) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) ViewsMetadataTest(io.crate.metadata.view.ViewsMetadataTest)

Aggregations

SQLExecutor (io.crate.testing.SQLExecutor)64 Test (org.junit.Test)55 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)54 DocTableInfo (io.crate.metadata.doc.DocTableInfo)24 RelationName (io.crate.metadata.RelationName)9 AnalyzedUpdateStatement (io.crate.analyze.AnalyzedUpdateStatement)8 Doc (io.crate.expression.reference.Doc)8 Assignments (io.crate.expression.symbol.Assignments)7 Symbols (io.crate.expression.symbol.Symbols)7 CreateTable (io.crate.sql.tree.CreateTable)7 TableStats (io.crate.statistics.TableStats)7 Before (org.junit.Before)7 Symbol (io.crate.expression.symbol.Symbol)6 ViewsMetadataTest (io.crate.metadata.view.ViewsMetadataTest)6 QualifiedName (io.crate.sql.tree.QualifiedName)6 DocTableRelation (io.crate.analyze.relations.DocTableRelation)5 SessionContext (io.crate.action.sql.SessionContext)4 AliasSymbol (io.crate.expression.symbol.AliasSymbol)4 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)3 PlannerContext (io.crate.planner.PlannerContext)3