forked from apache/gravitino
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[apache#1678] feat(partition): Add JSON serde for partitions (apache#…
…1679) ### What changes were proposed in this pull request? Add JSON serde for partitions ### Why are the changes needed? Fix: apache#1678 ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? UTs added
- Loading branch information
Showing
6 changed files
with
728 additions
and
2 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
common/src/main/java/com/datastrato/gravitino/dto/rel/partitions/IdentityPartitionDTO.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,108 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.dto.rel.partitions; | ||
|
||
import com.datastrato.gravitino.dto.rel.expressions.LiteralDTO; | ||
import java.util.Arrays; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class IdentityPartitionDTO implements PartitionDTO { | ||
|
||
private final String name; | ||
private final String[][] fieldNames; | ||
private final LiteralDTO[] values; | ||
private final Map<String, String> properties; | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
private IdentityPartitionDTO() { | ||
this(null, null, null, null); | ||
} | ||
|
||
private IdentityPartitionDTO( | ||
String name, String[][] fieldNames, LiteralDTO[] values, Map<String, String> properties) { | ||
this.name = name; | ||
this.fieldNames = fieldNames; | ||
this.values = values; | ||
this.properties = properties; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return name; | ||
} | ||
|
||
public String[][] fieldNames() { | ||
return fieldNames; | ||
} | ||
|
||
public LiteralDTO[] values() { | ||
return values; | ||
} | ||
|
||
@Override | ||
public Map<String, String> properties() { | ||
return properties; | ||
} | ||
|
||
@Override | ||
public Type type() { | ||
return Type.IDENTITY; | ||
} | ||
|
||
public static class Builder { | ||
private String name; | ||
private String[][] fieldNames; | ||
private LiteralDTO[] values; | ||
private Map<String, String> properties; | ||
|
||
public Builder withName(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public Builder withFieldNames(String[][] fieldNames) { | ||
this.fieldNames = fieldNames; | ||
return this; | ||
} | ||
|
||
public Builder withValues(LiteralDTO[] values) { | ||
this.values = values; | ||
return this; | ||
} | ||
|
||
public Builder withProperties(Map<String, String> properties) { | ||
this.properties = properties; | ||
return this; | ||
} | ||
|
||
public IdentityPartitionDTO build() { | ||
return new IdentityPartitionDTO(name, fieldNames, values, properties); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
IdentityPartitionDTO that = (IdentityPartitionDTO) o; | ||
return Objects.equals(name, that.name) | ||
&& Arrays.deepEquals(fieldNames, that.fieldNames) | ||
&& Arrays.equals(values, that.values) | ||
&& Objects.equals(properties, that.properties); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name, Arrays.deepHashCode(fieldNames), Arrays.hashCode(values), properties); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
common/src/main/java/com/datastrato/gravitino/dto/rel/partitions/ListPartitionDTO.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,96 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.dto.rel.partitions; | ||
|
||
import com.datastrato.gravitino.dto.rel.expressions.LiteralDTO; | ||
import java.util.Arrays; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class ListPartitionDTO implements PartitionDTO { | ||
|
||
private final String name; | ||
private final LiteralDTO[][] lists; | ||
private final Map<String, String> properties; | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
private ListPartitionDTO() { | ||
this(null, null, null); | ||
} | ||
|
||
private ListPartitionDTO(String name, LiteralDTO[][] lists, Map<String, String> properties) { | ||
this.name = name; | ||
this.lists = lists; | ||
this.properties = properties; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return name; | ||
} | ||
|
||
public LiteralDTO[][] lists() { | ||
return lists; | ||
} | ||
|
||
@Override | ||
public Map<String, String> properties() { | ||
return properties; | ||
} | ||
|
||
@Override | ||
public Type type() { | ||
return Type.LIST; | ||
} | ||
|
||
public static class Builder { | ||
private String name; | ||
private LiteralDTO[][] lists; | ||
private Map<String, String> properties; | ||
|
||
public Builder withName(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public Builder withLists(LiteralDTO[][] lists) { | ||
this.lists = lists; | ||
return this; | ||
} | ||
|
||
public Builder withProperties(Map<String, String> properties) { | ||
this.properties = properties; | ||
return this; | ||
} | ||
|
||
public ListPartitionDTO build() { | ||
return new ListPartitionDTO(name, lists, properties); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
ListPartitionDTO that = (ListPartitionDTO) o; | ||
return Objects.equals(name, that.name) | ||
&& Arrays.deepEquals(lists, that.lists) | ||
&& Objects.equals(properties, that.properties); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = Objects.hash(name, properties); | ||
result = 31 * result + Arrays.deepHashCode(lists); | ||
return result; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
common/src/main/java/com/datastrato/gravitino/dto/rel/partitions/PartitionDTO.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.dto.rel.partitions; | ||
|
||
import com.datastrato.gravitino.json.JsonUtils; | ||
import com.datastrato.gravitino.rel.partitions.Partition; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
|
||
@JsonSerialize(using = JsonUtils.PartitionDTOSerializer.class) | ||
@JsonDeserialize(using = JsonUtils.PartitionDTODeserializer.class) | ||
public interface PartitionDTO extends Partition { | ||
|
||
Type type(); | ||
|
||
enum Type { | ||
RANGE, | ||
LIST, | ||
IDENTITY | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
common/src/main/java/com/datastrato/gravitino/dto/rel/partitions/RangePartitionDTO.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,107 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.dto.rel.partitions; | ||
|
||
import com.datastrato.gravitino.dto.rel.expressions.LiteralDTO; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class RangePartitionDTO implements PartitionDTO { | ||
|
||
private final String name; | ||
private final Map<String, String> properties; | ||
private final LiteralDTO upper; | ||
private final LiteralDTO lower; | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
private RangePartitionDTO() { | ||
this(null, null, null, null); | ||
} | ||
|
||
private RangePartitionDTO( | ||
String name, Map<String, String> properties, LiteralDTO upper, LiteralDTO lower) { | ||
this.name = name; | ||
this.properties = properties; | ||
this.upper = upper; | ||
this.lower = lower; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return name; | ||
} | ||
|
||
public LiteralDTO upper() { | ||
return upper; | ||
} | ||
|
||
public LiteralDTO lower() { | ||
return lower; | ||
} | ||
|
||
@Override | ||
public Map<String, String> properties() { | ||
return properties; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
RangePartitionDTO that = (RangePartitionDTO) o; | ||
return Objects.equals(name, that.name) | ||
&& Objects.equals(properties, that.properties) | ||
&& Objects.equals(upper, that.upper) | ||
&& Objects.equals(lower, that.lower); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name, properties, upper, lower); | ||
} | ||
|
||
@Override | ||
public Type type() { | ||
return Type.RANGE; | ||
} | ||
|
||
public static class Builder { | ||
private String name; | ||
private Map<String, String> properties; | ||
private LiteralDTO upper; | ||
private LiteralDTO lower; | ||
|
||
public Builder withName(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public Builder withProperties(Map<String, String> properties) { | ||
this.properties = properties; | ||
return this; | ||
} | ||
|
||
public Builder withUpper(LiteralDTO upper) { | ||
this.upper = upper; | ||
return this; | ||
} | ||
|
||
public Builder withLower(LiteralDTO lower) { | ||
this.lower = lower; | ||
return this; | ||
} | ||
|
||
public RangePartitionDTO build() { | ||
return new RangePartitionDTO(name, properties, upper, lower); | ||
} | ||
} | ||
} |
Oops, something went wrong.