use of io.crate.sql.tree.CreateTable in project crate by crate.
the class MetadataToASTNodeResolverTest method testBuildCreateTableIndexes.
@Test
public void testBuildCreateTableIndexes() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table myschema.test (" + " id long," + " col_a string," + " col_b string index using fulltext," + " col_c string index off," + " col_d object as (" + " a string" + " )," + " index col_a_col_b_ft using fulltext (col_a, col_b) with (" + " analyzer= 'english'" + " )," + " index col_d_a_ft using fulltext (col_d['a']) with (" + " analyzer= 'custom_analyzer'" + " )," + " index col_a_col_b_plain using plain (col_a, col_b)" + ") " + "clustered 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" + " \"col_a\" TEXT,\n" + " \"col_b\" TEXT INDEX USING FULLTEXT WITH (\n" + " analyzer = 'standard'\n" + " ),\n" + " \"col_c\" TEXT INDEX OFF,\n" + " \"col_d\" OBJECT(DYNAMIC) AS (\n" + " \"a\" TEXT\n" + " ),\n" + " INDEX \"col_a_col_b_ft\" USING FULLTEXT (\"col_a\", \"col_b\") WITH (\n" + " analyzer = 'english'\n" + " ),\n" + " INDEX \"col_d_a_ft\" USING FULLTEXT (\"col_d\"['a']) WITH (\n" + " analyzer = 'custom_analyzer'\n" + " ),\n" + " INDEX \"col_a_col_b_plain\" USING FULLTEXT (\"col_a\", \"col_b\") WITH (\n" + " analyzer = 'keyword'\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 testBuildCreateTableCheckConstraints.
@Test
public void testBuildCreateTableCheckConstraints() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table doc.test (" + " floats float constraint test_floats_check check (floats != -1)," + " shorts short," + " constraint test_shorts_check check (shorts >= 0)" + ") " + "clustered into 5 shards " + "with (" + " number_of_replicas = '0-all'" + ")").build();
DocTableInfo tableInfo = e.resolveTableInfo("doc.test");
CreateTable node = MetadataToASTNodeResolver.resolveCreateTable(tableInfo);
assertEquals("CREATE TABLE IF NOT EXISTS \"doc\".\"test\" (\n" + " \"floats\" REAL,\n" + " \"shorts\" SMALLINT,\n" + " CONSTRAINT test_floats_check CHECK(\"floats\" <> - 1),\n" + " CONSTRAINT test_shorts_check CHECK(\"shorts\" >= 0)\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" + " 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 testBuildCreateTableNotNull.
@Test
public void testBuildCreateTableNotNull() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table myschema.test (" + " col_a string," + " col_b string not null index using fulltext," + " primary key (col_a)" + ") " + "clustered into 5 shards " + "with (" + " number_of_replicas = '0-all'," + " column_policy = 'strict'," + " \"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" + " \"col_a\" TEXT,\n" + " \"col_b\" TEXT NOT NULL INDEX USING FULLTEXT WITH (\n" + " analyzer = 'standard'\n" + " ),\n" + " PRIMARY KEY (\"col_a\")\n" + ")\n" + "CLUSTERED BY (\"col_a\") 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 testBuildCreateTableStorageDefinitions.
@Test
public void testBuildCreateTableStorageDefinitions() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table myschema.test (" + " s string storage with (columnstore =false)" + ") " + "clustered into 5 shards " + "with (" + " number_of_replicas = '0-all'," + " column_policy = 'strict'," + " \"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" + " \"s\" TEXT STORAGE WITH (\n" + " columnstore = false\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 testBuildCreateTablePrimaryKey.
@Test
public void testBuildCreateTablePrimaryKey() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table myschema.test (" + " pk_col_one long," + " pk_col_two long," + " primary key (pk_col_one, pk_col_two)" + ") " + "clustered into 5 shards " + "with (" + " number_of_replicas = '0-all'," + " column_policy = 'strict'," + " \"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" + " \"pk_col_one\" BIGINT,\n" + " \"pk_col_two\" BIGINT,\n" + " PRIMARY KEY (\"pk_col_one\", \"pk_col_two\")\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));
}
Aggregations