Skip to content

Commit

Permalink
[apache#1339] feat(table): Add index for tables.
Browse files Browse the repository at this point in the history
  • Loading branch information
Clearvive authored and Clearvive committed Jan 19, 2024
1 parent f306edf commit c8362f0
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@
/** Helper methods to create index to pass into Gravitino. */
public class Indexes {

public static Index[] EMPTY_INDEXES = new Index[0];
public static final Index[] EMPTY_INDEXES = new Index[0];
private static final String UNIQUE_KEY_FORMAT = "%s_uk";
private static final String PRIMARY_KEY_FORMAT = "%s_pk";

public static Index unique(String fieldName) {
String[] fieldNames = {fieldName};
return unique(new String[][] {fieldNames});
}

public static Index unique(String[][] fieldNames) {
return unique(String.format(UNIQUE_KEY_FORMAT, fieldNames[0][0]), fieldNames);
}

public static Index unique(String name, String[][] fieldNames) {
return IndexImpl.builder()
Expand All @@ -17,6 +28,15 @@ public static Index unique(String name, String[][] fieldNames) {
.build();
}

public static Index primary(String fieldName) {
String[] fieldNames = {fieldName};
return primary(new String[][] {fieldNames});
}

public static Index primary(String[][] fieldNames) {
return primary(String.format(PRIMARY_KEY_FORMAT, fieldNames[0][0]), fieldNames);
}

public static Index primary(String name, String[][] fieldNames) {
return IndexImpl.builder()
.withIndexType(Index.IndexType.PRIMARY_KEY)
Expand Down

0 comments on commit c8362f0

Please sign in to comment.