-
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
9 changed files
with
240 additions
and
4 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
16 changes: 16 additions & 0 deletions
16
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,16 @@ | ||
/* | ||
* 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 { | ||
|
||
/** @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(); | ||
} |
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
57 changes: 57 additions & 0 deletions
57
common/src/main/java/com/datastrato/gravitino/dto/rel/indexes/PrimaryKeyDTO.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,57 @@ | ||
/* | ||
* 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 PrimaryKeyDTO implements Index { | ||
|
||
private final String name; | ||
private final String fieldName; | ||
|
||
public PrimaryKeyDTO(String name, String fieldName) { | ||
this.name = name; | ||
this.fieldName = fieldName; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public String[][] fieldNames() { | ||
return new String[][] {new String[] {fieldName}}; | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder<S extends PrimaryKeyDTO.Builder> { | ||
|
||
protected String name; | ||
protected String fieldName; | ||
|
||
public Builder() {} | ||
|
||
public S withName(String name) { | ||
this.name = name; | ||
return (S) this; | ||
} | ||
|
||
public S withFieldName(String fieldName) { | ||
this.fieldName = fieldName; | ||
return (S) this; | ||
} | ||
|
||
public PrimaryKeyDTO build() { | ||
Preconditions.checkNotNull(name, "Index name cannot be null"); | ||
Preconditions.checkNotNull(fieldName, "Primary key must specify the field name"); | ||
return new PrimaryKeyDTO(name, fieldName); | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
common/src/main/java/com/datastrato/gravitino/dto/rel/indexes/UniqueDTO.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,57 @@ | ||
/* | ||
* 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 UniqueDTO implements Index { | ||
|
||
private final String name; | ||
private final String fieldName; | ||
|
||
public UniqueDTO(String name, String fieldName) { | ||
this.name = name; | ||
this.fieldName = fieldName; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public String[][] fieldNames() { | ||
return new String[][] {new String[] {fieldName}}; | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder<S extends Builder> { | ||
|
||
protected String name; | ||
protected String fieldName; | ||
|
||
public Builder() {} | ||
|
||
public S withName(String name) { | ||
this.name = name; | ||
return (S) this; | ||
} | ||
|
||
public S withFieldName(String fieldName) { | ||
this.fieldName = fieldName; | ||
return (S) this; | ||
} | ||
|
||
public PrimaryKeyDTO build() { | ||
Preconditions.checkNotNull(name, "Index name cannot be null"); | ||
Preconditions.checkNotNull(fieldName, "Unique index must specify the field name"); | ||
return new PrimaryKeyDTO(name, fieldName); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.