use of io.crate.testing.SQLExecutor in project crate by crate.
the class MetadataToASTNodeResolverTest method testBuildCreateTableColumnDefaultClause.
@Test
public void testBuildCreateTableColumnDefaultClause() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable("CREATE TABLE test (" + " col1 TEXT," + " col2 INTEGER DEFAULT 1 + 1," + " col3 TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP(3)," + " col4 TIMESTAMP WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP(3)" + ") with (" + " \"merge.scheduler.max_thread_count\" = 1" + ")").build();
DocTableInfo tableInfo = e.resolveTableInfo("test");
CreateTable<?> node = MetadataToASTNodeResolver.resolveCreateTable(tableInfo);
assertEquals("CREATE TABLE IF NOT EXISTS \"doc\".\"test\" (\n" + " \"col1\" TEXT,\n" + " \"col2\" INTEGER DEFAULT 2,\n" + " \"col3\" TIMESTAMP WITH TIME ZONE DEFAULT current_timestamp(3),\n" + " \"col4\" TIMESTAMP WITHOUT TIME ZONE DEFAULT _cast(current_timestamp(3), 'timestamp without time zone')\n" + ")\n" + "CLUSTERED INTO 4 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-1',\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.testing.SQLExecutor 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));
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class ColumnsIterableTest method test_bit_type_has_character_maximum_length_set.
@Test
public void test_bit_type_has_character_maximum_length_set() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table bit_table (xs bit(12))").build();
var columns = new InformationSchemaIterables.ColumnsIterable(e.resolveTableInfo("bit_table"));
var contexts = StreamSupport.stream(columns.spliterator(), false).toList();
assertThat(contexts.get(0).characterMaximumLength(), is(12));
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class UserDefinedFunctionsTest method prepare.
@Before
public void prepare() throws Exception {
SQLExecutor sqlExecutor = SQLExecutor.builder(clusterService).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
DocTableInfo users = sqlExecutor.schemas().getTableInfo(new RelationName("doc", "users"));
sqlExpressions = new SqlExpressions(Map.of(users.ident(), new DocTableRelation(users)));
udfService.registerLanguage(DUMMY_LANG);
}
use of io.crate.testing.SQLExecutor in project crate by crate.
the class LimitTest method testLimitOnLimitOperator.
@Test
public void testLimitOnLimitOperator() throws Exception {
SQLExecutor e = SQLExecutor.builder(clusterService, 2, RandomizedTest.getRandom(), List.of()).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
QueriedSelectRelation queriedDocTable = e.analyze("select name from users");
LogicalPlan plan = Limit.create(Limit.create(Collect.create(((AbstractTableRelation<?>) queriedDocTable.from().get(0)), queriedDocTable.outputs(), new WhereClause(queriedDocTable.where()), new TableStats(), null), Literal.of(10L), Literal.of(5L)), Literal.of(20L), Literal.of(7L));
assertThat(plan, isPlan("Limit[20::bigint;7::bigint]\n" + " └ Limit[10::bigint;5::bigint]\n" + " └ Collect[doc.users | [name] | true]"));
PlannerContext ctx = e.getPlannerContext(clusterService.state());
Merge merge = (Merge) plan.build(ctx, Set.of(), new ProjectionBuilder(e.nodeCtx), TopN.NO_LIMIT, 0, null, null, Row.EMPTY, SubQueryResults.EMPTY);
io.crate.planner.node.dql.Collect collect = (io.crate.planner.node.dql.Collect) merge.subPlan();
assertThat(collect.collectPhase().projections(), contains(ProjectionMatchers.isTopN(15, 0)));
// noinspection unchecked
assertThat(merge.mergePhase().projections(), contains(ProjectionMatchers.isTopN(10, 5), ProjectionMatchers.isTopN(20, 7)));
}
Aggregations