rpuch commented on code in PR #3342:
URL: https://github.com/apache/ignite-3/pull/3342#discussion_r1512487913
##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogManagerImpl.java:
##########
@@ -437,7 +447,8 @@ public List<SystemView<?>> systemViews() {
return List.of(
createSystemViewsView(),
createSystemViewColumnsView(),
- createSystemViewZonesView()
+ createSystemViewZonesView(),
+ createSystemViewIndexesView()
Review Comment:
```suggestion
createZonesView(),
createIndexesView()
```
##########
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
+ ? ((CatalogHashIndexDescriptor) indexDescriptor)
+ .columns()
+ .stream()
+ .collect(Collectors.joining(", "))
Review Comment:
Please import `Collectors.joining()` statically
##########
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())
Review Comment:
We should take currently active and not the latest version (as the latest
version might still be 'in the future'). This should probably be true for every
system view defined here.
##########
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)
Review Comment:
```suggestion
.filter(it -> it.status().isAlive())
```
##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/descriptors/CatalogIndexViewDescriptor.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.catalog.descriptors;
+
+/** Descriptor for the index system view. */
+public class CatalogIndexViewDescriptor {
+ /** Index ID. */
+ private final int id;
+
+ /** Index name. */
+ private final String name;
+
+ /** index type. */
Review Comment:
```suggestion
/** index type (sorted/hash/...). */
```
##########
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;
Review Comment:
We should not depend on concrete IDs of objects we create in tests. The IDs
can always be found in the Catalog after the entity is created.
##########
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());
Review Comment:
You already have the correct `Catalog` at the call site, please pass it here
and use it. Otherwise, different catalogs might be obtained due to a race,
hence an inconsistent data view is possible.
##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/descriptors/CatalogIndexViewDescriptor.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.catalog.descriptors;
+
+/** Descriptor for the index system view. */
Review Comment:
```suggestion
/** Descriptor for the indexes system view. */
```
##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItIgniteNodeRestartTest.java:
##########
@@ -1421,7 +1421,7 @@ public void createTableCallOnMultipleNodesTest(boolean
populateStableAssignments
}
// Assume that the table id will always be 7 for the test table. There
is an assertion below to check this is true.
- int tableId = 7;
+ int tableId = 8;
Review Comment:
Do we really need to rely on IDs here? If we still need, please introduce a
constant.
##########
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,
+ AVAILABLE.name()
+ ).check();
+ }
+
+ private static String createIndexSql(String name, String tableName, String
type, String columnString) {
+ return String.format("CREATE INDEX %s ON %s USING %S (%s);", name,
tableName, type, columnString);
+ }
+
+ private static String selectFromIndexesSystemView(String indexName) {
+ String sqlFormat = "SELECT INDEX_ID, INDEX_NAME, TYPE, TABLE_ID,
TABLE_NAME, SCHEMA_ID, SCHEMA_NAME, \"UNIQUE\", COLUMNS, STATUS "
Review Comment:
Let's rename the column to `IS_UNIQUE`, it's not cool if we must quote it
every time
##########
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) {
Review Comment:
Let's move this method elsewhere, like to `CatalogIndexViewDescriptor` as it
seems pretty specific for this view logic
--
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]