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