You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by tk...@apache.org on 2023/06/23 11:50:12 UTC
[ignite-3] branch main updated: IGNITE-19799 Refactoring classes associated with the catalog (#2243)
This is an automated email from the ASF dual-hosted git repository.
tkalkirill pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new e674c16add IGNITE-19799 Refactoring classes associated with the catalog (#2243)
e674c16add is described below
commit e674c16add0333815c3ef0b03ed09fbaf1657907
Author: Kirill Tkalenko <tk...@yandex.ru>
AuthorDate: Fri Jun 23 14:50:06 2023 +0300
IGNITE-19799 Refactoring classes associated with the catalog (#2243)
---
.../java/org/apache/ignite/sql/SqlException.java | 13 +
.../ignite/internal/catalog/CatalogService.java | 2 +-
.../internal/catalog/CatalogServiceImpl.java | 523 ++++++++++-----------
.../commands/AbstractIndexCommandParams.java | 41 ++
.../internal/catalog/commands/CatalogUtils.java | 33 +-
.../catalog/commands/CreateHashIndexParams.java | 22 -
.../catalog/commands/CreateSortedIndexParams.java | 41 --
.../internal/catalog/storage/AlterColumnEntry.java | 4 +-
.../internal/catalog/storage/DropColumnsEntry.java | 4 +-
.../internal/catalog/storage/DropIndexEntry.java | 4 +-
.../internal/catalog/storage/DropTableEntry.java | 4 +-
.../internal/catalog/storage/NewColumnsEntry.java | 4 +-
.../internal/catalog/storage/NewIndexEntry.java | 4 +-
.../internal/catalog/storage/NewTableEntry.java | 4 +-
.../internal/catalog/CatalogServiceSelfTest.java | 30 +-
.../sql/engine/schema/CatalogSqlSchemaManager.java | 6 +-
.../engine/schema/CatalogSqlSchemaManagerTest.java | 9 +-
17 files changed, 367 insertions(+), 381 deletions(-)
diff --git a/modules/api/src/main/java/org/apache/ignite/sql/SqlException.java b/modules/api/src/main/java/org/apache/ignite/sql/SqlException.java
index f1ca6e96b5..ab38dcf0e7 100644
--- a/modules/api/src/main/java/org/apache/ignite/sql/SqlException.java
+++ b/modules/api/src/main/java/org/apache/ignite/sql/SqlException.java
@@ -19,6 +19,7 @@ package org.apache.ignite.sql;
import java.util.UUID;
import org.apache.ignite.lang.IgniteException;
+import org.apache.ignite.lang.IgniteStringFormatter;
/**
* SQL exception base class.
@@ -97,4 +98,16 @@ public class SqlException extends IgniteException {
public SqlException(UUID traceId, int code, String message, Throwable cause) {
super(traceId, code, message, cause);
}
+
+ /**
+ * Constructor.
+ *
+ * @param code Full error code.
+ * @param messagePattern Error message pattern.
+ * @param params Error message params.
+ * @see IgniteStringFormatter#format(String, Object...)
+ */
+ public SqlException(int code, String messagePattern, Object... params) {
+ this(code, IgniteStringFormatter.format(messagePattern, params));
+ }
}
diff --git a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogService.java b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogService.java
index 7703222f98..b078bbd3c5 100644
--- a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogService.java
+++ b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogService.java
@@ -36,7 +36,7 @@ import org.jetbrains.annotations.Nullable;
* <p>TBD: events
*/
public interface CatalogService {
- String PUBLIC = "PUBLIC";
+ String DEFAULT_SCHEMA_NAME = "PUBLIC";
String DEFAULT_ZONE_NAME = "Default";
diff --git a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogServiceImpl.java b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogServiceImpl.java
index 010fa208ee..66ea991585 100644
--- a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogServiceImpl.java
+++ b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogServiceImpl.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.catalog;
import static java.util.concurrent.CompletableFuture.completedFuture;
import static java.util.concurrent.CompletableFuture.failedFuture;
+import static java.util.stream.Collectors.joining;
import static org.apache.ignite.internal.catalog.commands.CreateZoneParams.INFINITE_TIMER_VALUE;
import static org.apache.ignite.lang.ErrorGroups.Sql.UNSUPPORTED_DDL_OPERATION_ERR;
@@ -33,7 +34,6 @@ import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.function.Predicate;
-import java.util.stream.Collectors;
import org.apache.ignite.internal.catalog.commands.AlterColumnParams;
import org.apache.ignite.internal.catalog.commands.AlterTableAddColumnParams;
import org.apache.ignite.internal.catalog.commands.AlterTableDropColumnParams;
@@ -48,6 +48,7 @@ import org.apache.ignite.internal.catalog.commands.DropIndexParams;
import org.apache.ignite.internal.catalog.commands.DropTableParams;
import org.apache.ignite.internal.catalog.commands.DropZoneParams;
import org.apache.ignite.internal.catalog.commands.RenameZoneParams;
+import org.apache.ignite.internal.catalog.descriptors.CatalogHashIndexDescriptor;
import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor;
import org.apache.ignite.internal.catalog.descriptors.CatalogSchemaDescriptor;
import org.apache.ignite.internal.catalog.descriptors.CatalogTableColumnDescriptor;
@@ -86,9 +87,9 @@ import org.apache.ignite.lang.ErrorGroups.Common;
import org.apache.ignite.lang.ErrorGroups.DistributionZones;
import org.apache.ignite.lang.ErrorGroups.Sql;
import org.apache.ignite.lang.IgniteInternalException;
-import org.apache.ignite.lang.IgniteStringFormatter;
import org.apache.ignite.lang.IndexAlreadyExistsException;
import org.apache.ignite.lang.IndexNotFoundException;
+import org.apache.ignite.lang.SchemaNotFoundException;
import org.apache.ignite.lang.TableAlreadyExistsException;
import org.apache.ignite.lang.TableNotFoundException;
import org.apache.ignite.sql.ColumnType;
@@ -137,7 +138,6 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
this.delayDurationMs = delayDurationMs;
}
- /** {@inheritDoc} */
@Override
public void start() {
int objectIdGen = 0;
@@ -145,13 +145,14 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
// TODO: IGNITE-19082 Move default schema objects initialization to cluster init procedure.
CatalogSchemaDescriptor schemaPublic = new CatalogSchemaDescriptor(
objectIdGen++,
- "PUBLIC",
+ DEFAULT_SCHEMA_NAME,
new CatalogTableDescriptor[0],
new CatalogIndexDescriptor[0]
);
+
CatalogZoneDescriptor defaultZone = new CatalogZoneDescriptor(
objectIdGen++,
- CatalogService.DEFAULT_ZONE_NAME,
+ DEFAULT_ZONE_NAME,
25,
1,
INFINITE_TIMER_VALUE,
@@ -159,6 +160,7 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
INFINITE_TIMER_VALUE,
CreateZoneParams.DEFAULT_FILTER
);
+
registerCatalog(new Catalog(0, 0L, objectIdGen, List.of(defaultZone), List.of(schemaPublic)));
updateLog.registerUpdateHandler(new OnUpdateHandlerImpl());
@@ -166,37 +168,31 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
updateLog.start();
}
- /** {@inheritDoc} */
@Override
public void stop() throws Exception {
updateLog.stop();
}
- /** {@inheritDoc} */
@Override
public CatalogTableDescriptor table(String tableName, long timestamp) {
- return catalogAt(timestamp).schema(CatalogService.PUBLIC).table(tableName);
+ return catalogAt(timestamp).schema(DEFAULT_SCHEMA_NAME).table(tableName);
}
- /** {@inheritDoc} */
@Override
public CatalogTableDescriptor table(int tableId, long timestamp) {
return catalogAt(timestamp).table(tableId);
}
- /** {@inheritDoc} */
@Override
public CatalogIndexDescriptor index(String indexName, long timestamp) {
- return catalogAt(timestamp).schema(CatalogService.PUBLIC).index(indexName);
+ return catalogAt(timestamp).schema(DEFAULT_SCHEMA_NAME).index(indexName);
}
- /** {@inheritDoc} */
@Override
public CatalogIndexDescriptor index(int indexId, long timestamp) {
return catalogAt(timestamp).index(indexId);
}
- /** {@inheritDoc} */
@Override
public @Nullable CatalogSchemaDescriptor schema(int version) {
Catalog catalog = catalog(version);
@@ -205,10 +201,9 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
return null;
}
- return catalog.schema(CatalogService.PUBLIC);
+ return catalog.schema(DEFAULT_SCHEMA_NAME);
}
- /** {@inheritDoc} */
@Override
public @Nullable CatalogSchemaDescriptor schema(String schemaName, int version) {
Catalog catalog = catalog(version);
@@ -217,34 +212,29 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
return null;
}
- return catalog.schema(schemaName == null ? CatalogService.PUBLIC : schemaName);
+ return catalog.schema(schemaName == null ? DEFAULT_SCHEMA_NAME : schemaName);
}
- /** {@inheritDoc} */
@Override
public CatalogZoneDescriptor zone(String zoneName, long timestamp) {
return catalogAt(timestamp).zone(zoneName);
}
- /** {@inheritDoc} */
@Override
public CatalogZoneDescriptor zone(int zoneId, long timestamp) {
return catalogAt(timestamp).zone(zoneId);
}
- /** {@inheritDoc} */
@Override
public @Nullable CatalogSchemaDescriptor activeSchema(long timestamp) {
- return catalogAt(timestamp).schema(CatalogService.PUBLIC);
+ return catalogAt(timestamp).schema(DEFAULT_SCHEMA_NAME);
}
- /** {@inheritDoc} */
@Override
public @Nullable CatalogSchemaDescriptor activeSchema(String schemaName, long timestamp) {
- return catalogAt(timestamp).schema(schemaName == null ? CatalogService.PUBLIC : schemaName);
+ return catalogAt(timestamp).schema(schemaName == null ? DEFAULT_SCHEMA_NAME : schemaName);
}
- /** {@inheritDoc} */
@Override
public int activeCatalogVersion(long timestamp) {
return catalogAt(timestamp).version();
@@ -264,29 +254,18 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
return entry.getValue();
}
- /** {@inheritDoc} */
@Override
public CompletableFuture<Void> createTable(CreateTableParams params) {
return saveUpdate(catalog -> {
- String schemaName = Objects.requireNonNullElse(params.schemaName(), CatalogService.PUBLIC);
-
- CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(schemaName), "No schema found: " + schemaName);
+ CatalogSchemaDescriptor schema = getSchema(catalog, params.schemaName());
if (schema.table(params.tableName()) != null) {
- throw new TableAlreadyExistsException(schemaName, params.tableName());
+ throw new TableAlreadyExistsException(schema.name(), params.tableName());
}
- params.columns().stream().map(ColumnParams::name).filter(Predicate.not(new HashSet<>()::add))
- .findAny().ifPresent(columnName -> {
- throw new IgniteInternalException(
- ErrorGroups.Index.INVALID_INDEX_DEFINITION_ERR, "Can't create table with duplicate columns: "
- + params.columns().stream().map(ColumnParams::name).collect(Collectors.joining(", "))
- );
- });
-
- String zoneName = Objects.requireNonNullElse(params.zone(), CatalogService.DEFAULT_ZONE_NAME);
+ validateCreateTableParams(params);
- CatalogZoneDescriptor zone = Objects.requireNonNull(catalog.zone(zoneName), "No zone found: " + zoneName);
+ CatalogZoneDescriptor zone = getZone(catalog, Objects.requireNonNullElse(params.zone(), DEFAULT_ZONE_NAME));
CatalogTableDescriptor table = CatalogUtils.fromParams(catalog.objectIdGenState(), zone.id(), params);
@@ -297,19 +276,12 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
});
}
- /** {@inheritDoc} */
@Override
public CompletableFuture<Void> dropTable(DropTableParams params) {
return saveUpdate(catalog -> {
- String schemaName = Objects.requireNonNullElse(params.schemaName(), CatalogService.PUBLIC);
-
- CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(schemaName), "No schema found: " + schemaName);
+ CatalogSchemaDescriptor schema = getSchema(catalog, params.schemaName());
- CatalogTableDescriptor table = schema.table(params.tableName());
-
- if (table == null) {
- throw new TableNotFoundException(schemaName, params.tableName());
- }
+ CatalogTableDescriptor table = getTable(schema, params.tableName());
List<UpdateEntry> updateEntries = new ArrayList<>();
@@ -323,7 +295,6 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
});
}
- /** {@inheritDoc} */
@Override
public CompletableFuture<Void> addColumn(AlterTableAddColumnParams params) {
if (params.columns().isEmpty()) {
@@ -331,15 +302,9 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
}
return saveUpdate(catalog -> {
- String schemaName = Objects.requireNonNullElse(params.schemaName(), CatalogService.PUBLIC);
-
- CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(schemaName), "No schema found: " + schemaName);
+ CatalogSchemaDescriptor schema = getSchema(catalog, params.schemaName());
- CatalogTableDescriptor table = schema.table(params.tableName());
-
- if (table == null) {
- throw new TableNotFoundException(schemaName, params.tableName());
- }
+ CatalogTableDescriptor table = getTable(schema, params.tableName());
List<CatalogTableColumnDescriptor> columnDescriptors = new ArrayList<>();
@@ -357,7 +322,6 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
});
}
- /** {@inheritDoc} */
@Override
public CompletableFuture<Void> dropColumn(AlterTableDropColumnParams params) {
if (params.columns().isEmpty()) {
@@ -365,39 +329,11 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
}
return saveUpdate(catalog -> {
- String schemaName = Objects.requireNonNullElse(params.schemaName(), CatalogService.PUBLIC);
+ CatalogSchemaDescriptor schema = getSchema(catalog, params.schemaName());
- CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(schemaName), "No schema found: " + schemaName);
+ CatalogTableDescriptor table = getTable(schema, params.tableName());
- CatalogTableDescriptor table = schema.table(params.tableName());
-
- if (table == null) {
- throw new TableNotFoundException(schemaName, params.tableName());
- }
-
- for (String columnName : params.columns()) {
- if (table.column(columnName) == null) {
- throw new ColumnNotFoundException(columnName);
- }
- if (table.isPrimaryKeyColumn(columnName)) {
- throw new SqlException(
- Sql.DROP_IDX_COLUMN_CONSTRAINT_ERR,
- "Can't drop primary key column: column=" + columnName
- );
- }
- }
-
- Arrays.stream(schema.indexes())
- .filter(index -> index.tableId() == table.id())
- .forEach(index -> params.columns().stream()
- .filter(index::hasColumn)
- .findAny()
- .ifPresent(columnName -> {
- throw new SqlException(
- Sql.DROP_IDX_COLUMN_CONSTRAINT_ERR,
- "Can't drop indexed column: columnName=" + columnName + ", indexName=" + index.name()
- );
- }));
+ validateAlterTableDropColumnParams(params, schema, table);
return List.of(
new DropColumnsEntry(table.id(), params.columns())
@@ -405,36 +341,16 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
});
}
- /** {@inheritDoc} */
@Override
public CompletableFuture<Void> alterColumn(AlterColumnParams params) {
return saveUpdate(catalog -> {
- String schemaName = Objects.requireNonNullElse(params.schemaName(), CatalogService.PUBLIC);
-
- CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(schemaName), "No schema found: " + schemaName);
+ CatalogSchemaDescriptor schema = getSchema(catalog, params.schemaName());
- CatalogTableDescriptor table = schema.table(params.tableName());
+ CatalogTableDescriptor table = getTable(schema, params.tableName());
- if (table == null) {
- throw new TableNotFoundException(schemaName, params.tableName());
- }
+ CatalogTableColumnDescriptor origin = findTableColumn(table, params.columnName());
- String columnName = params.columnName();
-
- CatalogTableColumnDescriptor origin = table.columns().stream()
- .filter(desc -> desc.name().equals(columnName))
- .findFirst()
- .orElseThrow(() -> new ColumnNotFoundException(columnName));
-
- CatalogTableColumnDescriptor target = new CatalogTableColumnDescriptor(
- origin.name(),
- Objects.requireNonNullElse(params.type(), origin.type()),
- !Objects.requireNonNullElse(params.notNull(), !origin.nullable()),
- Objects.requireNonNullElse(params.precision(), origin.precision()),
- Objects.requireNonNullElse(params.scale(), origin.scale()),
- Objects.requireNonNullElse(params.length(), origin.length()),
- Objects.requireNonNullElse(params.defaultValue(origin.type()), origin.defaultValue())
- );
+ CatalogTableColumnDescriptor target = createNewTableColumn(params, origin);
if (origin.equals(target)) {
// No modifications required.
@@ -443,88 +359,28 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
boolean isPkColumn = table.isPrimaryKeyColumn(origin.name());
- if (origin.nullable() != target.nullable()) {
- if (isPkColumn) {
- throwUnsupportedDdl("Cannot change NOT NULL for the primary key column '{}'.", origin.name());
- }
-
- if (origin.nullable()) {
- throwUnsupportedDdl("Cannot set NOT NULL for column '{}'.", origin.name());
- }
- }
-
- if (origin.scale() != target.scale()) {
- throwUnsupportedDdl("Cannot change scale for column '{}'.", origin.name());
- }
-
- if (origin.type() != target.type()) {
- if (isPkColumn) {
- throwUnsupportedDdl("Cannot change data type for primary key column '{}'.", origin.name());
- }
-
- if (!CatalogUtils.isSupportedColumnTypeChange(origin.type(), target.type())) {
- throwUnsupportedDdl("Cannot change data type for column '{}' [from={}, to={}].",
- origin.name(), origin.type(), target.type());
- }
- }
-
- if (origin.length() != target.length() && target.type() != ColumnType.STRING && target.type() != ColumnType.BYTE_ARRAY) {
- throwUnsupportedDdl("Cannot change length for column '{}'.", origin.name());
- } else if (target.length() < origin.length()) {
- throwUnsupportedDdl("Cannot decrease length to {} for column '{}'.", target.length(), origin.name());
- }
-
- if (origin.precision() != target.precision() && target.type() != ColumnType.DECIMAL) {
- throwUnsupportedDdl("Cannot change precision for column '{}'.", origin.name());
- } else if (target.precision() < origin.precision()) {
- throwUnsupportedDdl("Cannot decrease precision to {} for column '{}'.", params.precision(), origin.name());
- }
+ validateAlterTableColumn(origin, target, isPkColumn);
- return List.of(new AlterColumnEntry(table.id(), target));
+ return List.of(
+ new AlterColumnEntry(table.id(), target)
+ );
});
}
- /** {@inheritDoc} */
@Override
public CompletableFuture<Void> createIndex(CreateHashIndexParams params) {
return saveUpdate(catalog -> {
- String schemaName = Objects.requireNonNullElse(params.schemaName(), CatalogService.PUBLIC);
-
- CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(schemaName), "No schema found: " + schemaName);
+ CatalogSchemaDescriptor schema = getSchema(catalog, params.schemaName());
if (schema.index(params.indexName()) != null) {
- throw new IndexAlreadyExistsException(schemaName, params.indexName());
- }
-
- CatalogTableDescriptor table = schema.table(params.tableName());
-
- if (table == null) {
- throw new TableNotFoundException(schemaName, params.tableName());
- }
-
- if (params.columns().isEmpty()) {
- throw new IgniteInternalException(
- ErrorGroups.Index.INVALID_INDEX_DEFINITION_ERR,
- "No index columns was specified."
- );
+ throw new IndexAlreadyExistsException(schema.name(), params.indexName());
}
- Predicate<String> duplicateValidator = Predicate.not(new HashSet<>()::add);
+ CatalogTableDescriptor table = getTable(schema, params.tableName());
- for (String columnName : params.columns()) {
- CatalogTableColumnDescriptor columnDescriptor = table.columnDescriptor(columnName);
-
- if (columnDescriptor == null) {
- throw new ColumnNotFoundException(columnName);
- } else if (duplicateValidator.test(columnName)) {
- throw new IgniteInternalException(
- ErrorGroups.Index.INVALID_INDEX_DEFINITION_ERR,
- "Can't create index on duplicate columns: " + String.join(", ", params.columns())
- );
- }
- }
+ validateCreateHashIndexParams(params, table);
- CatalogIndexDescriptor index = CatalogUtils.fromParams(catalog.objectIdGenState(), table.id(), params);
+ CatalogHashIndexDescriptor index = CatalogUtils.fromParams(catalog.objectIdGenState(), table.id(), params);
return List.of(
new NewIndexEntry(index),
@@ -533,50 +389,18 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
});
}
- /** {@inheritDoc} */
@Override
public CompletableFuture<Void> createIndex(CreateSortedIndexParams params) {
return saveUpdate(catalog -> {
- String schemaName = Objects.requireNonNullElse(params.schemaName(), CatalogService.PUBLIC);
-
- CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(schemaName), "No schema found: " + schemaName);
+ CatalogSchemaDescriptor schema = getSchema(catalog, params.schemaName());
if (schema.index(params.indexName()) != null) {
- throw new IndexAlreadyExistsException(schemaName, params.indexName());
- }
-
- CatalogTableDescriptor table = schema.table(params.tableName());
-
- if (table == null) {
- throw new TableNotFoundException(schemaName, params.tableName());
- }
-
- if (params.columns().isEmpty()) {
- throw new IgniteInternalException(
- ErrorGroups.Index.INVALID_INDEX_DEFINITION_ERR,
- "No index columns was specified."
- );
- } else if (params.collations().size() != params.columns().size()) {
- throw new IgniteInternalException(
- ErrorGroups.Index.INVALID_INDEX_DEFINITION_ERR,
- "Columns collations doesn't match number of columns."
- );
+ throw new IndexAlreadyExistsException(schema.name(), params.indexName());
}
- Predicate<String> duplicateValidator = Predicate.not(new HashSet<>()::add);
+ CatalogTableDescriptor table = getTable(schema, params.tableName());
- for (String columnName : params.columns()) {
- CatalogTableColumnDescriptor columnDescriptor = table.columnDescriptor(columnName);
-
- if (columnDescriptor == null) {
- throw new ColumnNotFoundException(columnName);
- } else if (duplicateValidator.test(columnName)) {
- throw new IgniteInternalException(
- ErrorGroups.Index.INVALID_INDEX_DEFINITION_ERR,
- "Can't create index on duplicate columns: " + String.join(", ", params.columns())
- );
- }
- }
+ validateCreateSortedIndexParams(params, table);
CatalogIndexDescriptor index = CatalogUtils.fromParams(catalog.objectIdGenState(), table.id(), params);
@@ -587,18 +411,15 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
});
}
- /** {@inheritDoc} */
@Override
public CompletableFuture<Void> dropIndex(DropIndexParams params) {
return saveUpdate(catalog -> {
- String schemaName = Objects.requireNonNullElse(params.schemaName(), CatalogService.PUBLIC);
-
- CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(schemaName), "No schema found: " + schemaName);
+ CatalogSchemaDescriptor schema = getSchema(catalog, params.schemaName());
CatalogIndexDescriptor index = schema.index(params.indexName());
if (index == null) {
- throw new IndexNotFoundException(schemaName, params.indexName());
+ throw new IndexNotFoundException(schema.name(), params.indexName());
}
return List.of(
@@ -607,22 +428,11 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
});
}
- /** {@inheritDoc} */
@Override
public CompletableFuture<Void> createDistributionZone(CreateZoneParams params) {
- if (params.dataNodesAutoAdjust() != INFINITE_TIMER_VALUE
- && (params.dataNodesAutoAdjustScaleUp() != INFINITE_TIMER_VALUE
- || params.dataNodesAutoAdjustScaleDown() != INFINITE_TIMER_VALUE)
- ) {
- return failedFuture(new IgniteInternalException(
- DistributionZones.ZONE_DEFINITION_ERR,
- "Not compatible parameters [dataNodesAutoAdjust=" + params.dataNodesAutoAdjust()
- + ", dataNodesAutoAdjustScaleUp=" + params.dataNodesAutoAdjustScaleUp()
- + ", dataNodesAutoAdjustScaleDown=" + params.dataNodesAutoAdjustScaleDown() + ']'
- ));
- }
-
return saveUpdate(catalog -> {
+ validateCreateZoneParams(params);
+
String zoneName = Objects.requireNonNull(params.zoneName(), "zone");
if (catalog.zone(params.zoneName()) != null) {
@@ -638,19 +448,12 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
});
}
- /** {@inheritDoc} */
@Override
public CompletableFuture<Void> dropDistributionZone(DropZoneParams params) {
return saveUpdate(catalog -> {
- String zoneName = Objects.requireNonNull(params.zoneName(), "zone");
-
- CatalogZoneDescriptor zone = catalog.zone(zoneName);
+ CatalogZoneDescriptor zone = getZone(catalog, params.zoneName());
- if (zone == null) {
- throw new DistributionZoneNotFoundException(zoneName);
- }
- if (zone.name().equals(CatalogService.DEFAULT_ZONE_NAME)) {
- //TODO IGNITE-19082 Can default zone be dropped?
+ if (zone.name().equals(DEFAULT_ZONE_NAME)) {
throw new IgniteInternalException(
DistributionZones.ZONE_DROP_ERR,
"Default distribution zone can't be dropped"
@@ -662,7 +465,7 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
.filter(t -> t.zoneId() == zone.id())
.findAny()
.ifPresent(t -> {
- throw new DistributionZoneBindTableException(zoneName, t.name());
+ throw new DistributionZoneBindTableException(zone.name(), t.name());
});
return List.of(
@@ -671,22 +474,16 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
});
}
- /** {@inheritDoc} */
@Override
public CompletableFuture<Void> renameDistributionZone(RenameZoneParams params) {
return saveUpdate(catalog -> {
- String zoneName = Objects.requireNonNull(params.newZoneName(), "newZoneName");
-
- CatalogZoneDescriptor zone = catalog.zone(params.zoneName());
+ CatalogZoneDescriptor zone = getZone(catalog, params.zoneName());
- if (zone == null) {
- throw new DistributionZoneNotFoundException(zoneName);
- }
if (catalog.zone(params.newZoneName()) != null) {
throw new DistributionZoneAlreadyExistsException(params.newZoneName());
}
- if (zone.name().equals(CatalogService.DEFAULT_ZONE_NAME)) {
- //TODO IGNITE-19082 Can default zone be renamed?
+
+ if (zone.name().equals(DEFAULT_ZONE_NAME)) {
throw new IgniteInternalException(
DistributionZones.ZONE_RENAME_ERR,
"Default distribution zone can't be renamed"
@@ -711,11 +508,7 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
@Override
public CompletableFuture<Void> alterDistributionZone(AlterZoneParams params) {
return saveUpdate(catalog -> {
- CatalogZoneDescriptor zone = catalog.zone(params.zoneName());
-
- if (zone == null) {
- throw new DistributionZoneNotFoundException(params.zoneName());
- }
+ CatalogZoneDescriptor zone = getZone(catalog, params.zoneName());
Integer dataNodesAutoAdjust = params.dataNodesAutoAdjust();
Integer dataNodesAutoAdjustScaleUp = params.dataNodesAutoAdjustScaleUp();
@@ -729,9 +522,8 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
if (dataNodesAutoAdjust != null && (dataNodesAutoAdjustScaleUp != null || dataNodesAutoAdjustScaleDown != null)) {
throw new IgniteInternalException(
DistributionZones.ZONE_DEFINITION_ERR,
- "Not compatible parameters [dataNodesAutoAdjust=" + params.dataNodesAutoAdjust()
- + ", dataNodesAutoAdjustScaleUp=" + params.dataNodesAutoAdjustScaleUp()
- + ", dataNodesAutoAdjustScaleDown=" + params.dataNodesAutoAdjustScaleDown() + ']'
+ "Not compatible dataNodes parameters [autoAdjust={}, autoAdjustScaleUp={}, autoAdjustScaleDown={}]",
+ params.dataNodesAutoAdjust(), params.dataNodesAutoAdjustScaleUp(), params.dataNodesAutoAdjustScaleDown()
);
}
@@ -846,7 +638,7 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
}
private static void throwUnsupportedDdl(String msg, Object... params) {
- throw new SqlException(UNSUPPORTED_DDL_OPERATION_ERR, IgniteStringFormatter.format(msg, params));
+ throw new SqlException(UNSUPPORTED_DDL_OPERATION_ERR, msg, params);
}
@FunctionalInterface
@@ -854,7 +646,7 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
List<UpdateEntry> get(Catalog catalog);
}
- private Catalog applyUpdateFinal(Catalog catalog, VersionedUpdate update) {
+ private static Catalog applyUpdateFinal(Catalog catalog, VersionedUpdate update) {
return new Catalog(
update.version(),
update.activationTimestamp(),
@@ -863,4 +655,207 @@ public class CatalogServiceImpl extends Producer<CatalogEvent, CatalogEventParam
catalog.schemas()
);
}
+
+ private static CatalogSchemaDescriptor getSchema(Catalog catalog, @Nullable String schemaName) {
+ schemaName = Objects.requireNonNullElse(schemaName, DEFAULT_SCHEMA_NAME);
+
+ CatalogSchemaDescriptor schema = catalog.schema(schemaName);
+
+ if (schema == null) {
+ throw new SchemaNotFoundException(schemaName);
+ }
+
+ return schema;
+ }
+
+ private static CatalogTableDescriptor getTable(CatalogSchemaDescriptor schema, String tableName) {
+ CatalogTableDescriptor table = schema.table(Objects.requireNonNull(tableName, "tableName"));
+
+ if (table == null) {
+ throw new TableNotFoundException(schema.name(), tableName);
+ }
+
+ return table;
+ }
+
+ private static CatalogZoneDescriptor getZone(Catalog catalog, String zoneName) {
+ zoneName = Objects.requireNonNull(zoneName, "zoneName");
+
+ CatalogZoneDescriptor zone = catalog.zone(zoneName);
+
+ if (zone == null) {
+ throw new DistributionZoneNotFoundException(zoneName);
+ }
+
+ return zone;
+ }
+
+ private static CatalogTableColumnDescriptor findTableColumn(CatalogTableDescriptor table, String columnName) {
+ return table.columns().stream()
+ .filter(desc -> desc.name().equals(columnName))
+ .findFirst()
+ .orElseThrow(() -> new ColumnNotFoundException(columnName));
+ }
+
+ private static CatalogTableColumnDescriptor createNewTableColumn(AlterColumnParams params, CatalogTableColumnDescriptor origin) {
+ return new CatalogTableColumnDescriptor(
+ origin.name(),
+ Objects.requireNonNullElse(params.type(), origin.type()),
+ !Objects.requireNonNullElse(params.notNull(), !origin.nullable()),
+ Objects.requireNonNullElse(params.precision(), origin.precision()),
+ Objects.requireNonNullElse(params.scale(), origin.scale()),
+ Objects.requireNonNullElse(params.length(), origin.length()),
+ Objects.requireNonNullElse(params.defaultValue(origin.type()), origin.defaultValue())
+ );
+ }
+
+ private static void validateCreateTableParams(CreateTableParams params) {
+ params.columns().stream()
+ .map(ColumnParams::name)
+ .filter(Predicate.not(new HashSet<>()::add))
+ .findAny()
+ .ifPresent(columnName -> {
+ throw new IgniteInternalException(
+ ErrorGroups.Index.INVALID_INDEX_DEFINITION_ERR,
+ "Can't create table with duplicate columns: {}",
+ params.columns().stream().map(ColumnParams::name).collect(joining(", "))
+ );
+ });
+
+ if (params.primaryKeyColumns().isEmpty()) {
+ throw new IgniteInternalException(
+ ErrorGroups.Index.INVALID_INDEX_DEFINITION_ERR,
+ "Missing primary key columns"
+ );
+ }
+ }
+
+ private static void validateAlterTableDropColumnParams(
+ AlterTableDropColumnParams params,
+ CatalogSchemaDescriptor schema,
+ CatalogTableDescriptor table
+ ) {
+ for (String columnName : params.columns()) {
+ if (table.column(columnName) == null) {
+ throw new ColumnNotFoundException(columnName);
+ }
+
+ if (table.isPrimaryKeyColumn(columnName)) {
+ throw new SqlException(
+ Sql.DROP_IDX_COLUMN_CONSTRAINT_ERR,
+ "Can't drop primary key column: [column={}]",
+ columnName
+ );
+ }
+ }
+
+ Arrays.stream(schema.indexes())
+ .filter(index -> index.tableId() == table.id())
+ .forEach(index -> params.columns().stream()
+ .filter(index::hasColumn)
+ .findAny()
+ .ifPresent(columnName -> {
+ throw new SqlException(
+ Sql.DROP_IDX_COLUMN_CONSTRAINT_ERR,
+ "Can't drop indexed column: [columnName={}, indexName={}]",
+ columnName, index.name()
+ );
+ }));
+ }
+
+ private static void validateCreateHashIndexParams(CreateHashIndexParams params, CatalogTableDescriptor table) {
+ validateIndexColumns(params.columns(), table);
+ }
+
+ private static void validateCreateSortedIndexParams(CreateSortedIndexParams params, CatalogTableDescriptor table) {
+ validateIndexColumns(params.columns(), table);
+
+ if (params.collations().size() != params.columns().size()) {
+ throw new IgniteInternalException(
+ ErrorGroups.Index.INVALID_INDEX_DEFINITION_ERR,
+ "Columns collations doesn't match number of columns."
+ );
+ }
+ }
+
+ private static void validateCreateZoneParams(CreateZoneParams params) {
+ if (params.dataNodesAutoAdjust() != INFINITE_TIMER_VALUE
+ && (params.dataNodesAutoAdjustScaleUp() != INFINITE_TIMER_VALUE
+ || params.dataNodesAutoAdjustScaleDown() != INFINITE_TIMER_VALUE)
+ ) {
+ throw new IgniteInternalException(
+ DistributionZones.ZONE_DEFINITION_ERR,
+ "Not compatible parameters [dataNodesAutoAdjust={}, dataNodesAutoAdjustScaleUp={}, dataNodesAutoAdjustScaleDown={}]",
+ params.dataNodesAutoAdjust(), params.dataNodesAutoAdjustScaleUp(), params.dataNodesAutoAdjustScaleDown()
+ );
+ }
+ }
+
+ private static void validateIndexColumns(List<String> indexColumns, CatalogTableDescriptor table) {
+ if (indexColumns.isEmpty()) {
+ throw new IgniteInternalException(
+ ErrorGroups.Index.INVALID_INDEX_DEFINITION_ERR,
+ "No index columns was specified."
+ );
+ }
+
+ Predicate<String> duplicateValidator = Predicate.not(new HashSet<>()::add);
+
+ for (String columnName : indexColumns) {
+ CatalogTableColumnDescriptor columnDescriptor = table.columnDescriptor(columnName);
+
+ if (columnDescriptor == null) {
+ throw new ColumnNotFoundException(columnName);
+ } else if (duplicateValidator.test(columnName)) {
+ throw new IgniteInternalException(
+ ErrorGroups.Index.INVALID_INDEX_DEFINITION_ERR,
+ "Can't create index on duplicate columns: {}",
+ String.join(", ", indexColumns)
+ );
+ }
+ }
+ }
+
+ private static void validateAlterTableColumn(
+ CatalogTableColumnDescriptor origin,
+ CatalogTableColumnDescriptor target,
+ boolean isPkColumn
+ ) {
+ if (origin.nullable() != target.nullable()) {
+ if (isPkColumn) {
+ throwUnsupportedDdl("Cannot change NOT NULL for the primary key column '{}'.", origin.name());
+ }
+
+ if (origin.nullable()) {
+ throwUnsupportedDdl("Cannot set NOT NULL for column '{}'.", origin.name());
+ }
+ }
+
+ if (origin.scale() != target.scale()) {
+ throwUnsupportedDdl("Cannot change scale for column '{}'.", origin.name());
+ }
+
+ if (origin.type() != target.type()) {
+ if (isPkColumn) {
+ throwUnsupportedDdl("Cannot change data type for primary key column '{}'.", origin.name());
+ }
+
+ if (!CatalogUtils.isSupportedColumnTypeChange(origin.type(), target.type())) {
+ throwUnsupportedDdl("Cannot change data type for column '{}' [from={}, to={}].",
+ origin.name(), origin.type(), target.type());
+ }
+ }
+
+ if (origin.length() != target.length() && target.type() != ColumnType.STRING && target.type() != ColumnType.BYTE_ARRAY) {
+ throwUnsupportedDdl("Cannot change length for column '{}'.", origin.name());
+ } else if (target.length() < origin.length()) {
+ throwUnsupportedDdl("Cannot decrease length to {} for column '{}'.", target.length(), origin.name());
+ }
+
+ if (origin.precision() != target.precision() && target.type() != ColumnType.DECIMAL) {
+ throwUnsupportedDdl("Cannot change precision for column '{}'.", origin.name());
+ } else if (target.precision() < origin.precision()) {
+ throwUnsupportedDdl("Cannot decrease precision to {} for column '{}'.", target.precision(), origin.name());
+ }
+ }
}
diff --git a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/AbstractIndexCommandParams.java b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/AbstractIndexCommandParams.java
index 56526615ee..ea980ece94 100644
--- a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/AbstractIndexCommandParams.java
+++ b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/AbstractIndexCommandParams.java
@@ -27,6 +27,12 @@ public abstract class AbstractIndexCommandParams implements DdlCommandParams {
/** Schema name where this new index will be created. */
protected String schema;
+ /** Table name. */
+ protected String tableName;
+
+ /** Unique index flag. */
+ protected boolean unique;
+
/**
* Returns index simple name.
*/
@@ -41,6 +47,20 @@ public abstract class AbstractIndexCommandParams implements DdlCommandParams {
return schema;
}
+ /**
+ * Returns table name.
+ */
+ public String tableName() {
+ return tableName;
+ }
+
+ /**
+ * Returns {@code true} if index is unique, {@code false} otherwise.
+ */
+ public boolean unique() {
+ return unique;
+ }
+
/**
* Parameters builder.
*/
@@ -73,6 +93,27 @@ public abstract class AbstractIndexCommandParams implements DdlCommandParams {
return (BuilderT) this;
}
+ /**
+ * Set table name.
+ *
+ * @param tableName Table name.
+ * @return {@code this}.
+ */
+ public BuilderT tableName(String tableName) {
+ params.tableName = tableName;
+
+ return (BuilderT) this;
+ }
+
+ /**
+ * Sets unique flag.
+ */
+ public BuilderT unique() {
+ params.unique = true;
+
+ return (BuilderT) this;
+ }
+
/**
* Builds parameters.
*
diff --git a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CatalogUtils.java b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CatalogUtils.java
index 0d2fbfbe7f..7823b09d47 100644
--- a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CatalogUtils.java
+++ b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CatalogUtils.java
@@ -17,17 +17,17 @@
package org.apache.ignite.internal.catalog.commands;
+import static java.util.stream.Collectors.toList;
+
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.apache.ignite.internal.catalog.descriptors.CatalogColumnCollation;
import org.apache.ignite.internal.catalog.descriptors.CatalogHashIndexDescriptor;
import org.apache.ignite.internal.catalog.descriptors.CatalogIndexColumnDescriptor;
-import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor;
import org.apache.ignite.internal.catalog.descriptors.CatalogSortedIndexDescriptor;
import org.apache.ignite.internal.catalog.descriptors.CatalogTableColumnDescriptor;
import org.apache.ignite.internal.catalog.descriptors.CatalogTableDescriptor;
@@ -60,7 +60,7 @@ public class CatalogUtils {
id,
params.tableName(),
zoneId,
- params.columns().stream().map(CatalogUtils::fromParams).collect(Collectors.toList()),
+ params.columns().stream().map(CatalogUtils::fromParams).collect(toList()),
params.primaryKeyColumns(),
params.colocationColumns()
);
@@ -69,44 +69,39 @@ public class CatalogUtils {
/**
* Converts CreateIndex command params to hash index descriptor.
*
- * @param id Index id.
- * @param tableId Table id.
+ * @param id Index ID.
+ * @param tableId Table ID.
* @param params Parameters.
* @return Index descriptor.
*/
- public static CatalogIndexDescriptor fromParams(int id, int tableId, CreateHashIndexParams params) {
- return new CatalogHashIndexDescriptor(id,
- params.indexName(),
- tableId,
- false,
- params.columns()
- );
+ public static CatalogHashIndexDescriptor fromParams(int id, int tableId, CreateHashIndexParams params) {
+ return new CatalogHashIndexDescriptor(id, params.indexName(), tableId, params.unique(), params.columns());
}
/**
* Converts CreateIndex command params to sorted index descriptor.
*
- * @param id Index id.
- * @param tableId Table id.
+ * @param id Index ID.
+ * @param tableId Table ID.
* @param params Parameters.
* @return Index descriptor.
*/
- public static CatalogIndexDescriptor fromParams(int id, int tableId, CreateSortedIndexParams params) {
+ public static CatalogSortedIndexDescriptor fromParams(int id, int tableId, CreateSortedIndexParams params) {
List<CatalogColumnCollation> collations = params.collations();
- assert collations.size() == params.columns().size();
+ assert collations.size() == params.columns().size() : "tableId=" + tableId + ", indexId=" + id;
List<CatalogIndexColumnDescriptor> columnDescriptors = IntStream.range(0, collations.size())
.mapToObj(i -> new CatalogIndexColumnDescriptor(params.columns().get(i), collations.get(i)))
- .collect(Collectors.toList());
+ .collect(toList());
- return new CatalogSortedIndexDescriptor(id, params.indexName(), tableId, params.isUnique(), columnDescriptors);
+ return new CatalogSortedIndexDescriptor(id, params.indexName(), tableId, params.unique(), columnDescriptors);
}
/**
* Converts CreateZone command params to descriptor.
*
- * @param id Distribution zone id.
+ * @param id Distribution zone ID.
* @param params Parameters.
* @return Distribution zone descriptor.
*/
diff --git a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CreateHashIndexParams.java b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CreateHashIndexParams.java
index bf260a39b4..961cd914e7 100644
--- a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CreateHashIndexParams.java
+++ b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CreateHashIndexParams.java
@@ -28,19 +28,9 @@ public class CreateHashIndexParams extends AbstractIndexCommandParams {
return new Builder();
}
- /** Table name. */
- private String tableName;
-
/** Indexed columns. */
private List<String> columns;
- /**
- * Gets table name.
- */
- public String tableName() {
- return tableName;
- }
-
/**
* Gets indexed columns.
*/
@@ -56,18 +46,6 @@ public class CreateHashIndexParams extends AbstractIndexCommandParams {
super(new CreateHashIndexParams());
}
- /**
- * Set table name.
- *
- * @param tableName Table name.
- * @return {@code this}.
- */
- public Builder tableName(String tableName) {
- params.tableName = tableName;
-
- return this;
- }
-
/**
* Set columns names.
*
diff --git a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CreateSortedIndexParams.java b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CreateSortedIndexParams.java
index 69abff38cb..2da5babf22 100644
--- a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CreateSortedIndexParams.java
+++ b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CreateSortedIndexParams.java
@@ -29,25 +29,12 @@ public class CreateSortedIndexParams extends AbstractIndexCommandParams {
return new Builder();
}
- /** Table name. */
- private String tableName;
-
/** Indexed columns. */
private List<String> columns;
/** Columns collations. */
private List<CatalogColumnCollation> collations;
- /** Unique index flag. */
- protected boolean unique;
-
- /**
- * Gets table name.
- */
- public String tableName() {
- return tableName;
- }
-
/**
* Gets indexed columns.
*/
@@ -62,13 +49,6 @@ public class CreateSortedIndexParams extends AbstractIndexCommandParams {
return collations;
}
- /**
- * Returns {@code true} if index is unique, {@code false} otherwise.
- */
- public boolean isUnique() {
- return unique;
- }
-
/**
* Parameters builder.
*/
@@ -77,18 +57,6 @@ public class CreateSortedIndexParams extends AbstractIndexCommandParams {
super(new CreateSortedIndexParams());
}
- /**
- * Set table name.
- *
- * @param tableName Table name.
- * @return {@code this}.
- */
- public Builder tableName(String tableName) {
- params.tableName = tableName;
-
- return this;
- }
-
/**
* Set columns names.
*
@@ -112,14 +80,5 @@ public class CreateSortedIndexParams extends AbstractIndexCommandParams {
return this;
}
-
- /**
- * Sets unique flag.
- */
- public Builder unique() {
- params.unique = true;
-
- return this;
- }
}
}
diff --git a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/AlterColumnEntry.java b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/AlterColumnEntry.java
index 1067e574c0..b29310e45e 100644
--- a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/AlterColumnEntry.java
+++ b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/AlterColumnEntry.java
@@ -18,7 +18,7 @@
package org.apache.ignite.internal.catalog.storage;
import static java.util.stream.Collectors.toList;
-import static org.apache.ignite.internal.catalog.CatalogService.PUBLIC;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_SCHEMA_NAME;
import java.util.Arrays;
import java.util.List;
@@ -75,7 +75,7 @@ public class AlterColumnEntry implements UpdateEntry, Fireable {
@Override
public Catalog applyUpdate(Catalog catalog) {
- CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(PUBLIC));
+ CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(DEFAULT_SCHEMA_NAME));
return new Catalog(
catalog.version(),
diff --git a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/DropColumnsEntry.java b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/DropColumnsEntry.java
index 1d50e5e196..3fc593667c 100644
--- a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/DropColumnsEntry.java
+++ b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/DropColumnsEntry.java
@@ -18,7 +18,7 @@
package org.apache.ignite.internal.catalog.storage;
import static java.util.stream.Collectors.toList;
-import static org.apache.ignite.internal.catalog.CatalogService.PUBLIC;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_SCHEMA_NAME;
import java.util.Arrays;
import java.util.List;
@@ -74,7 +74,7 @@ public class DropColumnsEntry implements UpdateEntry, Fireable {
@Override
public Catalog applyUpdate(Catalog catalog) {
- CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(PUBLIC));
+ CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(DEFAULT_SCHEMA_NAME));
return new Catalog(
catalog.version(),
diff --git a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/DropIndexEntry.java b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/DropIndexEntry.java
index fc5b019c81..4ba8749c2a 100644
--- a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/DropIndexEntry.java
+++ b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/DropIndexEntry.java
@@ -17,7 +17,7 @@
package org.apache.ignite.internal.catalog.storage;
-import static org.apache.ignite.internal.catalog.CatalogService.PUBLIC;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_SCHEMA_NAME;
import java.util.Arrays;
import java.util.List;
@@ -64,7 +64,7 @@ public class DropIndexEntry implements UpdateEntry, Fireable {
@Override
public Catalog applyUpdate(Catalog catalog) {
- CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(PUBLIC));
+ CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(DEFAULT_SCHEMA_NAME));
return new Catalog(
catalog.version(),
diff --git a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/DropTableEntry.java b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/DropTableEntry.java
index 54ffadfe58..99f14204a8 100644
--- a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/DropTableEntry.java
+++ b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/DropTableEntry.java
@@ -17,7 +17,7 @@
package org.apache.ignite.internal.catalog.storage;
-import static org.apache.ignite.internal.catalog.CatalogService.PUBLIC;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_SCHEMA_NAME;
import java.util.Arrays;
import java.util.List;
@@ -64,7 +64,7 @@ public class DropTableEntry implements UpdateEntry, Fireable {
@Override
public Catalog applyUpdate(Catalog catalog) {
- CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(PUBLIC));
+ CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(DEFAULT_SCHEMA_NAME));
return new Catalog(
catalog.version(),
diff --git a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/NewColumnsEntry.java b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/NewColumnsEntry.java
index c15fb4773f..b0fb639e35 100644
--- a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/NewColumnsEntry.java
+++ b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/NewColumnsEntry.java
@@ -17,7 +17,7 @@
package org.apache.ignite.internal.catalog.storage;
-import static org.apache.ignite.internal.catalog.CatalogService.PUBLIC;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_SCHEMA_NAME;
import java.util.Arrays;
import java.util.List;
@@ -74,7 +74,7 @@ public class NewColumnsEntry implements UpdateEntry, Fireable {
@Override
public Catalog applyUpdate(Catalog catalog) {
- CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(PUBLIC));
+ CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(DEFAULT_SCHEMA_NAME));
return new Catalog(
catalog.version(),
diff --git a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/NewIndexEntry.java b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/NewIndexEntry.java
index 0c57d7eef2..4e0419ab05 100644
--- a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/NewIndexEntry.java
+++ b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/NewIndexEntry.java
@@ -17,7 +17,7 @@
package org.apache.ignite.internal.catalog.storage;
-import static org.apache.ignite.internal.catalog.CatalogService.PUBLIC;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_SCHEMA_NAME;
import java.util.List;
import java.util.Objects;
@@ -64,7 +64,7 @@ public class NewIndexEntry implements UpdateEntry, Fireable {
@Override
public Catalog applyUpdate(Catalog catalog) {
- CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(PUBLIC));
+ CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(DEFAULT_SCHEMA_NAME));
return new Catalog(
catalog.version(),
diff --git a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/NewTableEntry.java b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/NewTableEntry.java
index 589ef47a8a..7a5c85e10f 100644
--- a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/NewTableEntry.java
+++ b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/NewTableEntry.java
@@ -17,7 +17,7 @@
package org.apache.ignite.internal.catalog.storage;
-import static org.apache.ignite.internal.catalog.CatalogService.PUBLIC;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_SCHEMA_NAME;
import java.util.List;
import java.util.Objects;
@@ -64,7 +64,7 @@ public class NewTableEntry implements UpdateEntry, Fireable {
@Override
public Catalog applyUpdate(Catalog catalog) {
- CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(PUBLIC));
+ CatalogSchemaDescriptor schema = Objects.requireNonNull(catalog.schema(DEFAULT_SCHEMA_NAME));
return new Catalog(
catalog.version(),
diff --git a/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/CatalogServiceSelfTest.java b/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/CatalogServiceSelfTest.java
index 4afcb4b2ee..2c72ace9b4 100644
--- a/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/CatalogServiceSelfTest.java
+++ b/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/CatalogServiceSelfTest.java
@@ -19,6 +19,8 @@ package org.apache.ignite.internal.catalog;
import static java.util.concurrent.CompletableFuture.completedFuture;
import static java.util.concurrent.CompletableFuture.failedFuture;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_SCHEMA_NAME;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_ZONE_NAME;
import static org.apache.ignite.internal.testframework.matchers.CompletableFutureExceptionMatcher.willThrow;
import static org.apache.ignite.internal.testframework.matchers.CompletableFutureExceptionMatcher.willThrowFast;
import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe;
@@ -121,8 +123,8 @@ import org.mockito.Mockito;
* Catalog service self test.
*/
public class CatalogServiceSelfTest {
- private static final String SCHEMA_NAME = CatalogService.PUBLIC;
- private static final String ZONE_NAME = CatalogService.DEFAULT_ZONE_NAME;
+ private static final String SCHEMA_NAME = DEFAULT_SCHEMA_NAME;
+ private static final String ZONE_NAME = DEFAULT_ZONE_NAME;
private static final String TABLE_NAME = "myTable";
private static final String TABLE_NAME_2 = "myTable2";
private static final String NEW_COLUMN_NAME = "NEWCOL";
@@ -181,7 +183,7 @@ public class CatalogServiceSelfTest {
assertEquals(0, schema.indexes().length);
CatalogZoneDescriptor zone = service.zone(1, clock.nowLong());
- assertEquals(CatalogService.DEFAULT_ZONE_NAME, zone.name());
+ assertEquals(DEFAULT_ZONE_NAME, zone.name());
assertEquals(1, zone.id());
assertEquals(CreateZoneParams.DEFAULT_PARTITION_COUNT, zone.partitions());
@@ -941,7 +943,7 @@ public class CatalogServiceSelfTest {
assertNotNull(schema);
assertEquals(0, schema.id());
- assertEquals(CatalogService.PUBLIC, schema.name());
+ assertEquals(DEFAULT_SCHEMA_NAME, schema.name());
assertSame(schema, service.activeSchema(beforeDropTimestamp));
assertSame(schema.table(TABLE_NAME), service.table(TABLE_NAME, beforeDropTimestamp));
@@ -955,7 +957,7 @@ public class CatalogServiceSelfTest {
assertNotNull(schema);
assertEquals(0, schema.id());
- assertEquals(CatalogService.PUBLIC, schema.name());
+ assertEquals(DEFAULT_SCHEMA_NAME, schema.name());
assertSame(schema, service.activeSchema(clock.nowLong()));
assertNull(schema.table(TABLE_NAME));
@@ -1211,7 +1213,7 @@ public class CatalogServiceSelfTest {
@Test
public void testCreateIndexEvents() {
CreateTableParams createTableParams = CreateTableParams.builder()
- .schemaName(CatalogService.PUBLIC)
+ .schemaName(DEFAULT_SCHEMA_NAME)
.tableName(TABLE_NAME)
.zone(ZONE_NAME)
.columns(List.of(
@@ -1226,7 +1228,7 @@ public class CatalogServiceSelfTest {
DropTableParams dropTableparams = DropTableParams.builder().tableName(TABLE_NAME).build();
CreateHashIndexParams createIndexParams = CreateHashIndexParams.builder()
- .schemaName(CatalogService.PUBLIC)
+ .schemaName(DEFAULT_SCHEMA_NAME)
.indexName(INDEX_NAME)
.tableName(TABLE_NAME)
.columns(List.of("key2"))
@@ -1385,40 +1387,40 @@ public class CatalogServiceSelfTest {
@Test
public void testDefaultZone() {
- CatalogZoneDescriptor defaultZone = service.zone(CatalogService.DEFAULT_ZONE_NAME, clock.nowLong());
+ CatalogZoneDescriptor defaultZone = service.zone(DEFAULT_ZONE_NAME, clock.nowLong());
// Try to create zone with default zone name.
CreateZoneParams createParams = CreateZoneParams.builder()
- .zoneName(CatalogService.DEFAULT_ZONE_NAME)
+ .zoneName(DEFAULT_ZONE_NAME)
.partitions(42)
.replicas(15)
.build();
assertThat(service.createDistributionZone(createParams), willThrow(IgniteInternalException.class));
// Validate default zone wasn't changed.
- assertSame(defaultZone, service.zone(CatalogService.DEFAULT_ZONE_NAME, clock.nowLong()));
+ assertSame(defaultZone, service.zone(DEFAULT_ZONE_NAME, clock.nowLong()));
// Try to rename default zone.
String newDefaultZoneName = "RenamedDefaultZone";
RenameZoneParams renameZoneParams = RenameZoneParams.builder()
- .zoneName(CatalogService.DEFAULT_ZONE_NAME)
+ .zoneName(DEFAULT_ZONE_NAME)
.newZoneName(newDefaultZoneName)
.build();
assertThat(service.renameDistributionZone(renameZoneParams), willThrow(IgniteInternalException.class));
// Validate default zone wasn't changed.
assertNull(service.zone(newDefaultZoneName, clock.nowLong()));
- assertSame(defaultZone, service.zone(CatalogService.DEFAULT_ZONE_NAME, clock.nowLong()));
+ assertSame(defaultZone, service.zone(DEFAULT_ZONE_NAME, clock.nowLong()));
// Try to drop default zone.
DropZoneParams dropZoneParams = DropZoneParams.builder()
- .zoneName(CatalogService.DEFAULT_ZONE_NAME)
+ .zoneName(DEFAULT_ZONE_NAME)
.build();
assertThat(service.dropDistributionZone(dropZoneParams), willThrow(IgniteInternalException.class));
// Validate default zone wasn't changed.
- assertSame(defaultZone, service.zone(CatalogService.DEFAULT_ZONE_NAME, clock.nowLong()));
+ assertSame(defaultZone, service.zone(DEFAULT_ZONE_NAME, clock.nowLong()));
}
@Test
diff --git a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/schema/CatalogSqlSchemaManager.java b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/schema/CatalogSqlSchemaManager.java
index d18bece8f9..ed27b83e91 100644
--- a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/schema/CatalogSqlSchemaManager.java
+++ b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/schema/CatalogSqlSchemaManager.java
@@ -17,6 +17,8 @@
package org.apache.ignite.internal.sql.engine.schema;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_SCHEMA_NAME;
+
import com.github.benmanes.caffeine.cache.Caffeine;
import java.util.ArrayList;
import java.util.Collections;
@@ -75,7 +77,7 @@ public class CatalogSqlSchemaManager implements SqlSchemaManager {
/** {@inheritDoc} */
@Override
public SchemaPlus schema(String name, int version) {
- String schemaName = name == null ? CatalogService.PUBLIC : name;
+ String schemaName = name == null ? DEFAULT_SCHEMA_NAME : name;
Entry<String, Integer> entry = Map.entry(schemaName, version);
return cache.computeIfAbsent(entry, (e) -> createSqlSchema(e.getValue(), catalogManager.schema(e.getKey(), e.getValue())));
@@ -97,7 +99,7 @@ public class CatalogSqlSchemaManager implements SqlSchemaManager {
/** {@inheritDoc} */
@Override
public SchemaPlus activeSchema(@Nullable String name, long timestamp) {
- String schemaName = name == null ? CatalogService.PUBLIC : name;
+ String schemaName = name == null ? DEFAULT_SCHEMA_NAME : name;
int version = catalogManager.activeCatalogVersion(timestamp);
diff --git a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/schema/CatalogSqlSchemaManagerTest.java b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/schema/CatalogSqlSchemaManagerTest.java
index 0d7521f17b..f5e782ecc6 100644
--- a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/schema/CatalogSqlSchemaManagerTest.java
+++ b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/schema/CatalogSqlSchemaManagerTest.java
@@ -17,6 +17,7 @@
package org.apache.ignite.internal.sql.engine.schema;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_SCHEMA_NAME;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -199,7 +200,7 @@ public class CatalogSqlSchemaManagerTest {
SchemaPlus schemaPlus = sqlSchemaManager.activeSchema(testSchema.name, testSchema.timestamp);
IgniteCatalogSchema schema = unwrapSchema(schemaPlus);
- assertEquals(CatalogManager.PUBLIC, schema.getName());
+ assertEquals(DEFAULT_SCHEMA_NAME, schema.getName());
assertEquals(testSchema.version, schema.version());
}
@@ -207,7 +208,7 @@ public class CatalogSqlSchemaManagerTest {
SchemaPlus schemaPlus = sqlSchemaManager.activeSchema(null, testSchema.timestamp);
IgniteCatalogSchema schema = unwrapSchema(schemaPlus);
- assertEquals(CatalogManager.PUBLIC, schema.getName());
+ assertEquals(DEFAULT_SCHEMA_NAME, schema.getName());
assertEquals(testSchema.version, schema.version());
}
}
@@ -455,7 +456,7 @@ public class CatalogSqlSchemaManagerTest {
final Set<TestIndex> indexes = new LinkedHashSet<>();
TestSchema() {
- this(CatalogManager.PUBLIC);
+ this(DEFAULT_SCHEMA_NAME);
}
TestSchema(String name) {
@@ -469,7 +470,7 @@ public class CatalogSqlSchemaManagerTest {
void init(CatalogManager catalogManager) {
CatalogSchemaDescriptor schemaDescriptor = newSchemaDescriptor(version);
when(catalogManager.activeCatalogVersion(timestamp)).thenReturn(version);
- when(catalogManager.schema(name != null ? name : CatalogManager.PUBLIC, version)).thenReturn(schemaDescriptor);
+ when(catalogManager.schema(name != null ? name : DEFAULT_SCHEMA_NAME, version)).thenReturn(schemaDescriptor);
}
CatalogSchemaDescriptor newSchemaDescriptor(int version) {