Search in sources :

Example 1 with Statement

use of io.crate.sql.tree.Statement in project crate by crate.

the class DocIndexMetaDataTest method getDocIndexMetaDataFromStatement.

private DocIndexMetaData getDocIndexMetaDataFromStatement(String stmt) throws IOException {
    Statement statement = SqlParser.createStatement(stmt);
    ClusterService clusterService = new NoopClusterService();
    final TransportPutIndexTemplateAction transportPutIndexTemplateAction = mock(TransportPutIndexTemplateAction.class);
    Provider<TransportPutIndexTemplateAction> indexTemplateActionProvider = new Provider<TransportPutIndexTemplateAction>() {

        @Override
        public TransportPutIndexTemplateAction get() {
            return transportPutIndexTemplateAction;
        }
    };
    DocTableInfoFactory docTableInfoFactory = new InternalDocTableInfoFactory(functions, new IndexNameExpressionResolver(Settings.EMPTY), indexTemplateActionProvider, executorService);
    DocSchemaInfo docSchemaInfo = new DocSchemaInfo(Schemas.DEFAULT_SCHEMA_NAME, clusterService, docTableInfoFactory);
    CreateTableStatementAnalyzer analyzer = new CreateTableStatementAnalyzer(new Schemas(Settings.EMPTY, ImmutableMap.<String, SchemaInfo>of("doc", docSchemaInfo), clusterService, new DocSchemaInfoFactory(docTableInfoFactory)), new FulltextAnalyzerResolver(clusterService, new IndicesAnalysisService(Settings.EMPTY)), functions, new NumberOfShards(clusterService));
    Analysis analysis = new Analysis(SessionContext.SYSTEM_SESSION, ParameterContext.EMPTY, ParamTypeHints.EMPTY);
    CreateTableAnalyzedStatement analyzedStatement = analyzer.analyze((CreateTable) statement, analysis.parameterContext(), analysis.sessionContext());
    Settings.Builder settingsBuilder = Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0).put("index.version.created", org.elasticsearch.Version.CURRENT).put(analyzedStatement.tableParameter().settings());
    IndexMetaData indexMetaData = IndexMetaData.builder(analyzedStatement.tableIdent().name()).settings(settingsBuilder).putMapping(new MappingMetaData(Constants.DEFAULT_MAPPING_TYPE, analyzedStatement.mapping())).build();
    return newMeta(indexMetaData, analyzedStatement.tableIdent().name());
}
Also used : IndicesAnalysisService(org.elasticsearch.indices.analysis.IndicesAnalysisService) Statement(io.crate.sql.tree.Statement) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) Provider(org.elasticsearch.common.inject.Provider) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ClusterService(org.elasticsearch.cluster.ClusterService) TransportPutIndexTemplateAction(org.elasticsearch.action.admin.indices.template.put.TransportPutIndexTemplateAction) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) Settings(org.elasticsearch.common.settings.Settings) SchemaInfo(io.crate.metadata.table.SchemaInfo)

Example 2 with Statement

use of io.crate.sql.tree.Statement in project crate by crate.

the class TestStatementBuilder method testRepositoryStmtBuilder.

@Test
public void testRepositoryStmtBuilder() {
    printStatement("create repository my_repo type s3");
    printStatement("CREATE REPOSITORY \"myRepo\" TYPE \"fs\"");
    printStatement("CREATE REPOSITORY \"myRepo\" TYPE \"fs\" with (location='/mount/backups/my_backup', compress=True)");
    Statement statement = SqlParser.createStatement("CREATE REPOSITORY my_repo type s3 with (location='/mount/backups/my_backup')");
    assertThat(statement.toString(), is("CreateRepository{" + "repository=my_repo, " + "type=s3, " + "properties={location='/mount/backups/my_backup'}}"));
    printStatement("DROP REPOSITORY my_repo");
    statement = SqlParser.createStatement("DROP REPOSITORY \"myRepo\"");
    assertThat(statement.toString(), is("DropRepository{" + "repository=myRepo}"));
}
Also used : SetStatement(io.crate.sql.tree.SetStatement) CommitStatement(io.crate.sql.tree.CommitStatement) DeallocateStatement(io.crate.sql.tree.DeallocateStatement) BeginStatement(io.crate.sql.tree.BeginStatement) Statement(io.crate.sql.tree.Statement) KillStatement(io.crate.sql.tree.KillStatement) SetSessionAuthorizationStatement(io.crate.sql.tree.SetSessionAuthorizationStatement) Test(org.junit.Test)

Example 3 with Statement

use of io.crate.sql.tree.Statement in project crate by crate.

the class TestStatementBuilder method testKillAll.

@Test
public void testKillAll() {
    Statement stmt = SqlParser.createStatement("KILL ALL");
    assertThat(stmt, is(new KillStatement(null)));
}
Also used : KillStatement(io.crate.sql.tree.KillStatement) SetStatement(io.crate.sql.tree.SetStatement) CommitStatement(io.crate.sql.tree.CommitStatement) DeallocateStatement(io.crate.sql.tree.DeallocateStatement) BeginStatement(io.crate.sql.tree.BeginStatement) Statement(io.crate.sql.tree.Statement) KillStatement(io.crate.sql.tree.KillStatement) SetSessionAuthorizationStatement(io.crate.sql.tree.SetSessionAuthorizationStatement) Test(org.junit.Test)

Example 4 with Statement

use of io.crate.sql.tree.Statement in project crate by crate.

the class TestStatementBuilder method testRestoreSnapshotStmtBuilder.

@Test
public void testRestoreSnapshotStmtBuilder() {
    printStatement("RESTORE SNAPSHOT my_repo.my_snapshot ALL");
    printStatement("RESTORE SNAPSHOT my_repo.my_snapshot TABLE authors, books");
    printStatement("RESTORE SNAPSHOT my_repo.my_snapshot TABLE authors, books with (wait_for_completion=True)");
    printStatement("RESTORE SNAPSHOT my_repo.my_snapshot ALL with (wait_for_completion=True)");
    printStatement("RESTORE SNAPSHOT my_repo.my_snapshot TABLE authors PARTITION (year=2015, year=2014), books");
    Statement statement = SqlParser.createStatement("RESTORE SNAPSHOT my_repo.my_snapshot " + "TABLE authors PARTITION (year=2015, year=2014), books " + "WITH (wait_for_completion=True)");
    assertThat(statement.toString(), is("RestoreSnapshot{" + "name=my_repo.my_snapshot, " + "properties={wait_for_completion=true}, " + "tables=[" + "Table{only=false, authors, partitionProperties=[" + "" + "Assignment{column=\"year\", expressions=[2015]}, " + "Assignment{column=\"year\", expressions=[2014]}]}, " + "Table{only=false, books, partitionProperties=[]}]}"));
    statement = SqlParser.createStatement("RESTORE SNAPSHOT my_repo.my_snapshot ALL");
    assertThat(statement.toString(), is("RestoreSnapshot{" + "name=my_repo.my_snapshot, " + "properties={}, " + "tables=[]}"));
}
Also used : SetStatement(io.crate.sql.tree.SetStatement) CommitStatement(io.crate.sql.tree.CommitStatement) DeallocateStatement(io.crate.sql.tree.DeallocateStatement) BeginStatement(io.crate.sql.tree.BeginStatement) Statement(io.crate.sql.tree.Statement) KillStatement(io.crate.sql.tree.KillStatement) SetSessionAuthorizationStatement(io.crate.sql.tree.SetSessionAuthorizationStatement) Test(org.junit.Test)

Example 5 with Statement

use of io.crate.sql.tree.Statement in project crate by crate.

the class TestStatementBuilder method testCreateSnapshotStmtBuilder.

@Test
public void testCreateSnapshotStmtBuilder() {
    printStatement("CREATE SNAPSHOT my_repo.my_snapshot ALL");
    printStatement("CREATE SNAPSHOT my_repo.my_snapshot TABLE authors, books");
    printStatement("CREATE SNAPSHOT my_repo.my_snapshot TABLE authors, books with (wait_for_completion=True)");
    printStatement("CREATE SNAPSHOT my_repo.my_snapshot ALL with (wait_for_completion=True)");
    Statement statement = SqlParser.createStatement("CREATE SNAPSHOT my_repo.my_snapshot TABLE authors PARTITION (year=2015, year=2014), books");
    assertThat(statement.toString(), is("CreateSnapshot{" + "name=my_repo.my_snapshot, " + "properties={}, " + "tables=[Table{only=false, authors, partitionProperties=[" + "Assignment{column=\"year\", expressions=[2015]}, " + "Assignment{column=\"year\", expressions=[2014]}]}, " + "Table{only=false, books, partitionProperties=[]}]}"));
}
Also used : SetStatement(io.crate.sql.tree.SetStatement) CommitStatement(io.crate.sql.tree.CommitStatement) DeallocateStatement(io.crate.sql.tree.DeallocateStatement) BeginStatement(io.crate.sql.tree.BeginStatement) Statement(io.crate.sql.tree.Statement) KillStatement(io.crate.sql.tree.KillStatement) SetSessionAuthorizationStatement(io.crate.sql.tree.SetSessionAuthorizationStatement) Test(org.junit.Test)

Aggregations

Statement (io.crate.sql.tree.Statement)18 BeginStatement (io.crate.sql.tree.BeginStatement)8 CommitStatement (io.crate.sql.tree.CommitStatement)8 DeallocateStatement (io.crate.sql.tree.DeallocateStatement)8 KillStatement (io.crate.sql.tree.KillStatement)8 SetSessionAuthorizationStatement (io.crate.sql.tree.SetSessionAuthorizationStatement)8 SetStatement (io.crate.sql.tree.SetStatement)8 Test (org.junit.Test)8 Lists2 (io.crate.common.collections.Lists2)6 AnalyzedStatement (io.crate.analyze.AnalyzedStatement)5 ParamTypeHints (io.crate.analyze.ParamTypeHints)5 AccessControl (io.crate.auth.AccessControl)5 VisibleForTesting (io.crate.common.annotations.VisibleForTesting)5 Row (io.crate.data.Row)5 Symbol (io.crate.expression.symbol.Symbol)5 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)5 NodeContext (io.crate.metadata.NodeContext)5 SqlParser (io.crate.sql.parser.SqlParser)5 DataType (io.crate.types.DataType)5 ArrayList (java.util.ArrayList)5