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));
}
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)));
}
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));
}
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));
}
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));
}
Aggregations