-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#1339] feat(table): Add index for tables.
- Loading branch information
Showing
14 changed files
with
256 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
api/src/main/java/com/datastrato/gravitino/rel/expressions/Indexes/Index.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
|
||
package com.datastrato.gravitino.rel.expressions.Indexes; | ||
|
||
/** Represents an index on a table. */ | ||
public interface Index { | ||
|
||
IndexType type(); | ||
|
||
/** @return The name of the index. */ | ||
String name(); | ||
|
||
/** @return Returns the field name under the table contained in the index. eg: table.id */ | ||
String[][] fieldNames(); | ||
|
||
enum IndexType { | ||
PRIMARY_KEY, | ||
UNIQUE_KEY, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
common/src/main/java/com/datastrato/gravitino/dto/rel/indexes/IndexDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.dto.rel.indexes; | ||
|
||
import com.datastrato.gravitino.rel.expressions.Indexes.Index; | ||
import com.google.common.base.Preconditions; | ||
|
||
public class IndexDTO implements Index { | ||
|
||
private final IndexType indexType; | ||
private final String name; | ||
private final String[][] fieldNames; | ||
|
||
public IndexDTO(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(); | ||
} | ||
|
||
public static class Builder<S extends IndexDTO.Builder> { | ||
|
||
protected IndexType indexType; | ||
|
||
protected String name; | ||
protected String[][] fieldNames; | ||
|
||
public Builder() {} | ||
|
||
public S withIndexType(IndexType indexType) { | ||
this.indexType = indexType; | ||
return (S) this; | ||
} | ||
|
||
public S withName(String name) { | ||
this.name = name; | ||
return (S) this; | ||
} | ||
|
||
public S withFieldNames(String[][] fieldNames) { | ||
this.fieldNames = fieldNames; | ||
return (S) this; | ||
} | ||
|
||
public IndexDTO build() { | ||
Preconditions.checkNotNull(indexType, "Index type cannot be null"); | ||
Preconditions.checkNotNull(name, "Index name cannot be null"); | ||
Preconditions.checkNotNull( | ||
fieldNames, "The index must be set with corresponding column names"); | ||
return new IndexDTO(indexType, name, fieldNames); | ||
} | ||
} | ||
} |
Oops, something went wrong.