lowka commented on code in PR #3342: URL: https://github.com/apache/ignite-3/pull/3342#discussion_r1512504924
########## modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItIndexesSystemViewTest.java: ########## @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.sql.engine; + +import static org.apache.ignite.internal.catalog.descriptors.CatalogIndexStatus.AVAILABLE; +import static org.apache.ignite.internal.sql.engine.schema.IgniteIndex.Type.HASH; +import static org.apache.ignite.internal.sql.engine.schema.IgniteIndex.Type.SORTED; + +import org.apache.ignite.internal.sql.BaseSqlIntegrationTest; +import org.apache.ignite.internal.sql.engine.schema.IgniteIndex.Collation; +import org.apache.ignite.internal.testframework.IgniteTestUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; + +/** End-to-end tests to verify indexes system view. */ +public class ItIndexesSystemViewTest extends BaseSqlIntegrationTest { + private static final int TABLE_ID = 7; + + private static final String TABLE_NAME = "TEST_TABLE"; + + private static final String COLUMN_NAME = "ID"; Review Comment: I think it is better use to obtain IDs via catalog instead of using constants > IgniteImpl ignite = CLUSTER.aliveNode(); CatalogManager catalogManager = ignite.catalogManager(); int version = catalogManager.latestCatalogVersion(); Catalog catalog = catalogManager.catalog(version); ... ########## modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItIndexesSystemViewTest.java: ########## @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.sql.engine; + +import static org.apache.ignite.internal.catalog.descriptors.CatalogIndexStatus.AVAILABLE; +import static org.apache.ignite.internal.sql.engine.schema.IgniteIndex.Type.HASH; +import static org.apache.ignite.internal.sql.engine.schema.IgniteIndex.Type.SORTED; + +import org.apache.ignite.internal.sql.BaseSqlIntegrationTest; +import org.apache.ignite.internal.sql.engine.schema.IgniteIndex.Collation; +import org.apache.ignite.internal.testframework.IgniteTestUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; + +/** End-to-end tests to verify indexes system view. */ +public class ItIndexesSystemViewTest extends BaseSqlIntegrationTest { + private static final int TABLE_ID = 7; + + private static final String TABLE_NAME = "TEST_TABLE"; + + private static final String COLUMN_NAME = "ID"; + + private static final int SCHEMA_ID = 0; + + private static final String SCHEMA_NAME = "PUBLIC"; + + private static final int LAST_INDEX_ID = 7; + + @Override + @BeforeAll + protected void beforeAll(TestInfo testInfo) { + super.beforeAll(testInfo); + + IgniteTestUtils.await(systemViewManager().completeRegistration()); + } + + @Test + public void multipleIndexes() { + sql(String.format("CREATE TABLE %S (%s INT PRIMARY KEY);", TABLE_NAME, COLUMN_NAME)); + + String hashIndexName = "TEST_INDEX_HASH"; + String sortedIndexName = "TEST_INDEX_SORTED"; + String primaryKeyIndexName = TABLE_NAME + "_PK"; + + sql(createIndexSql("TEST_INDEX_HASH", TABLE_NAME, HASH.name(), COLUMN_NAME)); + sql(createIndexSql("TEST_INDEX_SORTED", TABLE_NAME, "TREE", COLUMN_NAME + " DESC")); + + assertQuery("SELECT * FROM SYSTEM.INDEXES").returnRowCount(3).check(); + + assertQuery(selectFromIndexesSystemView(primaryKeyIndexName)).returns( + LAST_INDEX_ID + 1, + primaryKeyIndexName, + HASH.name(), + TABLE_ID, + TABLE_NAME, + SCHEMA_ID, + SCHEMA_NAME, + true, + COLUMN_NAME, + AVAILABLE.name() + ).check(); + + assertQuery(selectFromIndexesSystemView("TEST_INDEX_HASH")).returns( + LAST_INDEX_ID + 2, + hashIndexName, + HASH.name(), + TABLE_ID, + TABLE_NAME, + SCHEMA_ID, + SCHEMA_NAME, + false, + COLUMN_NAME, + AVAILABLE.name() + ).check(); + + assertQuery(selectFromIndexesSystemView("TEST_INDEX_SORTED")).returns( + LAST_INDEX_ID + 3, + sortedIndexName, + SORTED.name(), + TABLE_ID, + TABLE_NAME, + SCHEMA_ID, + SCHEMA_NAME, + false, + COLUMN_NAME + " " + Collation.DESC_NULLS_FIRST, Review Comment: I think it is better to not include NULLS FIRST / LAST options in output, because they are not supported at the moment. ########## modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItIndexesSystemViewTest.java: ########## @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.sql.engine; + +import static org.apache.ignite.internal.catalog.descriptors.CatalogIndexStatus.AVAILABLE; +import static org.apache.ignite.internal.sql.engine.schema.IgniteIndex.Type.HASH; +import static org.apache.ignite.internal.sql.engine.schema.IgniteIndex.Type.SORTED; + +import org.apache.ignite.internal.sql.BaseSqlIntegrationTest; +import org.apache.ignite.internal.sql.engine.schema.IgniteIndex.Collation; +import org.apache.ignite.internal.testframework.IgniteTestUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; + +/** End-to-end tests to verify indexes system view. */ +public class ItIndexesSystemViewTest extends BaseSqlIntegrationTest { + private static final int TABLE_ID = 7; + + private static final String TABLE_NAME = "TEST_TABLE"; + + private static final String COLUMN_NAME = "ID"; + + private static final int SCHEMA_ID = 0; + + private static final String SCHEMA_NAME = "PUBLIC"; + + private static final int LAST_INDEX_ID = 7; + + @Override + @BeforeAll + protected void beforeAll(TestInfo testInfo) { + super.beforeAll(testInfo); + + IgniteTestUtils.await(systemViewManager().completeRegistration()); + } + + @Test + public void multipleIndexes() { + sql(String.format("CREATE TABLE %S (%s INT PRIMARY KEY);", TABLE_NAME, COLUMN_NAME)); + + String hashIndexName = "TEST_INDEX_HASH"; + String sortedIndexName = "TEST_INDEX_SORTED"; + String primaryKeyIndexName = TABLE_NAME + "_PK"; + + sql(createIndexSql("TEST_INDEX_HASH", TABLE_NAME, HASH.name(), COLUMN_NAME)); + sql(createIndexSql("TEST_INDEX_SORTED", TABLE_NAME, "TREE", COLUMN_NAME + " DESC")); + + assertQuery("SELECT * FROM SYSTEM.INDEXES").returnRowCount(3).check(); + + assertQuery(selectFromIndexesSystemView(primaryKeyIndexName)).returns( + LAST_INDEX_ID + 1, + primaryKeyIndexName, + HASH.name(), + TABLE_ID, + TABLE_NAME, + SCHEMA_ID, + SCHEMA_NAME, + true, + COLUMN_NAME, + AVAILABLE.name() + ).check(); + + assertQuery(selectFromIndexesSystemView("TEST_INDEX_HASH")).returns( + LAST_INDEX_ID + 2, + hashIndexName, + HASH.name(), + TABLE_ID, + TABLE_NAME, + SCHEMA_ID, + SCHEMA_NAME, + false, + COLUMN_NAME, + AVAILABLE.name() + ).check(); + + assertQuery(selectFromIndexesSystemView("TEST_INDEX_SORTED")).returns( Review Comment: Perhaps we can add another column to this index, so it possible to see both ASC and DESC options. ########## modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogManagerImpl.java: ########## @@ -661,31 +672,90 @@ private SystemView<?> createSystemViewColumnsView() { return SystemViews.<ParentIdAwareDescriptor<CatalogTableColumnDescriptor>>clusterViewBuilder() .name("SYSTEM_VIEW_COLUMNS") - .addColumn("VIEW_ID", NativeTypes.INT32, entry -> entry.id) - .addColumn("NAME", NativeTypes.stringOf(SYSTEM_VIEW_STRING_COLUMN_LENGTH), entry -> entry.descriptor.name()) - .addColumn("TYPE", NativeTypes.stringOf(SYSTEM_VIEW_STRING_COLUMN_LENGTH), entry -> entry.descriptor.type().name()) - .addColumn("NULLABLE", NativeTypes.BOOLEAN, entry -> entry.descriptor.nullable()) - .addColumn("PRECISION", NativeTypes.INT32, entry -> entry.descriptor.precision()) - .addColumn("SCALE", NativeTypes.INT32, entry -> entry.descriptor.scale()) - .addColumn("LENGTH", NativeTypes.INT32, entry -> entry.descriptor.length()) + .addColumn("VIEW_ID", INT32, entry -> entry.id) + .addColumn("NAME", stringOf(SYSTEM_VIEW_STRING_COLUMN_LENGTH), entry -> entry.descriptor.name()) + .addColumn("TYPE", stringOf(SYSTEM_VIEW_STRING_COLUMN_LENGTH), entry -> entry.descriptor.type().name()) + .addColumn("NULLABLE", BOOLEAN, entry -> entry.descriptor.nullable()) + .addColumn("PRECISION", INT32, entry -> entry.descriptor.precision()) + .addColumn("SCALE", INT32, entry -> entry.descriptor.scale()) + .addColumn("LENGTH", INT32, entry -> entry.descriptor.length()) .dataProvider(viewDataPublisher) .build(); } private SystemView<?> createSystemViewZonesView() { return SystemViews.<CatalogZoneDescriptor>clusterViewBuilder() .name("ZONES") - .addColumn("NAME", NativeTypes.STRING, CatalogZoneDescriptor::name) - .addColumn("PARTITIONS", NativeTypes.INT32, CatalogZoneDescriptor::partitions) - .addColumn("REPLICAS", NativeTypes.INT32, CatalogZoneDescriptor::replicas) - .addColumn("DATA_NODES_AUTO_ADJUST_SCALE_UP", NativeTypes.INT32, CatalogZoneDescriptor::dataNodesAutoAdjustScaleUp) - .addColumn("DATA_NODES_AUTO_ADJUST_SCALE_DOWN", NativeTypes.INT32, CatalogZoneDescriptor::dataNodesAutoAdjustScaleDown) - .addColumn("DATA_NODES_FILTER", NativeTypes.STRING, CatalogZoneDescriptor::filter) - .addColumn("IS_DEFAULT_ZONE", NativeTypes.BOOLEAN, isDefaultZone()) + .addColumn("NAME", STRING, CatalogZoneDescriptor::name) + .addColumn("PARTITIONS", INT32, CatalogZoneDescriptor::partitions) + .addColumn("REPLICAS", INT32, CatalogZoneDescriptor::replicas) + .addColumn("DATA_NODES_AUTO_ADJUST_SCALE_UP", INT32, CatalogZoneDescriptor::dataNodesAutoAdjustScaleUp) + .addColumn("DATA_NODES_AUTO_ADJUST_SCALE_DOWN", INT32, CatalogZoneDescriptor::dataNodesAutoAdjustScaleDown) + .addColumn("DATA_NODES_FILTER", STRING, CatalogZoneDescriptor::filter) + .addColumn("IS_DEFAULT_ZONE", BOOLEAN, isDefaultZone()) .dataProvider(SubscriptionUtils.fromIterable(() -> catalog(latestCatalogVersion()).zones().iterator())) .build(); } + private SystemView<?> createSystemViewIndexesView() { + return SystemViews.<CatalogIndexViewDescriptor>clusterViewBuilder() + .name("INDEXES") + .addColumn("INDEX_ID", INT32, CatalogIndexViewDescriptor::id) + .addColumn("INDEX_NAME", STRING, CatalogIndexViewDescriptor::name) + .addColumn("TABLE_ID", INT32, CatalogIndexViewDescriptor::tableId) + .addColumn("TABLE_NAME", STRING, CatalogIndexViewDescriptor::tableName) + .addColumn("SCHEMA_ID", INT32, CatalogIndexViewDescriptor::schemaId) + .addColumn("SCHEMA_NAME", STRING, CatalogIndexViewDescriptor::schemaName) + .addColumn("TYPE", STRING, CatalogIndexViewDescriptor::type) + .addColumn("UNIQUE", BOOLEAN, CatalogIndexViewDescriptor::unique) + .addColumn("COLUMNS", STRING, CatalogIndexViewDescriptor::columnsString) + .addColumn("STATUS", STRING, CatalogIndexViewDescriptor::status) + .dataProvider(getIndexesDataProvider()) + .build(); + } + + private Publisher<CatalogIndexViewDescriptor> getIndexesDataProvider() { + return SubscriptionUtils.fromIterable(() -> + catalog(latestCatalogVersion()) + .indexes() + .stream() + .filter(it -> it.status() != STOPPING) + .map(this::toCatalogIndexView) + .iterator() + ); + } + + private CatalogIndexViewDescriptor toCatalogIndexView(CatalogIndexDescriptor index) { + Catalog catalog = catalog(latestCatalogVersion()); + CatalogTableDescriptor table = catalog.table(index.tableId()); + + return new CatalogIndexViewDescriptor( + index.id(), + index.name(), + index.indexType().name(), + index.tableId(), + table.name(), + table.schemaId(), + catalog.schema(table.schemaId()).name(), + index.unique(), + getIndexColumns(index), + index.status().name() + ); + } + + private static String getIndexColumns(CatalogIndexDescriptor indexDescriptor) { + return indexDescriptor.indexType() == CatalogIndexDescriptorType.HASH Review Comment: I think it would be better to move this code that formats columns to CatalogIndexViewDescriptor. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
