Search in sources :

Example 96 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo 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 97 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo 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 98 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo in project crate by crate.

the class CountAggregationTest method test_count_on_object_with_not_null_sibling_not_use_DocValueAggregator.

@Test
public void test_count_on_object_with_not_null_sibling_not_use_DocValueAggregator() {
    Reference notNullSibling = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_Integer")), RowGranularity.DOC, DataTypes.INTEGER, 0, null);
    Reference countedObject = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_object")), RowGranularity.DOC, ObjectType.UNTYPED, 0, null);
    DocTableInfo sourceTable = mock(DocTableInfo.class);
    when(sourceTable.notNullColumns()).thenReturn(List.of(notNullSibling.column()));
    when(sourceTable.getReference(eq(notNullSibling.column()))).thenReturn(notNullSibling);
    assertHasDocValueAggregator(List.of(countedObject), sourceTable, null);
    verify(sourceTable, times(1)).notNullColumns();
    verify(sourceTable, times(0)).getReference(eq(notNullSibling.column()));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) DocTableInfo(io.crate.metadata.doc.DocTableInfo) Reference(io.crate.metadata.Reference) ReferenceIdent(io.crate.metadata.ReferenceIdent) Test(org.junit.Test)

Example 99 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo in project crate by crate.

the class CountAggregationTest method test_count_on_object_with_not_null_siblings_child_not_use_DocValueAggregator.

@Test
public void test_count_on_object_with_not_null_siblings_child_not_use_DocValueAggregator() {
    Reference notNullSibilingsChild = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_sibling", List.of("not_null_subcol"))), RowGranularity.DOC, DataTypes.STRING, 0, null);
    Reference sibling = new // unused
    Reference(new ReferenceIdent(null, new ColumnIdent("top_level_sibling")), RowGranularity.DOC, ObjectType.builder().setInnerType(notNullSibilingsChild.column().leafName(), notNullSibilingsChild.valueType()).build(), 0, null);
    Reference countedObject = new Reference(new ReferenceIdent(null, new ColumnIdent("top_level_object")), RowGranularity.DOC, ObjectType.UNTYPED, 0, null);
    DocTableInfo sourceTable = mock(DocTableInfo.class);
    when(sourceTable.notNullColumns()).thenReturn(List.of(notNullSibilingsChild.column()));
    when(sourceTable.getReference(eq(notNullSibilingsChild.column()))).thenReturn(notNullSibilingsChild);
    assertHasDocValueAggregator(List.of(countedObject), sourceTable, null);
    verify(sourceTable, times(1)).notNullColumns();
    verify(sourceTable, times(0)).getReference(eq(notNullSibilingsChild.column()));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) DocTableInfo(io.crate.metadata.doc.DocTableInfo) Reference(io.crate.metadata.Reference) ReferenceIdent(io.crate.metadata.ReferenceIdent) Test(org.junit.Test)

Example 100 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo 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)

Aggregations

DocTableInfo (io.crate.metadata.doc.DocTableInfo)127 Test (org.junit.Test)56 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)40 Symbol (io.crate.expression.symbol.Symbol)27 Reference (io.crate.metadata.Reference)27 SQLExecutor (io.crate.testing.SQLExecutor)25 RelationName (io.crate.metadata.RelationName)24 DocTableRelation (io.crate.analyze.relations.DocTableRelation)20 ColumnIdent (io.crate.metadata.ColumnIdent)20 TableInfo (io.crate.metadata.table.TableInfo)18 Assignments (io.crate.expression.symbol.Assignments)16 Row (io.crate.data.Row)14 PlannerContext (io.crate.planner.PlannerContext)13 Before (org.junit.Before)13 RowConsumer (io.crate.data.RowConsumer)12 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)12 PartitionName (io.crate.metadata.PartitionName)12 DependencyCarrier (io.crate.planner.DependencyCarrier)12 ArrayList (java.util.ArrayList)12 Map (java.util.Map)12