diff --git a/CHANGELOG.md b/CHANGELOG.md
index e8e4045a..ee8db87b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,5 @@
+* Table: AlterTable supports index renaming
+
## 2.3.20 ##
* Table: Fixed session status updating on stream calls
* Core: Added endpoint pessimization when CreateSession returns OVERLOADED
diff --git a/table/pom.xml b/table/pom.xml
index f5518e02..cc47655b 100644
--- a/table/pom.xml
+++ b/table/pom.xml
@@ -51,6 +51,7 @@
true
ydbplatform/local-ydb:trunk
+ enable_vector_index
diff --git a/table/src/main/java/tech/ydb/table/description/RenameIndex.java b/table/src/main/java/tech/ydb/table/description/RenameIndex.java
new file mode 100644
index 00000000..ed39cb60
--- /dev/null
+++ b/table/src/main/java/tech/ydb/table/description/RenameIndex.java
@@ -0,0 +1,29 @@
+package tech.ydb.table.description;
+
+/**
+ * @author Kirill Kurdyukov
+ */
+public class RenameIndex {
+
+ private final String sourceName;
+ private final String destinationName;
+ private final boolean replaceDestination;
+
+ public RenameIndex(String sourceName, String destinationName, boolean replaceDestination) {
+ this.sourceName = sourceName;
+ this.destinationName = destinationName;
+ this.replaceDestination = replaceDestination;
+ }
+
+ public String getSourceName() {
+ return sourceName;
+ }
+
+ public String getDestinationName() {
+ return destinationName;
+ }
+
+ public boolean isReplaceDestination() {
+ return replaceDestination;
+ }
+}
diff --git a/table/src/main/java/tech/ydb/table/impl/BaseSession.java b/table/src/main/java/tech/ydb/table/impl/BaseSession.java
index 9874552c..3ecd7844 100644
--- a/table/src/main/java/tech/ydb/table/impl/BaseSession.java
+++ b/table/src/main/java/tech/ydb/table/impl/BaseSession.java
@@ -49,6 +49,7 @@
import tech.ydb.table.description.ColumnFamily;
import tech.ydb.table.description.KeyBound;
import tech.ydb.table.description.KeyRange;
+import tech.ydb.table.description.RenameIndex;
import tech.ydb.table.description.StoragePool;
import tech.ydb.table.description.TableColumn;
import tech.ydb.table.description.TableDescription;
@@ -576,6 +577,13 @@ public CompletableFuture alterTable(String path, AlterTableSettings sett
builder.addDropIndexes(dropIndex);
}
+ for (RenameIndex renameIndex : settings.getRenameIndexes()) {
+ builder.addRenameIndexes(YdbTable.RenameIndexItem.newBuilder()
+ .setSourceName(renameIndex.getSourceName())
+ .setDestinationName(renameIndex.getDestinationName())
+ .setReplaceDestination(renameIndex.isReplaceDestination()).build());
+ }
+
return rpc.alterTable(builder.build(), makeOptions(settings).build());
}
diff --git a/table/src/main/java/tech/ydb/table/settings/AlterTableSettings.java b/table/src/main/java/tech/ydb/table/settings/AlterTableSettings.java
index 6faa143e..49dfab9e 100644
--- a/table/src/main/java/tech/ydb/table/settings/AlterTableSettings.java
+++ b/table/src/main/java/tech/ydb/table/settings/AlterTableSettings.java
@@ -1,5 +1,6 @@
package tech.ydb.table.settings;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -11,6 +12,7 @@
import javax.annotation.Nullable;
+import tech.ydb.table.description.RenameIndex;
import tech.ydb.table.description.TableColumn;
import tech.ydb.table.description.TableIndex;
import tech.ydb.table.description.TableTtl;
@@ -31,6 +33,8 @@ public class AlterTableSettings extends RequestSettings {
private final Set dropChangefeeds = new HashSet<>();
private final Set dropIndexes = new HashSet<>();
+ private final List renameIndices = new ArrayList<>();
+
@Nullable
private TableTtl ttl;
@Nullable
@@ -119,6 +123,16 @@ public AlterTableSettings addGlobalAsyncIndex(String name, List columns,
return this;
}
+ public AlterTableSettings addRenameIndex(String oldName, String newName) {
+ renameIndices.add(new RenameIndex(oldName, newName, false));
+ return this;
+ }
+
+ public AlterTableSettings addRenameIndex(String oldName, String newName, boolean replaceExisting) {
+ renameIndices.add(new RenameIndex(oldName, newName, replaceExisting));
+ return this;
+ }
+
public AlterTableSettings dropIndex(String index) {
dropIndexes.add(index);
return this;
@@ -168,6 +182,10 @@ public Collection getDropIndexes() {
return dropIndexes;
}
+ public Collection getRenameIndexes() {
+ return renameIndices;
+ }
+
@Nullable
public TableTtl getTableTTL() {
return ttl;
diff --git a/table/src/test/java/tech/ydb/table/integration/AlterTableTest.java b/table/src/test/java/tech/ydb/table/integration/AlterTableTest.java
index 39315b2b..b54689a1 100644
--- a/table/src/test/java/tech/ydb/table/integration/AlterTableTest.java
+++ b/table/src/test/java/tech/ydb/table/integration/AlterTableTest.java
@@ -69,7 +69,7 @@ public void alterTableTest() {
Assert.assertTrue("Create table with indexes " + createStatus, createStatus.isSuccess());
// --------------------- describe table after creating -----------------------------
- Result describeResult = ctx.supplyResult(session ->session.describeTable(tablePath)).join();
+ Result describeResult = ctx.supplyResult(session -> session.describeTable(tablePath)).join();
Assert.assertTrue("Describe table with indexes " + describeResult.getStatus(), describeResult.isSuccess());
TableDescription description = describeResult.getValue();
@@ -99,7 +99,7 @@ public void alterTableTest() {
Assert.assertTrue("Alter table with column " + alterStatus, alterStatus.isSuccess());
// --------------------- describe table after first altering -----------------------------
- describeResult = ctx.supplyResult(session ->session.describeTable(tablePath)).join();
+ describeResult = ctx.supplyResult(session -> session.describeTable(tablePath)).join();
Assert.assertTrue("Describe table after altering " + describeResult.getStatus(), describeResult.isSuccess());
description = describeResult.getValue();
@@ -126,7 +126,7 @@ public void alterTableTest() {
Assert.assertTrue("Alter table with indexes " + alterStatus, alterStatus.isSuccess());
// --------------------- describe table after first altering -----------------------------
- describeResult = ctx.supplyResult(session ->session.describeTable(tablePath)).join();
+ describeResult = ctx.supplyResult(session -> session.describeTable(tablePath)).join();
Assert.assertTrue("Describe table after altering " + describeResult.getStatus(), describeResult.isSuccess());
description = describeResult.getValue();
@@ -163,7 +163,7 @@ public void alterTableWithSerialTest() {
Assert.assertTrue("Create table with indexes " + createStatus, createStatus.isSuccess());
// --------------------- describe table after creating -----------------------------
- Result describeResult = ctx.supplyResult(session ->session.describeTable(tablePath)).join();
+ Result describeResult = ctx.supplyResult(session -> session.describeTable(tablePath)).join();
Assert.assertTrue("Describe table with indexes " + describeResult.getStatus(), describeResult.isSuccess());
TableDescription description = describeResult.getValue();
@@ -193,7 +193,7 @@ public void alterTableWithSerialTest() {
Assert.assertTrue("Alter table with column " + alterStatus, alterStatus.isSuccess());
// --------------------- describe table after first altering -----------------------------
- describeResult = ctx.supplyResult(session ->session.describeTable(tablePath)).join();
+ describeResult = ctx.supplyResult(session -> session.describeTable(tablePath)).join();
Assert.assertTrue("Describe table after altering " + describeResult.getStatus(), describeResult.isSuccess());
description = describeResult.getValue();
@@ -220,7 +220,7 @@ public void alterTableWithSerialTest() {
Assert.assertTrue("Alter table with indexes " + alterStatus, alterStatus.isSuccess());
// --------------------- describe table after first altering -----------------------------
- describeResult = ctx.supplyResult(session ->session.describeTable(tablePath)).join();
+ describeResult = ctx.supplyResult(session -> session.describeTable(tablePath)).join();
Assert.assertTrue("Describe table after altering " + describeResult.getStatus(), describeResult.isSuccess());
description = describeResult.getValue();
@@ -239,6 +239,50 @@ public void alterTableWithSerialTest() {
assertIndexAsync(description.getIndexes().get(0), "idx2", Collections.singletonList("data"), Collections.singletonList("code"));
}
+ @Test
+ public void renameIndexTest() {
+ // --------------------- create table -----------------------------
+ ctx.supplyStatus(session -> session.executeSchemeQuery(""
+ + "CREATE TABLE " + TABLE_NAME + " ("
+ + " id Uint64 NOT NULL,"
+ + " code Text NOT NULL,"
+ + " size Float,"
+ + " created Timestamp,"
+ + " data Text,"
+ + " PRIMARY KEY(id),"
+ + " INDEX idx1 GLOBAL ON (id, code),"
+ + " INDEX idx2 GLOBAL ASYNC ON (data) COVER (code)"
+ + ")"
+ )).join().expectSuccess();
+
+ Status alterStatus = ctx.supplyStatus(
+ session -> session.alterTable(tablePath, new AlterTableSettings()
+ .addRenameIndex("idx1", "new_name"))
+ ).join();
+ Assert.assertTrue("Alter table with rename indexes " + alterStatus, alterStatus.isSuccess());
+
+ Result describeResult = ctx.supplyResult(session -> session.describeTable(tablePath)).join();
+ Assert.assertTrue("Describe table after altering " + describeResult.getStatus(), describeResult.isSuccess());
+
+ TableDescription description = describeResult.getValue();
+ Assert.assertEquals(2, description.getIndexes().size());
+ assertIndexSync(description.getIndexes().get(1), "new_name", Arrays.asList("id", "code"), Collections.emptyList());
+
+ alterStatus = ctx.supplyStatus(
+ session -> session.alterTable(tablePath, new AlterTableSettings()
+ .addRenameIndex("new_name", "idx2", true))
+ ).join();
+ Assert.assertTrue("Alter table with rename indexes " + alterStatus, alterStatus.isSuccess());
+
+ describeResult = ctx.supplyResult(session -> session.describeTable(tablePath)).join();
+ Assert.assertTrue("Describe table after altering " + describeResult.getStatus(), describeResult.isSuccess());
+
+ description = describeResult.getValue();
+
+ Assert.assertEquals(1, description.getIndexes().size());
+ assertIndexSync(description.getIndexes().get(0), "idx2", Arrays.asList("id", "code"), Collections.emptyList());
+ }
+
private void assertColumn(TableColumn column, String name, Type type) {
assertColumn(column, name, type, false, false);
}