This is an automated email from the ASF dual-hosted git repository.
yuqi4733 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new 7c5709492d [#9927] feat(index): add support for index properties
(#9927)
7c5709492d is described below
commit 7c5709492df02152fffc908a237b63da64ea4365
Author: A0R0P0I7T <[email protected]>
AuthorDate: Tue Mar 3 11:49:34 2026 +0530
[#9927] feat(index): add support for index properties (#9927)
### What changes were proposed in this pull request?
This PR adds support for `properties` in index definitions and ensures
consistent handling across Java and Python clients.
The following changes are included:
- Extended `Indexes.of`, `Indexes.primary`, and `Indexes.unique` to
accept index properties
- Updated DTO converters to handle index properties
- Updated JSON serializer and deserializer
- Updated Python client and DTOs to support properties
- Updated existing unit tests to validate the new behavior
### Why are the changes needed?
Previously, index properties were not supported or propagated through
the API and client layers. This limited extensibility and prevented
passing additional configuration metadata for indexes.
This change enables consistent transmission and usage of index
properties across different components and clients, improving
flexibility and future extensibility.
Fix: #9897
### Does this PR introduce _any_ user-facing change?
Yes. This PR introduces a new optional `properties` field in index
definitions and API responses. The change is backward-compatible and
defaults to an empty map when not specified.
### How was this patch tested?
- All Java unit tests were executed and passed
- All Python unit tests and pylint checks were executed and passed
- Verified JSON serialization and deserialization for index objects
- Ran full Gradle build successfully
---------
Co-authored-by: Copilot <[email protected]>
---
.gitignore | 2 +
.../org/apache/gravitino/rel/indexes/Index.java | 9 ++
.../org/apache/gravitino/rel/indexes/Indexes.java | 98 ++++++++++++++++++++--
.../operation/TestOceanBaseTableOperations.java | 4 +-
.../jdbc/operation/JdbcTableOperations.java | 4 +-
.../mysql/integration/test/CatalogMysqlIT.java | 3 +-
.../mysql/operation/TestMysqlTableOperations.java | 6 +-
.../integration/test/CatalogPostgreSqlIT.java | 30 +++----
.../lakehouse/paimon/GravitinoPaimonTable.java | 2 +-
.../lakehouse/paimon/TestGravitinoPaimonTable.java | 13 ++-
.../integration/test/CatalogPaimonBaseIT.java | 3 +-
.../gravitino/api/rel/indexes/indexes.py | 40 +++++++--
.../gravitino/dto/rel/indexes/index_dto.py | 7 +-
.../gravitino/dto/util/dto_converters.py | 2 +-
.../tests/unittests/api/rel/test_indexes.py | 10 ++-
.../unittests/dto/util/test_dto_converters.py | 6 +-
.../apache/gravitino/dto/rel/indexes/IndexDTO.java | 33 +++++++-
.../apache/gravitino/dto/util/DTOConverters.java | 4 +-
.../java/org/apache/gravitino/json/JsonUtils.java | 24 +++++-
.../dto/requests/TestTableUpdatesRequest.java | 4 +-
.../org/apache/gravitino/json/TestSerializer.java | 32 ++++++-
.../gravitino/catalog/CapabilityHelpers.java | 5 +-
docs/jdbc-doris-catalog.md | 2 +-
docs/jdbc-mysql-catalog.md | 6 +-
docs/jdbc-oceanbase-catalog.md | 10 +--
docs/jdbc-postgresql-catalog.md | 4 +-
docs/manage-relational-metadata-using-gravitino.md | 2 +-
...partitioning-distribution-sort-order-indexes.md | 6 +-
.../flink/connector/catalog/BaseCatalog.java | 2 +-
.../catalog/jdbc/mysql/MySQLMetadataAdapter.java | 4 +-
30 files changed, 299 insertions(+), 78 deletions(-)
diff --git a/.gitignore b/.gitignore
index f84bb25bd9..0d5aa0cbeb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -60,4 +60,6 @@ derby.log
web/node_modules
web/dist
web/.next
+
+.venv/
.worktrees/
diff --git a/api/src/main/java/org/apache/gravitino/rel/indexes/Index.java
b/api/src/main/java/org/apache/gravitino/rel/indexes/Index.java
index 925ac4cb72..d299683889 100644
--- a/api/src/main/java/org/apache/gravitino/rel/indexes/Index.java
+++ b/api/src/main/java/org/apache/gravitino/rel/indexes/Index.java
@@ -19,6 +19,8 @@
package org.apache.gravitino.rel.indexes;
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
import org.apache.gravitino.annotation.Evolving;
/**
@@ -44,6 +46,13 @@ public interface Index {
*/
String[][] fieldNames();
+ /**
+ * @return Extra properties for index configuration
+ */
+ default Map<String, String> properties() {
+ return ImmutableMap.of();
+ }
+
/**
* The enum IndexType defines the type of the index. Currently, PRIMARY_KEY
and UNIQUE_KEY are
* supported.
diff --git a/api/src/main/java/org/apache/gravitino/rel/indexes/Indexes.java
b/api/src/main/java/org/apache/gravitino/rel/indexes/Indexes.java
index 16ea392109..01d6e1bfe7 100644
--- a/api/src/main/java/org/apache/gravitino/rel/indexes/Indexes.java
+++ b/api/src/main/java/org/apache/gravitino/rel/indexes/Indexes.java
@@ -19,7 +19,10 @@
package org.apache.gravitino.rel.indexes;
import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableMap;
import java.util.Arrays;
+import java.util.Map;
+import org.apache.gravitino.rel.indexes.Index.IndexType;
/** Helper methods to create index to pass into Apache Gravitino. */
public class Indexes {
@@ -41,7 +44,19 @@ public class Indexes {
* @return The unique index
*/
public static Index unique(String name, String[][] fieldNames) {
- return of(Index.IndexType.UNIQUE_KEY, name, fieldNames);
+ return of(Index.IndexType.UNIQUE_KEY, name, fieldNames, ImmutableMap.of());
+ }
+
+ /**
+ * Create a unique index on columns. Like unique (a) or unique (a, b), for
complex like unique
+ *
+ * @param name The name of the index
+ * @param fieldNames The field names under the table contained in the index.
+ * @param properties Extra properties for index configuration
+ * @return The unique index
+ */
+ public static Index unique(String name, String[][] fieldNames, Map<String,
String> properties) {
+ return of(Index.IndexType.UNIQUE_KEY, name, fieldNames, properties);
}
/**
@@ -51,7 +66,18 @@ public class Indexes {
* @return The primary key index
*/
public static Index createMysqlPrimaryKey(String[][] fieldNames) {
- return primary(DEFAULT_PRIMARY_KEY_NAME, fieldNames);
+ return primary(DEFAULT_PRIMARY_KEY_NAME, fieldNames, ImmutableMap.of());
+ }
+
+ /**
+ * To create a MySQL primary key, you need to use the default primary key
name.
+ *
+ * @param properties Extra properties for index configuration
+ * @param fieldNames The field names under the table contained in the index.
+ * @return The primary key index
+ */
+ public static Index createMysqlPrimaryKey(String[][] fieldNames, Map<String,
String> properties) {
+ return primary(DEFAULT_PRIMARY_KEY_NAME, fieldNames, properties);
}
/**
@@ -62,20 +88,48 @@ public class Indexes {
* @return The primary index
*/
public static Index primary(String name, String[][] fieldNames) {
- return of(Index.IndexType.PRIMARY_KEY, name, fieldNames);
+ return of(Index.IndexType.PRIMARY_KEY, name, fieldNames,
ImmutableMap.of());
+ }
+
+ /**
+ * Create a primary index on columns. Like primary (a), for complex like
primary
+ *
+ * @param name The name of the index
+ * @param fieldNames The field names under the table contained in the index.
+ * @param properties Extra properties for index configuration
+ * @return The primary index
+ */
+ public static Index primary(String name, String[][] fieldNames, Map<String,
String> properties) {
+ return of(Index.IndexType.PRIMARY_KEY, name, fieldNames, properties);
+ }
+
+ /**
+ * @param indexType The type of the index
+ * @param name The name of the index
+ * @param fieldNames The field names under the table contained in the index.
+ * @return An {@link Index} instance with empty properties
+ */
+ public static Index of(IndexType indexType, String name, String[][]
fieldNames) {
+ return of(indexType, name, fieldNames, Map.of());
}
/**
* @param indexType The type of the index
* @param name The name of the index
* @param fieldNames The field names under the table contained in the index.
+ * @param properties Extra properties for index configuration
* @return The index
*/
- public static Index of(Index.IndexType indexType, String name, String[][]
fieldNames) {
+ public static Index of(
+ Index.IndexType indexType,
+ String name,
+ String[][] fieldNames,
+ Map<String, String> properties) {
return IndexImpl.builder()
.withIndexType(indexType)
.withName(name)
.withFieldNames(fieldNames)
+ .withProperties(properties)
.build();
}
@@ -87,17 +141,22 @@ public class Indexes {
private final String[][] fieldNames;
+ private final Map<String, String> properties;
+
/**
* The constructor of the index.
*
* @param indexType The type of the index
* @param name The name of the index
* @param fieldNames The field names under the table contained in the
index.
+ * @param properties The properties of the index.
*/
- private IndexImpl(IndexType indexType, String name, String[][] fieldNames)
{
+ private IndexImpl(
+ IndexType indexType, String name, String[][] fieldNames, Map<String,
String> properties) {
this.indexType = indexType;
this.name = name;
this.fieldNames = fieldNames;
+ this.properties = properties == null ? Map.of() : properties;
}
/**
@@ -124,6 +183,14 @@ public class Indexes {
return fieldNames;
}
+ /**
+ * @return Extra properties for index configuration
+ */
+ @Override
+ public Map<String, String> properties() {
+ return properties;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -135,12 +202,13 @@ public class Indexes {
IndexImpl index = (IndexImpl) o;
return indexType == index.indexType
&& Objects.equal(name, index.name)
- && Arrays.deepEquals(fieldNames, index.fieldNames);
+ && Arrays.deepEquals(fieldNames, index.fieldNames)
+ && Objects.equal(properties, index.properties);
}
@Override
public int hashCode() {
- return Objects.hashCode(indexType, name, Arrays.hashCode(fieldNames));
+ return Objects.hashCode(indexType, name,
Arrays.deepHashCode(fieldNames), properties);
}
/**
@@ -162,6 +230,9 @@ public class Indexes {
/** The field names of the index. */
protected String[][] fieldNames;
+ /** The properties of the index. */
+ protected Map<String, String> properties;
+
/**
* Set the type of the index.
*
@@ -195,13 +266,24 @@ public class Indexes {
return this;
}
+ /**
+ * Set the properties of the index.
+ *
+ * @param properties The properties of the index
+ * @return The builder for creating a new instance of IndexImpl.
+ */
+ public Builder withProperties(Map<String, String> properties) {
+ this.properties = properties;
+ return this;
+ }
+
/**
* Build a new instance of IndexImpl.
*
* @return The new instance.
*/
public Index build() {
- return new IndexImpl(indexType, name, fieldNames);
+ return new IndexImpl(indexType, name, fieldNames, properties);
}
}
}
diff --git
a/catalogs-contrib/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/operation/TestOceanBaseTableOperations.java
b/catalogs-contrib/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/operation/TestOceanBaseTableOperations.java
index c26d25b608..2a063d8a94 100644
---
a/catalogs-contrib/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/operation/TestOceanBaseTableOperations.java
+++
b/catalogs-contrib/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/operation/TestOceanBaseTableOperations.java
@@ -906,7 +906,9 @@ public class TestOceanBaseTableOperations extends
TestOceanBase {
};
final Index[] primaryIndex =
- new Index[] {Indexes.createMysqlPrimaryKey(new String[][] {{"col_1"},
{"col_4"}})};
+ new Index[] {
+ Indexes.createMysqlPrimaryKey(new String[][] {{"col_1"}, {"col_4"}},
Map.of())
+ };
exception =
Assertions.assertThrows(
IllegalArgumentException.class,
diff --git
a/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/operation/JdbcTableOperations.java
b/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/operation/JdbcTableOperations.java
index 5e4e5b52fd..516b3c01b9 100644
---
a/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/operation/JdbcTableOperations.java
+++
b/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/operation/JdbcTableOperations.java
@@ -488,9 +488,9 @@ public abstract class JdbcTableOperations implements
TableOperation {
.collect(Collectors.toList());
String[][] colStrArrays = convertIndexFieldNames(colNames);
if (entry.getKey() == Index.IndexType.PRIMARY_KEY) {
- indexes.add(Indexes.primary(indexEntry.getKey(), colStrArrays));
+ indexes.add(Indexes.primary(indexEntry.getKey(), colStrArrays,
Map.of()));
} else {
- indexes.add(Indexes.unique(indexEntry.getKey(), colStrArrays));
+ indexes.add(Indexes.unique(indexEntry.getKey(), colStrArrays,
Map.of()));
}
}
}
diff --git
a/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java
b/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java
index 576cef39eb..93aad7ea4c 100644
---
a/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java
+++
b/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java
@@ -1008,7 +1008,8 @@ public class CatalogMysqlIT extends BaseIT {
Indexes.unique("u3_key", new String[][] {{"col_5"}, {"col_4"}}),
Indexes.unique("u4_key", new String[][] {{"col_2"}, {"col_3"},
{"col_4"}}),
Indexes.unique("u5_key", new String[][] {{"col_3"}, {"col_2"},
{"col_4"}}),
- Indexes.unique("u6_key", new String[][] {{"col_3"}, {"col_4"},
{"col_1"}, {"col_2"}}),
+ Indexes.unique(
+ "u6_key", new String[][] {{"col_3"}, {"col_4"}, {"col_1"},
{"col_2"}}, Map.of()),
};
NameIdentifier tableIdentifier = NameIdentifier.of(schemaName, tableName);
diff --git
a/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/operation/TestMysqlTableOperations.java
b/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/operation/TestMysqlTableOperations.java
index 48ff38e7fc..eb47047219 100644
---
a/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/operation/TestMysqlTableOperations.java
+++
b/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/operation/TestMysqlTableOperations.java
@@ -967,7 +967,9 @@ public class TestMysqlTableOperations extends TestMysql {
};
final Index[] primaryIndex =
- new Index[] {Indexes.createMysqlPrimaryKey(new String[][] {{"col_1"},
{"col_4"}})};
+ new Index[] {
+ Indexes.createMysqlPrimaryKey(new String[][] {{"col_1"}, {"col_4"}},
Map.of())
+ };
exception =
Assertions.assertThrows(
IllegalArgumentException.class,
@@ -1071,7 +1073,7 @@ public class TestMysqlTableOperations extends TestMysql {
Map<String, String> properties = new HashMap<>();
properties.put(MYSQL_AUTO_INCREMENT_OFFSET_KEY, "10");
- Index[] indexes = new Index[] {Indexes.unique("uk_2", new String[][]
{{"col_1"}})};
+ Index[] indexes = new Index[] {Indexes.unique("uk_2", new String[][]
{{"col_1"}}, Map.of())};
// create table
TABLE_OPERATIONS.create(
TEST_DB_NAME.toString(),
diff --git
a/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/integration/test/CatalogPostgreSqlIT.java
b/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/integration/test/CatalogPostgreSqlIT.java
index b637ca7a69..afd1fb6283 100644
---
a/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/integration/test/CatalogPostgreSqlIT.java
+++
b/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/integration/test/CatalogPostgreSqlIT.java
@@ -762,7 +762,8 @@ public class CatalogPostgreSqlIT extends BaseIT {
Indexes.unique("u3_key", new String[][] {{"col_5"}, {"col_4"}}),
Indexes.unique("u4_key", new String[][] {{"col_2"}, {"col_4"},
{"col_3"}}),
Indexes.unique("u5_key", new String[][] {{"col_5"}, {"col_3"},
{"col_2"}}),
- Indexes.unique("u6_key", new String[][] {{"col_1"}, {"col_3"},
{"col_2"}, {"col_4"}}),
+ Indexes.unique(
+ "u6_key", new String[][] {{"col_1"}, {"col_3"}, {"col_2"},
{"col_4"}}, Map.of()),
};
NameIdentifier tableIdentifier = NameIdentifier.of(schemaName, tableName);
@@ -823,7 +824,7 @@ public class CatalogPostgreSqlIT extends BaseIT {
"Index does not support complex fields in PostgreSQL"));
Index[] primaryIndex2 =
- new Index[] {Indexes.unique("u1_key", new String[][] {{"col_2",
"col_3"}})};
+ new Index[] {Indexes.unique("u1_key", new String[][] {{"col_2",
"col_3"}}, Map.of())};
illegalArgumentException =
assertThrows(
IllegalArgumentException.class,
@@ -875,8 +876,8 @@ public class CatalogPostgreSqlIT extends BaseIT {
Distributions.NONE,
new SortOrder[0],
new Index[] {
- Indexes.unique("u4_key_2", new String[][] {{"col_2"}, {"col_3"},
{"col_4"}}),
- Indexes.unique("u5_key_3", new String[][] {{"col_2"}, {"col_3"},
{"col_4"}}),
+ Indexes.unique("u4_key_2", new String[][] {{"col_2"}, {"col_3"},
{"col_4"}}, Map.of()),
+ Indexes.unique("u5_key_3", new String[][] {{"col_2"}, {"col_3"},
{"col_4"}}, Map.of()),
});
table = tableCatalog.loadTable(tableIdent);
@@ -1138,7 +1139,7 @@ public class CatalogPostgreSqlIT extends BaseIT {
Column t1_col = Column.of(t1_name, Types.LongType.get(), "id", false,
false, null);
Column[] columns = {t1_col};
- Index[] t1_indexes = {Indexes.unique("u1_key", new String[][]
{{t1_name}})};
+ Index[] t1_indexes = {Indexes.unique("u1_key", new String[][] {{t1_name}},
Map.of())};
NameIdentifier tableIdentifier = NameIdentifier.of(schemaName, t1_name);
tableCatalog.createTable(
@@ -1153,7 +1154,7 @@ public class CatalogPostgreSqlIT extends BaseIT {
String t2_name = "t212";
Column t2_col = Column.of(t2_name, Types.LongType.get(), "id", false,
false, null);
- Index[] t2_indexes = {Indexes.unique("u2_key", new String[][]
{{t2_name}})};
+ Index[] t2_indexes = {Indexes.unique("u2_key", new String[][] {{t2_name}},
Map.of())};
columns = new Column[] {t2_col};
tableIdentifier = NameIdentifier.of(schemaName, t2_name);
tableCatalog.createTable(
@@ -1168,7 +1169,7 @@ public class CatalogPostgreSqlIT extends BaseIT {
String t3_name = "t_12";
Column t3_col = Column.of(t3_name, Types.LongType.get(), "id", false,
false, null);
- Index[] t3_indexes = {Indexes.unique("u3_key", new String[][]
{{t3_name}})};
+ Index[] t3_indexes = {Indexes.unique("u3_key", new String[][] {{t3_name}},
Map.of())};
columns = new Column[] {t3_col};
tableIdentifier = NameIdentifier.of(schemaName, t3_name);
tableCatalog.createTable(
@@ -1183,7 +1184,7 @@ public class CatalogPostgreSqlIT extends BaseIT {
String t4_name = "_1__";
Column t4_col = Column.of(t4_name, Types.LongType.get(), "id", false,
false, null);
- Index[] t4_indexes = {Indexes.unique("u4_key", new String[][]
{{t4_name}})};
+ Index[] t4_indexes = {Indexes.unique("u4_key", new String[][] {{t4_name}},
Map.of())};
columns = new Column[] {t4_col};
tableIdentifier = NameIdentifier.of(schemaName, t4_name);
tableCatalog.createTable(
@@ -1250,7 +1251,7 @@ public class CatalogPostgreSqlIT extends BaseIT {
String t1_name = table_name + "`; DROP TABLE important_table; -- ";
Column t1_col = Column.of(t1_name, Types.LongType.get(), "id", false,
false, null);
Column[] columns = {t1_col};
- Index[] t1_indexes = {Indexes.unique("u1_key", new String[][]
{{t1_name}})};
+ Index[] t1_indexes = {Indexes.unique("u1_key", new String[][] {{t1_name}},
Map.of())};
NameIdentifier tableIdentifier =
NameIdentifier.of(metalakeName, catalogName, schemaName, t1_name);
@@ -1275,7 +1276,7 @@ public class CatalogPostgreSqlIT extends BaseIT {
String t2_name = table_name + "`; SLEEP(10); -- ";
Column t2_col = Column.of(t2_name, Types.LongType.get(), "id", false,
false, null);
- Index[] t2_indexes = {Indexes.unique("u2_key", new String[][]
{{t2_name}})};
+ Index[] t2_indexes = {Indexes.unique("u2_key", new String[][] {{t2_name}},
Map.of())};
Column[] columns2 = new Column[] {t2_col};
NameIdentifier tableIdentifier2 =
NameIdentifier.of(metalakeName, catalogName, schemaName, t2_name);
@@ -1302,7 +1303,7 @@ public class CatalogPostgreSqlIT extends BaseIT {
String t3_name =
table_name + "`; UPDATE Users SET password = 'newpassword' WHERE
username = 'admin'; -- ";
Column t3_col = Column.of(t3_name, Types.LongType.get(), "id", false,
false, null);
- Index[] t3_indexes = {Indexes.unique("u3_key", new String[][]
{{t3_name}})};
+ Index[] t3_indexes = {Indexes.unique("u3_key", new String[][] {{t3_name}},
Map.of())};
Column[] columns3 = new Column[] {t3_col};
NameIdentifier tableIdentifier3 =
NameIdentifier.of(metalakeName, catalogName, schemaName, t3_name);
@@ -1328,7 +1329,7 @@ public class CatalogPostgreSqlIT extends BaseIT {
String invalidInput = StringUtils.repeat("a", 64);
Column t4_col = Column.of(invalidInput, Types.LongType.get(), "id", false,
false, null);
- Index[] t4_indexes = {Indexes.unique("u4_key", new String[][]
{{invalidInput}})};
+ Index[] t4_indexes = {Indexes.unique("u4_key", new String[][]
{{invalidInput}}, Map.of())};
Column[] columns4 = new Column[] {t4_col};
NameIdentifier tableIdentifier4 =
NameIdentifier.of(metalakeName, catalogName, schemaName, invalidInput);
@@ -1354,7 +1355,7 @@ public class CatalogPostgreSqlIT extends BaseIT {
String invalidInput2 = RandomNameUtils.genRandomName("$test_db");
Column t5_col = Column.of(invalidInput2, Types.LongType.get(), "id",
false, false, null);
- Index[] t5_indexes = {Indexes.unique("u5_key", new String[][]
{{invalidInput2}})};
+ Index[] t5_indexes = {Indexes.unique("u5_key", new String[][]
{{invalidInput2}}, Map.of())};
Column[] columns5 = new Column[] {t5_col};
NameIdentifier tableIdentifier5 =
NameIdentifier.of(metalakeName, catalogName, schemaName,
invalidInput2);
@@ -1563,7 +1564,8 @@ public class CatalogPostgreSqlIT extends BaseIT {
Column col3 = Column.of("col_3", Types.VarCharType.of(255), "config",
false, false, null);
Column[] newColumns = new Column[] {col1, col2, col3};
- Index[] indexes = new Index[] {Indexes.unique("u1_key", new String[][]
{{"col_2"}, {"col_3"}})};
+ Index[] indexes =
+ new Index[] {Indexes.unique("u1_key", new String[][] {{"col_2"},
{"col_3"}}, Map.of())};
String[] schemas = {"db_", "db_1", "db_2", "db12"};
SupportsSchemas schemaSupport = catalog.asSchemas();
diff --git
a/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/GravitinoPaimonTable.java
b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/GravitinoPaimonTable.java
index d09d58cdd9..4e1714ee7b 100644
---
a/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/GravitinoPaimonTable.java
+++
b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/GravitinoPaimonTable.java
@@ -170,7 +170,7 @@ public class GravitinoPaimonTable extends BaseTable {
if (table.primaryKeys() != null && !table.primaryKeys().isEmpty()) {
String[][] filedNames = constructIndexFiledNames(table.primaryKeys());
indexes =
- Collections.singletonList(primary(PAIMON_PRIMARY_KEY_INDEX_NAME,
filedNames))
+ Collections.singletonList(primary(PAIMON_PRIMARY_KEY_INDEX_NAME,
filedNames, Map.of()))
.toArray(new Index[0]);
}
return indexes;
diff --git
a/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/TestGravitinoPaimonTable.java
b/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/TestGravitinoPaimonTable.java
index ae1ecc2707..6133b13c83 100644
---
a/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/TestGravitinoPaimonTable.java
+++
b/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/TestGravitinoPaimonTable.java
@@ -288,7 +288,10 @@ public class TestGravitinoPaimonTable {
String[] partitionKeys = new String[] {"col_1"};
Index[] indexes =
Collections.singletonList(
- primary(PAIMON_PRIMARY_KEY_INDEX_NAME, new String[][] {new
String[] {"col_2"}}))
+ primary(
+ PAIMON_PRIMARY_KEY_INDEX_NAME,
+ new String[][] {new String[] {"col_2"}},
+ Map.of()))
.toArray(new Index[0]);
Table table =
@@ -429,7 +432,10 @@ public class TestGravitinoPaimonTable {
Index[] indexes =
Collections.singletonList(
- primary(PAIMON_PRIMARY_KEY_INDEX_NAME, new String[][] {new
String[] {"col_2"}}))
+ primary(
+ PAIMON_PRIMARY_KEY_INDEX_NAME,
+ new String[][] {new String[] {"col_2"}},
+ Map.of()))
.toArray(new Index[0]);
IllegalArgumentException exception =
@@ -669,7 +675,8 @@ public class TestGravitinoPaimonTable {
Collections.singletonList(
primary(
PAIMON_PRIMARY_KEY_INDEX_NAME,
- new String[][] {new String[] {columns[2].name()}}))
+ new String[][] {new String[] {columns[2].name()}},
+ Map.of()))
.toArray(new Index[0]);
GravitinoPaimonTable gravitinoPaimonTable =
diff --git
a/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/integration/test/CatalogPaimonBaseIT.java
b/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/integration/test/CatalogPaimonBaseIT.java
index c77cca1b97..677d8ca790 100644
---
a/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/integration/test/CatalogPaimonBaseIT.java
+++
b/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/integration/test/CatalogPaimonBaseIT.java
@@ -433,7 +433,8 @@ public abstract class CatalogPaimonBaseIT extends BaseIT {
Collections.singletonList(
primary(
PAIMON_PRIMARY_KEY_INDEX_NAME,
- new String[][] {new String[] {PAIMON_COL_NAME5}}))
+ new String[][] {new String[] {PAIMON_COL_NAME5}},
+ Map.of()))
.toArray(new Index[0]);
Map<String, String> properties = createProperties();
diff --git a/clients/client-python/gravitino/api/rel/indexes/indexes.py
b/clients/client-python/gravitino/api/rel/indexes/indexes.py
index 8e118434d5..6529e634b5 100644
--- a/clients/client-python/gravitino/api/rel/indexes/indexes.py
+++ b/clients/client-python/gravitino/api/rel/indexes/indexes.py
@@ -37,21 +37,40 @@ class Indexes:
@staticmethod
def of(
- index_type: Index.IndexType, name: Optional[str], field_names:
List[List[str]]
+ index_type: Index.IndexType,
+ name: Optional[str],
+ field_names: List[List[str]],
+ properties: Optional[dict[str, str]] = None,
) -> Index:
- return Indexes.IndexImpl(index_type, name, field_names)
+ return Indexes.IndexImpl(index_type, name, field_names, properties or
{})
@staticmethod
- def unique(name: str, field_names: List[List[str]]) -> Index:
- return Indexes.IndexImpl(Index.IndexType.UNIQUE_KEY, name, field_names)
+ def unique(
+ name: str,
+ field_names: List[List[str]],
+ properties: Optional[dict[str, str]] = None,
+ ) -> Index:
+ return Indexes.IndexImpl(
+ Index.IndexType.UNIQUE_KEY, name, field_names, properties or {}
+ )
@staticmethod
- def primary(name: str, field_names: List[List[str]]) -> Index:
- return Indexes.IndexImpl(Index.IndexType.PRIMARY_KEY, name,
field_names)
+ def primary(
+ name: str,
+ field_names: List[List[str]],
+ properties: Optional[dict[str, str]] = None,
+ ) -> Index:
+ return Indexes.IndexImpl(
+ Index.IndexType.PRIMARY_KEY, name, field_names, properties or {}
+ )
@staticmethod
- def create_mysql_primary_key(field_names: List[List[str]]) -> Index:
- return Indexes.primary(Indexes.DEFAULT_MYSQL_PRIMARY_KEY_NAME,
field_names)
+ def create_mysql_primary_key(
+ field_names: List[List[str]], properties: Optional[dict[str, str]] =
None
+ ) -> Index:
+ return Indexes.primary(
+ Indexes.DEFAULT_MYSQL_PRIMARY_KEY_NAME, field_names, properties or
{}
+ )
@final
class IndexImpl(Index):
@@ -60,10 +79,12 @@ class Indexes:
index_type: Index.IndexType,
name: Optional[str],
field_names: List[List[str]],
+ properties: Optional[dict[str, str]] = None,
):
self._index_type = index_type
self._name = name
self._field_names = field_names
+ self._properties = properties or {}
def type(self) -> Index.IndexType:
return self._index_type
@@ -73,3 +94,6 @@ class Indexes:
def field_names(self) -> List[List[str]]:
return self._field_names
+
+ def properties(self) -> dict[str, str]:
+ return self._properties
diff --git a/clients/client-python/gravitino/dto/rel/indexes/index_dto.py
b/clients/client-python/gravitino/dto/rel/indexes/index_dto.py
index b804fc0cc0..9d18f01ff9 100644
--- a/clients/client-python/gravitino/dto/rel/indexes/index_dto.py
+++ b/clients/client-python/gravitino/dto/rel/indexes/index_dto.py
@@ -16,7 +16,7 @@
# under the License.
from functools import reduce
-from typing import ClassVar, List, Optional
+from typing import ClassVar, List, Optional, Dict
from gravitino.api.rel.indexes.index import Index
from gravitino.utils.precondition import Precondition
@@ -36,6 +36,7 @@ class IndexDTO(Index):
index_type: Index.IndexType,
name: Optional[str],
field_names: List[List[str]],
+ properties: Optional[Dict[str, str]] = None,
):
Precondition.check_argument(index_type is not None, "Index type cannot
be null")
Precondition.check_argument(
@@ -46,6 +47,7 @@ class IndexDTO(Index):
self._index_type = index_type
self._name = name
self._field_names = field_names
+ self._properties = properties or {}
def type(self) -> Index.IndexType:
return self._index_type
@@ -53,6 +55,9 @@ class IndexDTO(Index):
def name(self) -> Optional[str]:
return self._name
+ def properties(self) -> Dict[str, str]:
+ return self._properties
+
def field_names(self) -> List[List[str]]:
return self._field_names
diff --git a/clients/client-python/gravitino/dto/util/dto_converters.py
b/clients/client-python/gravitino/dto/util/dto_converters.py
index f59fdabe0a..16fcece621 100644
--- a/clients/client-python/gravitino/dto/util/dto_converters.py
+++ b/clients/client-python/gravitino/dto/util/dto_converters.py
@@ -170,7 +170,7 @@ class DTOConverters:
Returns:
Index: The index.
"""
- return Indexes.of(dto.type(), dto.name(), dto.field_names())
+ return Indexes.of(dto.type(), dto.name(), dto.field_names(),
dto.properties())
@from_dto.register
@staticmethod
diff --git a/clients/client-python/tests/unittests/api/rel/test_indexes.py
b/clients/client-python/tests/unittests/api/rel/test_indexes.py
index 4f9a65f770..d1737be573 100644
--- a/clients/client-python/tests/unittests/api/rel/test_indexes.py
+++ b/clients/client-python/tests/unittests/api/rel/test_indexes.py
@@ -28,9 +28,13 @@ class TestIndexes(unittest.TestCase):
def test_indexes_create_index(self):
field_names = [["col_1"], ["col_2"]]
- unique = Indexes.unique(name="unique", field_names=field_names)
- primary = Indexes.primary(name="primary", field_names=field_names)
- mysql_primary =
Indexes.create_mysql_primary_key(field_names=field_names)
+ unique = Indexes.unique(name="unique", field_names=field_names,
properties={})
+ primary = Indexes.primary(
+ name="primary", field_names=field_names, properties={}
+ )
+ mysql_primary = Indexes.create_mysql_primary_key(
+ field_names=field_names, properties={}
+ )
self.assertIs(unique.type(), Index.IndexType.UNIQUE_KEY)
self.assertIs(primary.type(), Index.IndexType.PRIMARY_KEY)
diff --git
a/clients/client-python/tests/unittests/dto/util/test_dto_converters.py
b/clients/client-python/tests/unittests/dto/util/test_dto_converters.py
index dc29c89203..51ebf0bdd9 100644
--- a/clients/client-python/tests/unittests/dto/util/test_dto_converters.py
+++ b/clients/client-python/tests/unittests/dto/util/test_dto_converters.py
@@ -359,7 +359,7 @@ class TestDTOConverters(unittest.TestCase):
field_names=field_names,
)
converted = DTOConverters.from_dto(index_dto)
- expected = Indexes.of(Index.IndexType.PRIMARY_KEY, "PRIMARY",
field_names)
+ expected = Indexes.of(Index.IndexType.PRIMARY_KEY, "PRIMARY",
field_names, {})
self.assertTrue(converted.type() == expected.type())
self.assertTrue(converted.name() == expected.name())
self.assertListEqual(converted.field_names(), expected.field_names())
@@ -493,7 +493,7 @@ class TestDTOConverters(unittest.TestCase):
]
converted_dtos = DTOConverters.from_dtos(dtos)
expected_items = [
- Indexes.of(index_type, index_type.value, field_names)
+ Indexes.of(index_type, index_type.value, field_names, {})
for index_type in Index.IndexType
]
self.assertEqual(len(converted_dtos), len(expected_items))
@@ -839,7 +839,7 @@ class TestDTOConverters(unittest.TestCase):
field_names = [[f"field_{i}"] for i in range(2)]
indexes: list[Index] = [
- Indexes.of(index_type, index_type.value, field_names)
+ Indexes.of(index_type, index_type.value, field_names, {})
for index_type in Index.IndexType
]
expected_dtos: list[IndexDTO] = [
diff --git
a/common/src/main/java/org/apache/gravitino/dto/rel/indexes/IndexDTO.java
b/common/src/main/java/org/apache/gravitino/dto/rel/indexes/IndexDTO.java
index f165e59f92..8b134d5c53 100644
--- a/common/src/main/java/org/apache/gravitino/dto/rel/indexes/IndexDTO.java
+++ b/common/src/main/java/org/apache/gravitino/dto/rel/indexes/IndexDTO.java
@@ -22,6 +22,7 @@ import
com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.base.Preconditions;
import java.util.Arrays;
+import java.util.Map;
import java.util.Objects;
import org.apache.gravitino.json.JsonUtils.IndexDeserializer;
import org.apache.gravitino.json.JsonUtils.IndexSerializer;
@@ -38,6 +39,7 @@ public class IndexDTO implements Index {
private IndexType indexType;
private String name;
private String[][] fieldNames;
+ private Map<String, String> properties;
/** Default constructor for Jackson deserialization. */
public IndexDTO() {}
@@ -48,11 +50,14 @@ public class IndexDTO implements Index {
* @param indexType The type of the index.
* @param name The name of the index.
* @param fieldNames The names of the fields.
+ * @param properties Extra properties for index configuration
*/
- public IndexDTO(IndexType indexType, String name, String[][] fieldNames) {
+ public IndexDTO(
+ IndexType indexType, String name, String[][] fieldNames, Map<String,
String> properties) {
this.indexType = indexType;
this.name = name;
this.fieldNames = fieldNames;
+ this.properties = properties == null ? Map.of() : properties;
}
/**
@@ -79,6 +84,14 @@ public class IndexDTO implements Index {
return fieldNames;
}
+ /**
+ * @return Extra properties for index configuration
+ */
+ @Override
+ public Map<String, String> properties() {
+ return properties;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -87,6 +100,7 @@ public class IndexDTO implements Index {
return indexType == indexDTO.indexType
&& Objects.equals(name, indexDTO.name)
+ && Objects.equals(properties, indexDTO.properties)
&& compareStringArrays(fieldNames, indexDTO.fieldNames);
}
@@ -104,7 +118,7 @@ public class IndexDTO implements Index {
@Override
public int hashCode() {
- int result = Objects.hash(indexType, name);
+ int result = Objects.hash(indexType, name, properties);
for (String[] fieldName : fieldNames) {
result = 31 * result + Arrays.hashCode(fieldName);
}
@@ -130,6 +144,8 @@ public class IndexDTO implements Index {
protected String name;
/** The names of the fields. */
protected String[][] fieldNames;
+ /** The properties of the index. */
+ protected Map<String, String> properties;
/** Default constructor. */
public Builder() {}
@@ -167,6 +183,17 @@ public class IndexDTO implements Index {
return (S) this;
}
+ /**
+ * Sets the properties of the index.
+ *
+ * @param properties The properties of the index.
+ * @return The builder.
+ */
+ public S withProperties(Map<String, String> properties) {
+ this.properties = properties;
+ return (S) this;
+ }
+
/**
* Builds a new instance of IndexDTO.
*
@@ -177,7 +204,7 @@ public class IndexDTO implements Index {
Preconditions.checkArgument(
fieldNames != null && fieldNames.length > 0,
"The index must be set with corresponding column names");
- return new IndexDTO(indexType, name, fieldNames);
+ return new IndexDTO(indexType, name, fieldNames, properties);
}
}
}
diff --git
a/common/src/main/java/org/apache/gravitino/dto/util/DTOConverters.java
b/common/src/main/java/org/apache/gravitino/dto/util/DTOConverters.java
index 8bd6bda85b..16733b10c6 100644
--- a/common/src/main/java/org/apache/gravitino/dto/util/DTOConverters.java
+++ b/common/src/main/java/org/apache/gravitino/dto/util/DTOConverters.java
@@ -407,6 +407,7 @@ public class DTOConverters {
.withIndexType(index.type())
.withName(index.name())
.withFieldNames(index.fieldNames())
+ .withProperties(index.properties())
.build();
}
@@ -961,7 +962,8 @@ public class DTOConverters {
* @return The index.
*/
public static Index fromDTO(IndexDTO indexDTO) {
- return Indexes.of(indexDTO.type(), indexDTO.name(), indexDTO.fieldNames());
+ return Indexes.of(
+ indexDTO.type(), indexDTO.name(), indexDTO.fieldNames(),
indexDTO.properties());
}
/**
diff --git a/common/src/main/java/org/apache/gravitino/json/JsonUtils.java
b/common/src/main/java/org/apache/gravitino/json/JsonUtils.java
index b35243b17b..d104b7253b 100644
--- a/common/src/main/java/org/apache/gravitino/json/JsonUtils.java
+++ b/common/src/main/java/org/apache/gravitino/json/JsonUtils.java
@@ -50,10 +50,12 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.gravitino.NameIdentifier;
@@ -1473,14 +1475,18 @@ public class JsonUtils {
}
gen.writeFieldName(INDEX_FIELD_NAMES);
gen.writeObject(value.fieldNames());
+ Map<String, String> props = value.properties();
+ gen.writeFieldName("properties");
+ Map<String, String> sortedProps = new TreeMap<>(props);
+ gen.writeObject(sortedProps);
gen.writeEndObject();
}
}
/** Custom JSON deserializer for Index objects. */
- public static class IndexDeserializer extends JsonDeserializer<Index> {
+ public static class IndexDeserializer extends JsonDeserializer<IndexDTO> {
@Override
- public Index deserialize(JsonParser p, DeserializationContext ctxt) throws
IOException {
+ public IndexDTO deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException {
JsonNode node = p.getCodec().readTree(p);
Preconditions.checkArgument(
node != null && !node.isNull() && node.isObject(),
@@ -1501,6 +1507,20 @@ public class JsonUtils {
node.get(INDEX_FIELD_NAMES)
.forEach(field -> fieldNames.add(getStringArray((ArrayNode) field)));
builder.withFieldNames(fieldNames.toArray(new String[0][0]));
+ Map<String, String> properties = Map.of();
+
+ if (node.has("properties") && node.get("properties").isObject()) {
+
+ Map<String, String> props = new HashMap<>();
+
+ node.get("properties")
+ .fields()
+ .forEachRemaining(entry -> props.put(entry.getKey(),
entry.getValue().asText()));
+
+ properties = props;
+ }
+
+ builder.withProperties(properties);
return builder.build();
}
}
diff --git
a/common/src/test/java/org/apache/gravitino/dto/requests/TestTableUpdatesRequest.java
b/common/src/test/java/org/apache/gravitino/dto/requests/TestTableUpdatesRequest.java
index 11804ae7e5..4c2c176d3b 100644
---
a/common/src/test/java/org/apache/gravitino/dto/requests/TestTableUpdatesRequest.java
+++
b/common/src/test/java/org/apache/gravitino/dto/requests/TestTableUpdatesRequest.java
@@ -288,7 +288,7 @@ public class TestTableUpdatesRequest {
new String[][] {{"column1"}});
String jsonString =
JsonUtils.objectMapper().writeValueAsString(tableUpdateRequest);
String expected =
-
"{\"@type\":\"addTableIndex\",\"index\":{\"indexType\":\"PRIMARY_KEY\",\"name\":\"PRIMARY\",\"fieldNames\":[[\"column1\"]]}}";
+
"{\"@type\":\"addTableIndex\",\"index\":{\"indexType\":\"PRIMARY_KEY\",\"name\":\"PRIMARY\",\"fieldNames\":[[\"column1\"]],
\"properties\":{}}}";
Assertions.assertEquals(
JsonUtils.objectMapper().readTree(expected),
JsonUtils.objectMapper().readTree(jsonString));
@@ -297,7 +297,7 @@ public class TestTableUpdatesRequest {
Index.IndexType.UNIQUE_KEY, "uk_2", new String[][] {{"column2"}});
jsonString =
JsonUtils.objectMapper().writeValueAsString(tableUpdateRequest);
expected =
-
"{\"@type\":\"addTableIndex\",\"index\":{\"indexType\":\"UNIQUE_KEY\",\"name\":\"uk_2\",\"fieldNames\":[[\"column2\"]]}}";
+
"{\"@type\":\"addTableIndex\",\"index\":{\"indexType\":\"UNIQUE_KEY\",\"name\":\"uk_2\",\"fieldNames\":[[\"column2\"]],
\"properties\":{}}}";
Assertions.assertEquals(
JsonUtils.objectMapper().readTree(expected),
JsonUtils.objectMapper().readTree(jsonString));
diff --git a/common/src/test/java/org/apache/gravitino/json/TestSerializer.java
b/common/src/test/java/org/apache/gravitino/json/TestSerializer.java
index f5e11a9778..efb08de177 100644
--- a/common/src/test/java/org/apache/gravitino/json/TestSerializer.java
+++ b/common/src/test/java/org/apache/gravitino/json/TestSerializer.java
@@ -20,6 +20,7 @@
package org.apache.gravitino.json;
import com.fasterxml.jackson.core.JsonProcessingException;
+import java.util.Map;
import org.apache.gravitino.dto.rel.DistributionDTO;
import org.apache.gravitino.dto.rel.SortOrderDTO;
import org.apache.gravitino.dto.rel.expressions.LiteralDTO;
@@ -120,7 +121,8 @@ public class TestSerializer {
String actualJson =
JsonUtils.anyFieldMapper().writeValueAsString((DTOConverters.toDTO(index)));
String expectedJson =
- "{\"indexType\":\"PRIMARY_KEY\",\"name\":\"index_1\"," +
"\"fieldNames\":[[\"col1\"]]}";
+ "{\"indexType\":\"PRIMARY_KEY\",\"name\":\"index_1\","
+ + "\"fieldNames\":[[\"col1\"]],\"properties\":{}}";
Assertions.assertEquals(expectedJson, actualJson);
IndexDTO deserialized = JsonUtils.anyFieldMapper().readValue(actualJson,
IndexDTO.class);
Assertions.assertEquals(index, DTOConverters.fromDTO(deserialized));
@@ -134,8 +136,34 @@ public class TestSerializer {
actualJson = JsonUtils.anyFieldMapper().writeValueAsString(index);
expectedJson =
"{\"indexType\":\"unique_key\",\"name\":\"index_2\","
- + "\"fieldNames\":[[\"col1\"],[\"col2\"]]}";
+ + "\"fieldNames\":[[\"col1\"],[\"col2\"]],\"properties\":{}}";
Assertions.assertEquals(expectedJson, actualJson);
+
+ Map<String, String> props =
+ Map.of(
+ "compression", "lz4",
+ "level", "high");
+ index =
+ (IndexImpl)
+ Indexes.of(
+ IndexType.PRIMARY_KEY, "index_3", new String[][] {new String[]
{"colA"}}, props);
+ actualJson =
JsonUtils.anyFieldMapper().writeValueAsString(DTOConverters.toDTO(index));
+
+ expectedJson =
+ "{"
+ + "\"indexType\":\"PRIMARY_KEY\","
+ + "\"name\":\"index_3\","
+ + "\"fieldNames\":[[\"colA\"]],"
+ + "\"properties\":{"
+ + "\"compression\":\"lz4\","
+ + "\"level\":\"high\""
+ + "}"
+ + "}";
+ Assertions.assertEquals(expectedJson, actualJson);
+
+ deserialized = JsonUtils.anyFieldMapper().readValue(actualJson,
IndexDTO.class);
+
+ Assertions.assertEquals(index, DTOConverters.fromDTO(deserialized));
}
@Test
diff --git
a/core/src/main/java/org/apache/gravitino/catalog/CapabilityHelpers.java
b/core/src/main/java/org/apache/gravitino/catalog/CapabilityHelpers.java
index e405cfdd92..a3c7d53157 100644
--- a/core/src/main/java/org/apache/gravitino/catalog/CapabilityHelpers.java
+++ b/core/src/main/java/org/apache/gravitino/catalog/CapabilityHelpers.java
@@ -213,7 +213,10 @@ public class CapabilityHelpers {
private static Index applyCapabilities(Index index, Capability capabilities)
{
return Indexes.of(
- index.type(), index.name(), applyCapabilities(index.fieldNames(),
capabilities));
+ index.type(),
+ index.name(),
+ applyCapabilities(index.fieldNames(), capabilities),
+ index.properties());
}
private static String[][] applyCapabilities(String[][] fieldNames,
Capability capabilities) {
diff --git a/docs/jdbc-doris-catalog.md b/docs/jdbc-doris-catalog.md
index 900b351e9a..67b0bbf002 100644
--- a/docs/jdbc-doris-catalog.md
+++ b/docs/jdbc-doris-catalog.md
@@ -171,7 +171,7 @@ Unsupported for now.
```java
Index[] indexes = new Index[] {
- Indexes.of(IndexType.PRIMARY_KEY, "PRIMARY", new String[][]{{"id"}})
+ Indexes.of(IndexType.PRIMARY_KEY, "PRIMARY", new String[][]{{"id"}},
Map.of())
}
```
diff --git a/docs/jdbc-mysql-catalog.md b/docs/jdbc-mysql-catalog.md
index 8571a63fd9..81f4b4124f 100644
--- a/docs/jdbc-mysql-catalog.md
+++ b/docs/jdbc-mysql-catalog.md
@@ -189,7 +189,7 @@ Column[] cols = new Column[] {
Column.of("name", Types.VarCharType.of(500), "Name of the user", true,
false, null)
};
Index[] indexes = new Index[] {
- Indexes.of(IndexType.PRIMARY_KEY, "PRIMARY", new String[][]{{"id"}})
+ Indexes.of(IndexType.PRIMARY_KEY, "PRIMARY", new String[][]{{"id"}},
Map.of())
};
```
@@ -255,8 +255,8 @@ The index name of the PRIMARY_KEY must be PRIMARY
```java
Index[] indexes = new Index[] {
- Indexes.of(IndexType.PRIMARY_KEY, "PRIMARY", new String[][]{{"id"}}),
- Indexes.of(IndexType.UNIQUE_KEY, "id_name_uk", new String[][]{{"id"} ,
{"name"}}),
+ Indexes.of(IndexType.PRIMARY_KEY, "PRIMARY", new String[][]{{"id"}},
Map.of()),
+ Indexes.of(IndexType.UNIQUE_KEY, "id_name_uk", new String[][]{{"id"} ,
{"name"}}, Map.of()),
};
```
diff --git a/docs/jdbc-oceanbase-catalog.md b/docs/jdbc-oceanbase-catalog.md
index d55e9f96ec..fa1f47ba7a 100644
--- a/docs/jdbc-oceanbase-catalog.md
+++ b/docs/jdbc-oceanbase-catalog.md
@@ -191,8 +191,8 @@ Column[] cols = new Column[] {
Column.of("name", Types.VarCharType.of(500), "Name of the user", true,
false, null)
};
Index[] indexes = new Index[] {
- Indexes.of(IndexType.PRIMARY_KEY, "PRIMARY", new String[][]{{"id"}})
-}
+ Indexes.of(IndexType.PRIMARY_KEY, "PRIMARY", new String[][]{{"id"}},
Map.of())
+};
```
</TabItem>
@@ -228,9 +228,9 @@ Index[] indexes = new Index[] {
```java
Index[] indexes = new Index[] {
- Indexes.of(IndexType.PRIMARY_KEY, "PRIMARY", new String[][]{{"id"}}),
- Indexes.of(IndexType.UNIQUE_KEY, "id_name_uk", new String[][]{{"id"} ,
{"name"}}),
-}
+ Indexes.of(IndexType.PRIMARY_KEY, "PRIMARY", new String[][]{{"id"}},
Map.of()),
+ Indexes.of(IndexType.UNIQUE_KEY, "id_name_uk", new String[][]{{"id"} ,
{"name"}}, Map.of()),
+};
```
</TabItem>
diff --git a/docs/jdbc-postgresql-catalog.md b/docs/jdbc-postgresql-catalog.md
index 973a3a0373..d9e9c5d0fa 100644
--- a/docs/jdbc-postgresql-catalog.md
+++ b/docs/jdbc-postgresql-catalog.md
@@ -152,8 +152,8 @@ Meanwhile, the data types other than listed above are
mapped to Gravitino **[Ext
```java
Index[] indexes = new Index[] {
- Indexes.of(IndexType.PRIMARY_KEY, "PRIMARY", new String[][]{{"id"}}),
- Indexes.of(IndexType.UNIQUE_KEY, "id_name_uk", new String[][]{{"id"} ,
{"name"}}),
+ Indexes.of(IndexType.PRIMARY_KEY, "PRIMARY", new String[][]{{"id"}},
Map.of()),
+ Indexes.of(IndexType.UNIQUE_KEY, "id_name_uk", new String[][]{{"id"} ,
{"name"}}, Map.of()),
}
```
diff --git a/docs/manage-relational-metadata-using-gravitino.md
b/docs/manage-relational-metadata-using-gravitino.md
index b8237ce687..016d44a36b 100644
--- a/docs/manage-relational-metadata-using-gravitino.md
+++ b/docs/manage-relational-metadata-using-gravitino.md
@@ -862,7 +862,7 @@ tableCatalog.createTable(
new Transform[] {Transforms.identity("id")},
Distributions.of(Strategy.HASH, 32, NamedReference.field("id")),
new SortOrder[] {SortOrders.ascending(NamedReference.field("name"))},
- new Index[] {Indexes.of(IndexType.PRIMARY_KEY, "PRIMARY", new
String[][]{{"id"}})}
+ new Index[] {Indexes.of(IndexType.PRIMARY_KEY, "PRIMARY", new
String[][]{{"id"}}, Map.of())}
);
```
diff --git a/docs/table-partitioning-distribution-sort-order-indexes.md
b/docs/table-partitioning-distribution-sort-order-indexes.md
index d27213ba18..10d4c211c7 100644
--- a/docs/table-partitioning-distribution-sort-order-indexes.md
+++ b/docs/table-partitioning-distribution-sort-order-indexes.md
@@ -269,7 +269,7 @@ To define an indexed table, you should utilize the
following three components to
<TabItem value="java" label="Java">
```java
-Indexes.of(IndexType.PRIMARY_KEY, "PRIMARY", new String[][]{{"col_1"},
{"col_2"}});
+Indexes.of(IndexType.PRIMARY_KEY, "PRIMARY", new String[][]{{"col_1"},
{"col_2"}}, Map.of());
```
</TabItem>
@@ -344,8 +344,8 @@ tableCatalog.createTable(
Distributions.NONE,
new SortOrder[0],
new Index[] {
- Indexes.of(IndexType.PRIMARY_KEY, "PRIMARY", new String[][]{{"id"}}),
- Indexes.of(IndexType.UNIQUE_KEY, "name_age_score_uk", new
String[][]{{"name"}, {"age"}, {"score"}})
+ Indexes.of(IndexType.PRIMARY_KEY, "PRIMARY", new String[][]{{"id"}},
Map.of()),
+ Indexes.of(IndexType.UNIQUE_KEY, "name_age_score_uk", new
String[][]{{"name"}, {"age"}, {"score"}}, Map.of())
});
```
diff --git
a/flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/catalog/BaseCatalog.java
b/flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/catalog/BaseCatalog.java
index e2f412ec67..cbbde24986 100644
---
a/flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/catalog/BaseCatalog.java
+++
b/flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/catalog/BaseCatalog.java
@@ -328,7 +328,7 @@ public abstract class BaseCatalog extends AbstractCatalog {
primaryColumns.stream()
.map(primaryColumn -> new String[] {primaryColumn})
.toArray(String[][]::new);
- Index primary = Indexes.primary("primary", primaryField);
+ Index primary = Indexes.primary("primary", primaryField, Map.of());
return new Index[] {primary};
}
diff --git
a/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/jdbc/mysql/MySQLMetadataAdapter.java
b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/jdbc/mysql/MySQLMetadataAdapter.java
index d77fd62016..555170ef46 100644
---
a/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/jdbc/mysql/MySQLMetadataAdapter.java
+++
b/trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/jdbc/mysql/MySQLMetadataAdapter.java
@@ -172,7 +172,7 @@ public class MySQLMetadataAdapter extends
CatalogConnectorMetadataAdapter {
primaryKeyColumn, TABLE_PRIMARY_KEY));
}
}
- return Indexes.createMysqlPrimaryKey(convertIndexFieldNames(primaryKeys));
+ return Indexes.createMysqlPrimaryKey(convertIndexFieldNames(primaryKeys),
Map.of());
}
private static List<Index> convertUniqueKey(
@@ -189,7 +189,7 @@ public class MySQLMetadataAdapter extends
CatalogConnectorMetadataAdapter {
uniqueKeyColumn, TABLE_UNIQUE_KEY));
}
}
- builder.add(Indexes.unique(uniqueKey,
convertIndexFieldNames(uniqueKeyColumns)));
+ builder.add(Indexes.unique(uniqueKey,
convertIndexFieldNames(uniqueKeyColumns), Map.of()));
}
return builder.build();
}