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());
}
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}"));
}
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)));
}
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=[]}"));
}
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=[]}]}"));
}
Aggregations