Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1678] feat(partition): Add JSON serde for partitions #1679

Merged
merged 2 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
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;
}
}
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
}
}
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);
}
}
}
Loading
Loading