Search in sources :

Example 36 with SQLExecutor

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));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) SQLExecutor(io.crate.testing.SQLExecutor) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 37 with SQLExecutor

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));
}
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 38 with SQLExecutor

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));
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 39 with SQLExecutor

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);
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) SQLExecutor(io.crate.testing.SQLExecutor) RelationName(io.crate.metadata.RelationName) DocTableRelation(io.crate.analyze.relations.DocTableRelation) SqlExpressions(io.crate.testing.SqlExpressions) Before(org.junit.Before)

Example 40 with SQLExecutor

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)));
}
Also used : WhereClause(io.crate.analyze.WhereClause) TableStats(io.crate.statistics.TableStats) PlannerContext(io.crate.planner.PlannerContext) Merge(io.crate.planner.Merge) SQLExecutor(io.crate.testing.SQLExecutor) QueriedSelectRelation(io.crate.analyze.QueriedSelectRelation) ProjectionBuilder(io.crate.execution.dsl.projection.builder.ProjectionBuilder) AbstractTableRelation(io.crate.analyze.relations.AbstractTableRelation) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Aggregations

SQLExecutor (io.crate.testing.SQLExecutor)64 Test (org.junit.Test)55 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)54 DocTableInfo (io.crate.metadata.doc.DocTableInfo)24 RelationName (io.crate.metadata.RelationName)9 AnalyzedUpdateStatement (io.crate.analyze.AnalyzedUpdateStatement)8 Doc (io.crate.expression.reference.Doc)8 Assignments (io.crate.expression.symbol.Assignments)7 Symbols (io.crate.expression.symbol.Symbols)7 CreateTable (io.crate.sql.tree.CreateTable)7 TableStats (io.crate.statistics.TableStats)7 Before (org.junit.Before)7 Symbol (io.crate.expression.symbol.Symbol)6 ViewsMetadataTest (io.crate.metadata.view.ViewsMetadataTest)6 QualifiedName (io.crate.sql.tree.QualifiedName)6 DocTableRelation (io.crate.analyze.relations.DocTableRelation)5 SessionContext (io.crate.action.sql.SessionContext)4 AliasSymbol (io.crate.expression.symbol.AliasSymbol)4 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)3 PlannerContext (io.crate.planner.PlannerContext)3