diff --git a/api/src/main/java/com/datastrato/gravitino/rel/Table.java b/api/src/main/java/com/datastrato/gravitino/rel/Table.java index 55daaa03f07..a019ae37ff1 100644 --- a/api/src/main/java/com/datastrato/gravitino/rel/Table.java +++ b/api/src/main/java/com/datastrato/gravitino/rel/Table.java @@ -9,6 +9,7 @@ import com.datastrato.gravitino.Auditable; import com.datastrato.gravitino.Namespace; import com.datastrato.gravitino.rel.expressions.Indexes.Index; +import com.datastrato.gravitino.rel.expressions.Indexes.Indexes; import com.datastrato.gravitino.rel.expressions.distributions.Distribution; import com.datastrato.gravitino.rel.expressions.distributions.Distributions; import com.datastrato.gravitino.rel.expressions.sorts.SortOrder; @@ -51,7 +52,7 @@ default Distribution distribution() { /** @return The indexes of the table. If no indexes are specified, Indexes.NONE is returned. */ default Index[] index() { - return new Index[0]; + return Indexes.EMPTY_INDEXES; } /** @return The comment of the table. Null is returned if no comment is set. */ diff --git a/api/src/main/java/com/datastrato/gravitino/rel/TableCatalog.java b/api/src/main/java/com/datastrato/gravitino/rel/TableCatalog.java index 0dd63a7f817..01cb7167cd9 100644 --- a/api/src/main/java/com/datastrato/gravitino/rel/TableCatalog.java +++ b/api/src/main/java/com/datastrato/gravitino/rel/TableCatalog.java @@ -212,7 +212,7 @@ default Table createTable( } /** - * Create a partitioned table in the catalog. + * Create a table in the catalog. * * @param ident A table identifier. * @param columns The columns of the new table. @@ -222,7 +222,7 @@ default Table createTable( * @param sortOrders The sort orders of the table * @param partitions The table partitioning. * @param indexes The table indexes. - * @return Fhe created table metadata. + * @return The created table metadata. * @throws NoSuchSchemaException If the schema does not exist. * @throws TableAlreadyExistsException If the table already exists. */ diff --git a/api/src/main/java/com/datastrato/gravitino/rel/expressions/Indexes/Index.java b/api/src/main/java/com/datastrato/gravitino/rel/expressions/Indexes/Index.java index 83b909826e1..a3cbc1f9bea 100644 --- a/api/src/main/java/com/datastrato/gravitino/rel/expressions/Indexes/Index.java +++ b/api/src/main/java/com/datastrato/gravitino/rel/expressions/Indexes/Index.java @@ -5,7 +5,10 @@ package com.datastrato.gravitino.rel.expressions.Indexes; -/** Represents an index on a table. */ +/** + * The Index interface defines methods for implementing table index columns. Currently, settings for + * PRIMARY_KEY and UNIQUE_KEY are provided. + */ public interface Index { IndexType type(); @@ -17,7 +20,9 @@ public interface Index { String[][] fieldNames(); enum IndexType { + /** Primary key index. */ PRIMARY_KEY, + /** Unique key index. */ UNIQUE_KEY, } } diff --git a/api/src/main/java/com/datastrato/gravitino/rel/expressions/Indexes/Indexes.java b/api/src/main/java/com/datastrato/gravitino/rel/expressions/Indexes/Indexes.java new file mode 100644 index 00000000000..d4c5a039cd1 --- /dev/null +++ b/api/src/main/java/com/datastrato/gravitino/rel/expressions/Indexes/Indexes.java @@ -0,0 +1,65 @@ +package com.datastrato.gravitino.rel.expressions.Indexes; + +/** Helper methods to create index to pass into Gravitino. */ +public class Indexes { + + public static Index[] EMPTY_INDEXES = new Index[0]; + + public static final class IndexImpl implements Index { + private final IndexType indexType; + private final String name; + private final String[][] fieldNames; + + public IndexImpl(IndexType indexType, String name, String[][] fieldNames) { + this.indexType = indexType; + this.name = name; + this.fieldNames = fieldNames; + } + + @Override + public IndexType type() { + return indexType; + } + + @Override + public String name() { + return name; + } + + @Override + public String[][] fieldNames() { + return fieldNames; + } + + public static Builder builder() { + return new Builder(); + } + + /** Builder to create a index. */ + public static class Builder { + protected IndexType indexType; + + protected String name; + protected String[][] fieldNames; + + public Indexes.IndexImpl.Builder withIndexType(IndexType indexType) { + this.indexType = indexType; + return this; + } + + public Indexes.IndexImpl.Builder withName(String name) { + this.name = name; + return this; + } + + public Indexes.IndexImpl.Builder withFieldNames(String[][] fieldNames) { + this.fieldNames = fieldNames; + return this; + } + + public Index build() { + return new IndexImpl(indexType, name, fieldNames); + } + } + } +} diff --git a/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/HiveCatalogOperations.java b/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/HiveCatalogOperations.java index efc93ead55c..49f965d9a24 100644 --- a/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/HiveCatalogOperations.java +++ b/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/HiveCatalogOperations.java @@ -31,6 +31,7 @@ import com.datastrato.gravitino.rel.TableCatalog; import com.datastrato.gravitino.rel.TableChange; import com.datastrato.gravitino.rel.expressions.Indexes.Index; +import com.datastrato.gravitino.rel.expressions.Indexes.Indexes; import com.datastrato.gravitino.rel.expressions.NamedReference; import com.datastrato.gravitino.rel.expressions.distributions.Distribution; import com.datastrato.gravitino.rel.expressions.distributions.Distributions; @@ -561,7 +562,8 @@ public Table createTable( Index[] indexes) throws NoSuchSchemaException, TableAlreadyExistsException { Preconditions.checkArgument( - null == indexes || indexes.length == 0, "hive-catalog does not support indexes"); + indexes == Indexes.EMPTY_INDEXES, + "Hive-catalog does not support indexes,The current Gravitino hive-catalog only supports Hive 2.x"); NameIdentifier schemaIdent = NameIdentifier.of(tableIdent.namespace().levels()); validatePartitionForCreate(columns, partitioning);