Search in sources :

Example 1 with CreateTable

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

the class MetaDataToASTNodeResolverTest method testBuildCreateTableColumns.

@Test
public void testBuildCreateTableColumns() throws Exception {
    TableIdent ident = new TableIdent("doc", "test");
    List<Reference> columns = ImmutableList.of(newReference(ident, "bools", DataTypes.BOOLEAN), newReference(ident, "bytes", DataTypes.BYTE), newReference(ident, "strings", DataTypes.STRING), newReference(ident, "shorts", DataTypes.SHORT), newReference(ident, "floats", DataTypes.FLOAT), newReference(ident, "doubles", DataTypes.DOUBLE), newReference(ident, "ints", DataTypes.INTEGER), newReference(ident, "longs", DataTypes.LONG), newReference(ident, "timestamp", DataTypes.TIMESTAMP), newReference(ident, "ip_addr", DataTypes.IP), newReference(ident, "arr_simple", new ArrayType(DataTypes.STRING)), newReference(ident, "arr_geo_point", new ArrayType(DataTypes.GEO_POINT)), newReference(ident, "arr_obj", new ArrayType(DataTypes.OBJECT), null, ColumnPolicy.STRICT, false), newReference(ident, "arr_obj", DataTypes.LONG, Arrays.asList("col_1"), null, false), newReference(ident, "arr_obj", DataTypes.STRING, Arrays.asList("col_2"), null, false), newReference(ident, "obj", DataTypes.OBJECT, null, ColumnPolicy.DYNAMIC, false), newReference(ident, "obj", DataTypes.LONG, Arrays.asList("col_1"), null, false), newReference(ident, "obj", DataTypes.STRING, Arrays.asList("col_2"), null, false));
    DocTableInfo tableInfo = new TestDocTableInfo(ident, 5, "0-all", columns, ImmutableList.<Reference>of(), ImmutableList.<GeneratedReference>of(), ImmutableMap.<ColumnIdent, IndexReference>of(), referencesMap(columns), ImmutableMap.<ColumnIdent, String>of(), ImmutableList.<ColumnIdent>of(), null, ImmutableMap.<String, Object>of(), ImmutableList.<ColumnIdent>of(), ColumnPolicy.DYNAMIC);
    CreateTable node = MetaDataToASTNodeResolver.resolveCreateTable(tableInfo);
    assertEquals("CREATE TABLE IF NOT EXISTS \"doc\".\"test\" (\n" + "   \"bools\" BOOLEAN,\n" + "   \"bytes\" BYTE,\n" + "   \"strings\" STRING,\n" + "   \"shorts\" SHORT,\n" + "   \"floats\" FLOAT,\n" + "   \"doubles\" DOUBLE,\n" + "   \"ints\" INTEGER,\n" + "   \"longs\" LONG,\n" + "   \"timestamp\" TIMESTAMP,\n" + "   \"ip_addr\" IP,\n" + "   \"arr_simple\" ARRAY(STRING),\n" + "   \"arr_geo_point\" ARRAY(GEO_POINT),\n" + "   \"arr_obj\" ARRAY(OBJECT (STRICT) AS (\n" + "      \"col_1\" LONG,\n" + "      \"col_2\" STRING\n" + "   )),\n" + "   \"obj\" OBJECT (DYNAMIC) AS (\n" + "      \"col_1\" LONG,\n" + "      \"col_2\" STRING\n" + "   )\n" + ")\n" + "CLUSTERED INTO 5 SHARDS\n" + "WITH (\n" + "   column_policy = 'dynamic',\n" + "   number_of_replicas = '0-all'\n" + ")", SqlFormatter.formatSql(node));
}
Also used : ArrayType(io.crate.types.ArrayType) DocTableInfo(io.crate.metadata.doc.DocTableInfo) CreateTable(io.crate.sql.tree.CreateTable) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with CreateTable

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

the class CreateTablePlan method executeOrFail.

@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
    BoundCreateTable boundCreateTable = bind(createTable, plannerContext.transactionContext(), dependencies.nodeContext(), params, subQueryResults, numberOfShards, schemas, dependencies.fulltextAnalyzerResolver());
    if (boundCreateTable.noOp()) {
        consumer.accept(InMemoryBatchIterator.empty(SENTINEL), null);
        return;
    }
    tableCreator.create(boundCreateTable).whenComplete(new OneRowActionListener<>(consumer, rCount -> new Row1(rCount == null ? -1 : rCount)));
}
Also used : AnalyzedColumnDefinition(io.crate.analyze.AnalyzedColumnDefinition) RelationName(io.crate.metadata.RelationName) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) SENTINEL(io.crate.data.SentinelRow.SENTINEL) GenericProperties(io.crate.sql.tree.GenericProperties) Function(java.util.function.Function) DependencyCarrier(io.crate.planner.DependencyCarrier) SymbolEvaluator(io.crate.analyze.SymbolEvaluator) Settings(org.elasticsearch.common.settings.Settings) Locale(java.util.Locale) OneRowActionListener(io.crate.execution.support.OneRowActionListener) BoundCreateTable(io.crate.analyze.BoundCreateTable) FulltextAnalyzerResolver(io.crate.metadata.FulltextAnalyzerResolver) Nullable(javax.annotation.Nullable) TableParameter(io.crate.analyze.TableParameter) CreateTable(io.crate.sql.tree.CreateTable) AnalyzedCreateTable(io.crate.analyze.AnalyzedCreateTable) NodeContext(io.crate.metadata.NodeContext) PartitionedBy(io.crate.sql.tree.PartitionedBy) TableCreator(io.crate.execution.ddl.tables.TableCreator) TablePropertiesAnalyzer(io.crate.analyze.TablePropertiesAnalyzer) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) ColumnIdent(io.crate.metadata.ColumnIdent) SubQueryAndParamBinder(io.crate.planner.operators.SubQueryAndParamBinder) TableParameters(io.crate.analyze.TableParameters) RowConsumer(io.crate.data.RowConsumer) AnalyzedTableElements(io.crate.analyze.AnalyzedTableElements) NumberOfShards(io.crate.analyze.NumberOfShards) ClusteredBy(io.crate.sql.tree.ClusteredBy) Row(io.crate.data.Row) Symbol(io.crate.expression.symbol.Symbol) PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan) SubQueryResults(io.crate.planner.operators.SubQueryResults) Optional(java.util.Optional) Schemas(io.crate.metadata.Schemas) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) Row1(io.crate.data.Row1) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) Row1(io.crate.data.Row1) BoundCreateTable(io.crate.analyze.BoundCreateTable)

Example 3 with CreateTable

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

the class MetadataToASTNodeResolverTest method testBuildCreateTableColumns.

@Test
public void testBuildCreateTableColumns() throws Exception {
    SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table doc.test (" + " bools boolean," + " bytes byte," + " strings string," + " shorts short," + " floats float," + " doubles double," + " ints integer," + " longs long," + " timestamp timestamp with time zone," + " ip_addr ip," + " arr_simple array(string)," + " arr_geo_point array(geo_point)," + " arr_obj array(object(strict) as (" + "  col_1 long," + "  col_2 string" + " ))," + " obj object as (" + "  col_1 long," + "  col_2 string" + " )" + ") " + "clustered into 5 shards " + "with (" + " number_of_replicas = '0-all'," + " \"merge.scheduler.max_thread_count\" = 1" + ")").build();
    DocTableInfo tableInfo = e.resolveTableInfo("doc.test");
    CreateTable node = MetadataToASTNodeResolver.resolveCreateTable(tableInfo);
    assertEquals("CREATE TABLE IF NOT EXISTS \"doc\".\"test\" (\n" + "   \"bools\" BOOLEAN,\n" + "   \"bytes\" CHAR,\n" + "   \"strings\" TEXT,\n" + "   \"shorts\" SMALLINT,\n" + "   \"floats\" REAL,\n" + "   \"doubles\" DOUBLE PRECISION,\n" + "   \"ints\" INTEGER,\n" + "   \"longs\" BIGINT,\n" + "   \"timestamp\" TIMESTAMP WITH TIME ZONE,\n" + "   \"ip_addr\" IP,\n" + "   \"arr_simple\" ARRAY(TEXT),\n" + "   \"arr_geo_point\" ARRAY(GEO_POINT),\n" + "   \"arr_obj\" ARRAY(OBJECT(STRICT) AS (\n" + "      \"col_1\" BIGINT,\n" + "      \"col_2\" TEXT\n" + "   )),\n" + "   \"obj\" OBJECT(DYNAMIC) AS (\n" + "      \"col_1\" BIGINT,\n" + "      \"col_2\" TEXT\n" + "   )\n" + ")\n" + "CLUSTERED INTO 5 SHARDS\n" + "WITH (\n" + "   \"allocation.max_retries\" = 5,\n" + "   \"blocks.metadata\" = false,\n" + "   \"blocks.read\" = false,\n" + "   \"blocks.read_only\" = false,\n" + "   \"blocks.read_only_allow_delete\" = false,\n" + "   \"blocks.write\" = false,\n" + "   codec = 'default',\n" + "   column_policy = 'strict',\n" + "   \"mapping.total_fields.limit\" = 1000,\n" + "   max_ngram_diff = 1,\n" + "   max_shingle_diff = 3,\n" + "   \"merge.scheduler.max_thread_count\" = 1,\n" + "   number_of_replicas = '0-all',\n" + "   \"routing.allocation.enable\" = 'all',\n" + "   \"routing.allocation.total_shards_per_node\" = -1,\n" + "   \"store.type\" = 'fs',\n" + "   \"translog.durability\" = 'REQUEST',\n" + "   \"translog.flush_threshold_size\" = 536870912,\n" + "   \"translog.sync_interval\" = 5000,\n" + "   \"unassigned.node_left.delayed_timeout\" = 60000,\n" + "   \"write.wait_for_active_shards\" = '1'\n" + ")", SqlFormatter.formatSql(node));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) SQLExecutor(io.crate.testing.SQLExecutor) CreateTable(io.crate.sql.tree.CreateTable) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 4 with CreateTable

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

the class MetadataToASTNodeResolverTest method testBuildCreateTableClusteredByPartitionedBy.

@Test
public void testBuildCreateTableClusteredByPartitionedBy() throws Exception {
    SQLExecutor e = SQLExecutor.builder(clusterService).addPartitionedTable("create table myschema.test (" + " id long," + " partition_column string," + " cluster_column string" + ") " + "partitioned by (partition_column) " + "clustered by (cluster_column) into 5 shards " + "with (" + " number_of_replicas = '0-all'," + " \"merge.scheduler.max_thread_count\" = 1" + ")").build();
    DocTableInfo tableInfo = e.resolveTableInfo("myschema.test");
    CreateTable node = MetadataToASTNodeResolver.resolveCreateTable(tableInfo);
    assertEquals("CREATE TABLE IF NOT EXISTS \"myschema\".\"test\" (\n" + "   \"id\" BIGINT,\n" + "   \"partition_column\" TEXT,\n" + "   \"cluster_column\" TEXT\n" + ")\n" + "CLUSTERED BY (\"cluster_column\") INTO 5 SHARDS\n" + "PARTITIONED BY (\"partition_column\")\n" + "WITH (\n" + "   \"allocation.max_retries\" = 5,\n" + "   \"blocks.metadata\" = false,\n" + "   \"blocks.read\" = false,\n" + "   \"blocks.read_only\" = false,\n" + "   \"blocks.read_only_allow_delete\" = false,\n" + "   \"blocks.write\" = false,\n" + "   codec = 'default',\n" + "   column_policy = 'strict',\n" + "   \"mapping.total_fields.limit\" = 1000,\n" + "   max_ngram_diff = 1,\n" + "   max_shingle_diff = 3,\n" + "   \"merge.scheduler.max_thread_count\" = 1,\n" + "   number_of_replicas = '0-all',\n" + "   \"routing.allocation.enable\" = 'all',\n" + "   \"routing.allocation.total_shards_per_node\" = -1,\n" + "   \"store.type\" = 'fs',\n" + "   \"translog.durability\" = 'REQUEST',\n" + "   \"translog.flush_threshold_size\" = 536870912,\n" + "   \"translog.sync_interval\" = 5000,\n" + "   \"unassigned.node_left.delayed_timeout\" = 60000,\n" + "   \"write.wait_for_active_shards\" = '1'\n" + ")", SqlFormatter.formatSql(node));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) SQLExecutor(io.crate.testing.SQLExecutor) CreateTable(io.crate.sql.tree.CreateTable) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 5 with CreateTable

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

the class MetaDataToASTNodeResolverTest method testBuildCreateTableParameters.

@Test
public void testBuildCreateTableParameters() throws Exception {
    TableIdent ident = new TableIdent("myschema", "test");
    List<Reference> columns = ImmutableList.of(newReference(ident, "id", DataTypes.LONG));
    ImmutableMap.Builder<String, Object> tableParameters = ImmutableMap.builder();
    tableParameters.put("refresh_interval", 10000L).put("param_array", new String[] { "foo", "bar" }).put("param_obj", new HashMap<String, Object>() {

        {
            put("foo", "bar");
            put("int", 42);
        }
    }).put("index.translog.flush_interval", 100L);
    DocTableInfo tableInfo = new TestDocTableInfo(ident, 5, "5", columns, ImmutableList.<Reference>of(), ImmutableList.<GeneratedReference>of(), ImmutableMap.<ColumnIdent, IndexReference>of(), referencesMap(columns), ImmutableMap.<ColumnIdent, String>of(), ImmutableList.<ColumnIdent>of(), null, tableParameters.build(), ImmutableList.<ColumnIdent>of(), ColumnPolicy.IGNORED);
    CreateTable node = MetaDataToASTNodeResolver.resolveCreateTable(tableInfo);
    assertEquals("CREATE TABLE IF NOT EXISTS \"myschema\".\"test\" (\n" + "   \"id\" LONG\n" + ")\n" + "CLUSTERED INTO 5 SHARDS\n" + "WITH (\n" + "   column_policy = 'ignored',\n" + "   \"index.translog.flush_interval\" = 100,\n" + "   number_of_replicas = '5',\n" + "   param_array = ['foo','bar'],\n" + "   param_obj = {\"foo\"= 'bar', \"int\"= 42},\n" + "   refresh_interval = 10000\n" + ")", SqlFormatter.formatSql(node));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) HashMap(java.util.HashMap) CreateTable(io.crate.sql.tree.CreateTable) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

CreateTable (io.crate.sql.tree.CreateTable)20 Test (org.junit.Test)14 DocTableInfo (io.crate.metadata.doc.DocTableInfo)13 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)8 SQLExecutor (io.crate.testing.SQLExecutor)7 CrateUnitTest (io.crate.test.integration.CrateUnitTest)6 RelationName (io.crate.metadata.RelationName)5 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)4 NodeContext (io.crate.metadata.NodeContext)4 AnalyzedCreateTable (io.crate.analyze.AnalyzedCreateTable)3 BoundCreateTable (io.crate.analyze.BoundCreateTable)3 NumberOfShards (io.crate.analyze.NumberOfShards)3 Row (io.crate.data.Row)3 Row1 (io.crate.data.Row1)3 Symbol (io.crate.expression.symbol.Symbol)3 ColumnIdent (io.crate.metadata.ColumnIdent)3 FulltextAnalyzerResolver (io.crate.metadata.FulltextAnalyzerResolver)3 Schemas (io.crate.metadata.Schemas)3 SubQueryResults (io.crate.planner.operators.SubQueryResults)3 Expression (io.crate.sql.tree.Expression)3