Search in sources :

Example 26 with SQLExecutor

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

the class DocLevelExpressionsTest method prepare.

@Before
public void prepare() throws Exception {
    SQLExecutor e = SQLExecutor.builder(clusterService).addTable(createTableStatement).build();
    indexEnv = new IndexEnv(THREAD_POOL, (DocTableInfo) StreamSupport.stream(e.schemas().spliterator(), false).filter(x -> x instanceof DocSchemaInfo).map(x -> (DocSchemaInfo) x).findFirst().orElseThrow(() -> new IllegalStateException("No doc schema found")).getTables().iterator().next(), clusterService.state(), Version.CURRENT, createTempDir());
    IndexWriter writer = indexEnv.writer();
    insertValues(writer);
    DirectoryReader directoryReader = DirectoryReader.open(writer, true, true);
    readerContext = directoryReader.leaves().get(0);
    ctx = new CollectorContext();
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) CollectorContext(io.crate.expression.reference.doc.lucene.CollectorContext) IndexEnv(io.crate.testing.IndexEnv) DirectoryReader(org.apache.lucene.index.DirectoryReader) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) IndexWriter(org.apache.lucene.index.IndexWriter) Version(org.elasticsearch.Version) DocSchemaInfo(io.crate.metadata.doc.DocSchemaInfo) After(org.junit.After) StreamSupport(java.util.stream.StreamSupport) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) SQLExecutor(io.crate.testing.SQLExecutor) Before(org.junit.Before) DocTableInfo(io.crate.metadata.doc.DocTableInfo) DocSchemaInfo(io.crate.metadata.doc.DocSchemaInfo) SQLExecutor(io.crate.testing.SQLExecutor) IndexEnv(io.crate.testing.IndexEnv) IndexWriter(org.apache.lucene.index.IndexWriter) DirectoryReader(org.apache.lucene.index.DirectoryReader) CollectorContext(io.crate.expression.reference.doc.lucene.CollectorContext) Before(org.junit.Before)

Example 27 with SQLExecutor

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

the class SysNodesTableInfoTest method test_column_that_is_a_child_of_an_array_has_array_type_on_select.

@Test
public void test_column_that_is_a_child_of_an_array_has_array_type_on_select() {
    var table = SysNodesTableInfo.create();
    Reference ref = table.getReference(new ColumnIdent("fs", List.of("data", "path")));
    assertThat(ref.valueType(), is(new ArrayType<>(DataTypes.STRING)));
    SQLExecutor e = SQLExecutor.builder(clusterService).build();
    AnalyzedRelation statement = e.analyze("select fs['data']['path'] from sys.nodes");
    assertThat(statement.outputs().get(0).valueType(), is(new ArrayType<>(DataTypes.STRING)));
}
Also used : ArrayType(io.crate.types.ArrayType) SQLExecutor(io.crate.testing.SQLExecutor) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 28 with SQLExecutor

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

the class SchemasTest method testResolveTableInfoForValidFQN.

@Test
public void testResolveTableInfoForValidFQN() throws IOException {
    RelationName tableIdent = new RelationName("schema", "t");
    SQLExecutor sqlExecutor = getSqlExecutorBuilderForTable(tableIdent, "doc", "schema").build();
    QualifiedName fqn = QualifiedName.of("schema", "t");
    SessionContext sessionContext = sqlExecutor.getSessionContext();
    TableInfo tableInfo = sqlExecutor.schemas().resolveTableInfo(fqn, Operation.READ, sessionContext.sessionUser(), sessionContext.searchPath());
    RelationName relation = tableInfo.ident();
    assertThat(relation.schema(), is("schema"));
    assertThat(relation.name(), is("t"));
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) QualifiedName(io.crate.sql.tree.QualifiedName) SessionContext(io.crate.action.sql.SessionContext) TableInfo(io.crate.metadata.table.TableInfo) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) ViewsMetadataTest(io.crate.metadata.view.ViewsMetadataTest)

Example 29 with SQLExecutor

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

the class DropViewAnalyzerTest method testDropViewRaisesRelationsUnkownForMissingView.

@Test
public void testDropViewRaisesRelationsUnkownForMissingView() {
    SQLExecutor e = SQLExecutor.builder(clusterService).build();
    expectedException.expect(RelationsUnknown.class);
    expectedException.expectMessage("Relations not found: doc.v1, doc.v2");
    e.analyze("drop view v1, v2");
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 30 with SQLExecutor

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

the class DropViewAnalyzerTest method testDropViewContainsIfExistsAndEmptyViews.

@Test
public void testDropViewContainsIfExistsAndEmptyViews() {
    SQLExecutor e = SQLExecutor.builder(clusterService).build();
    AnalyzedDropView dropView = e.analyze("drop view if exists v1, v2, x.v3");
    assertThat(dropView.ifExists(), is(true));
    assertThat(dropView.views(), is(empty()));
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

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