Skip to content

Commit

Permalink
support json format inner object
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry-024 committed Dec 23, 2024
1 parent 0189dd0 commit 0b10fe6
Show file tree
Hide file tree
Showing 17 changed files with 408 additions and 479 deletions.
19 changes: 19 additions & 0 deletions paimon-common/src/main/java/org/apache/paimon/types/DataField.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.paimon.annotation.Public;

import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.core.JsonGenerator;

import javax.annotation.Nullable;
Expand All @@ -37,6 +38,7 @@
* @since 0.4.0
*/
@Public
@JsonIgnoreProperties(ignoreUnknown = true)
public final class DataField implements Serializable {

private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -76,6 +78,23 @@ public DataType type() {
return type;
}

public int getId() {
return id;
}

public String getName() {
return name;
}

public DataType getType() {
return type;
}

@Nullable
public String getDescription() {
return description;
}

public DataField newId(int newid) {
return new DataField(newid, name, type, description);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
import org.apache.paimon.utils.Preconditions;
import org.apache.paimon.utils.StringUtils;

import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonGetter;
import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonProperty;

import javax.annotation.Nullable;

import java.io.Serializable;
Expand All @@ -40,10 +45,15 @@
* @since 0.4.0
*/
@Public
@JsonIgnoreProperties(ignoreUnknown = true)
public class Identifier implements Serializable {

private static final long serialVersionUID = 1L;

private static final String FIELD_DATABASE_NAME = "database";
private static final String FIELD_TABLE_NAME = "table";
private static final String FIELD_BRANCH_NAME = "branch";

public static final RowType SCHEMA =
new RowType(
false,
Expand All @@ -53,19 +63,29 @@ public class Identifier implements Serializable {

public static final String UNKNOWN_DATABASE = "unknown";

@JsonProperty(FIELD_DATABASE_NAME)
private final String database;

private final String object;

@JsonProperty(FIELD_TABLE_NAME)
private transient String table;

@JsonProperty(FIELD_BRANCH_NAME)
private transient String branch;

private transient String systemTable;

public Identifier(String database, String object) {
this.database = database;
this.object = object;
}

public Identifier(String database, String table, @Nullable String branch) {
@JsonCreator
public Identifier(
@JsonProperty(FIELD_DATABASE_NAME) String database,
@JsonProperty(FIELD_TABLE_NAME) String table,
@JsonProperty(FIELD_BRANCH_NAME) @Nullable String branch) {
this(database, table, branch, null);
}

Expand All @@ -89,6 +109,7 @@ public Identifier(
this.systemTable = systemTable;
}

@JsonGetter(FIELD_DATABASE_NAME)
public String getDatabaseName() {
return database;
}
Expand All @@ -103,11 +124,13 @@ public String getFullName() {
: String.format("%s.%s", database, object);
}

@JsonGetter(FIELD_TABLE_NAME)
public String getTableName() {
splitObjectName();
return table;
}

@JsonGetter(FIELD_BRANCH_NAME)
public @Nullable String getBranchName() {
splitObjectName();
return branch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@

package org.apache.paimon.rest;

import org.apache.paimon.catalog.Identifier;
import org.apache.paimon.rest.serializer.IdentifierSerializer;
import org.apache.paimon.rest.serializer.SchemaSerializer;
import org.apache.paimon.schema.Schema;
import org.apache.paimon.types.DataField;
import org.apache.paimon.types.DataType;
import org.apache.paimon.types.DataTypeJsonParser;
Expand Down Expand Up @@ -53,15 +49,8 @@ public static Module createPaimonRestJacksonModule() {
DataField.class,
DataField::serializeJson,
DataTypeJsonParser::parseDataField);
registerJsonObjects(
module, Schema.class, SchemaSerializer.INSTANCE, SchemaSerializer.INSTANCE);
registerJsonObjects(
module, DataType.class, DataType::serializeJson, DataTypeJsonParser::parseDataType);
registerJsonObjects(
module,
Identifier.class,
IdentifierSerializer.INSTANCE,
IdentifierSerializer.INSTANCE);
return module;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@
/** Request for creating table. */
public class CreateTableRequest implements RESTRequest {

private static final String FIELD_IDENTIFIER_NAME = "identifier";
private static final String FIELD_IDENTIFIER = "identifier";
private static final String FIELD_SCHEMA = "schema";

@JsonProperty(FIELD_IDENTIFIER_NAME)
@JsonProperty(FIELD_IDENTIFIER)
private Identifier identifier;

@JsonProperty(FIELD_SCHEMA)
private Schema schema;

@JsonCreator
public CreateTableRequest(
@JsonProperty(FIELD_IDENTIFIER_NAME) Identifier identifier,
@JsonProperty(FIELD_IDENTIFIER) Identifier identifier,
@JsonProperty(FIELD_SCHEMA) Schema schema) {
this.schema = schema;
}

@JsonGetter(FIELD_IDENTIFIER_NAME)
@JsonGetter(FIELD_IDENTIFIER)
public Identifier getIdentifier() {
return identifier;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,78 @@

import org.apache.paimon.schema.SchemaChange;

import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonGetter;
import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonProperty;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/** Schema changes to serialize List of SchemaChange . */
@JsonIgnoreProperties(ignoreUnknown = true)
public class SchemaChanges {
private static final String FIELD_SET_OPTIONS_NAME = "set-options";
private static final String FIELD_REMOVE_OPTIONS_NAME = "remove-options";
private static final String FIELD_COMMENT_NAME = "comment";
private static final String FIELD_ADD_COLUMNS_NAME = "add-columns";
private static final String FIELD_RENAME_COLUMNS_NAME = "rename-columns";

private static final String FIELD_SET_OPTIONS = "set-options";
private static final String FIELD_REMOVE_OPTIONS = "remove-options";
private static final String FIELD_COMMENT = "comment";
private static final String FIELD_ADD_COLUMNS = "add-columns";
private static final String FIELD_RENAME_COLUMNS = "rename-columns";
private static final String FIELD_DROP_COLUMNS = "drop-columns";
private static final String FIELD_UPDATE_COLUMN_TYPES = "update-column-types";
private static final String FIELD_UPDATE_COLUMN_NULLABILITIES = "update-column-nullabilities";
private static final String FIELD_UPDATE_COLUMN_COMMENTS = "update-column-comments";
private static final String FIELD_UPDATE_COLUMN_POSITIONS = "update-column-positions";

@JsonProperty(FIELD_SET_OPTIONS)
private Map<String, String> setOptions;

@JsonProperty(FIELD_REMOVE_OPTIONS)
private List<String> removeOptions;

@JsonProperty(FIELD_COMMENT)
private String comment;

@JsonProperty(FIELD_ADD_COLUMNS)
private List<SchemaChange.AddColumn> addColumns;

@JsonProperty(FIELD_RENAME_COLUMNS)
private List<SchemaChange.RenameColumn> renameColumns;
private List<SchemaChange.DropColumn> dropColumns;

@JsonProperty(FIELD_DROP_COLUMNS)
private List<String> dropColumns;

@JsonProperty(FIELD_UPDATE_COLUMN_TYPES)
private List<SchemaChange.UpdateColumnType> updateColumnTypes;

@JsonProperty(FIELD_UPDATE_COLUMN_NULLABILITIES)
private List<SchemaChange.UpdateColumnNullability> updateColumnNullabilities;

@JsonProperty(FIELD_UPDATE_COLUMN_COMMENTS)
private List<SchemaChange.UpdateColumnComment> updateColumnComments;
private List<SchemaChange.UpdateColumnPosition> updateColumnPositions;

@JsonProperty(FIELD_UPDATE_COLUMN_POSITIONS)
private List<SchemaChange.Move> updateColumnPositions;

@JsonCreator
public SchemaChanges(
Map<String, String> setOptions,
List<String> removeOptions,
String comment,
List<SchemaChange.AddColumn> addColumns,
List<SchemaChange.RenameColumn> renameColumns,
List<SchemaChange.DropColumn> dropColumns,
List<SchemaChange.UpdateColumnType> updateColumnTypes,
List<SchemaChange.UpdateColumnNullability> updateColumnNullabilities,
List<SchemaChange.UpdateColumnComment> updateColumnComments,
List<SchemaChange.UpdateColumnPosition> updateColumnPositions) {
@JsonProperty(FIELD_SET_OPTIONS) Map<String, String> setOptions,
@JsonProperty(FIELD_REMOVE_OPTIONS) List<String> removeOptions,
@JsonProperty(FIELD_COMMENT) String comment,
@JsonProperty(FIELD_ADD_COLUMNS) List<SchemaChange.AddColumn> addColumns,
@JsonProperty(FIELD_RENAME_COLUMNS) List<SchemaChange.RenameColumn> renameColumns,
@JsonProperty(FIELD_DROP_COLUMNS) List<String> dropColumns,
@JsonProperty(FIELD_UPDATE_COLUMN_TYPES)
List<SchemaChange.UpdateColumnType> updateColumnTypes,
@JsonProperty(FIELD_UPDATE_COLUMN_NULLABILITIES)
List<SchemaChange.UpdateColumnNullability> updateColumnNullabilities,
@JsonProperty(FIELD_UPDATE_COLUMN_COMMENTS)
List<SchemaChange.UpdateColumnComment> updateColumnComments,
@JsonProperty(FIELD_UPDATE_COLUMN_POSITIONS)
List<SchemaChange.Move> updateColumnPositions) {
this.setOptions = setOptions;
this.removeOptions = removeOptions;
this.comment = comment;
Expand All @@ -66,10 +105,16 @@ public SchemaChanges(
}

public SchemaChanges(List<SchemaChange> changes) {
Map<String, String> setOptions = null;
Map<String, String> setOptions = new HashMap<>();
List<String> removeOptions = new ArrayList<>();
String comment = null;
List<SchemaChange.AddColumn> addColumns = new ArrayList<>();
List<SchemaChange.RenameColumn> renameColumns = new ArrayList<>();
List<String> dropColumns = new ArrayList<>();
List<SchemaChange.UpdateColumnType> updateColumnTypes = new ArrayList<>();
List<SchemaChange.UpdateColumnNullability> updateColumnNullabilities = new ArrayList<>();
List<SchemaChange.UpdateColumnComment> updateColumnComments = new ArrayList<>();
List<SchemaChange.Move> updateColumnPositions = new ArrayList<>();
for (SchemaChange change : changes) {
if (change instanceof SchemaChange.SetOption) {
setOptions.put(
Expand All @@ -81,51 +126,79 @@ public SchemaChanges(List<SchemaChange> changes) {
comment = ((SchemaChange.UpdateComment) change).comment();
} else if (change instanceof SchemaChange.AddColumn) {
addColumns.add((SchemaChange.AddColumn) change);
} else if (change instanceof SchemaChange.RenameColumn) {
renameColumns.add((SchemaChange.RenameColumn) change);
} else if (change instanceof SchemaChange.DropColumn) {
dropColumns.addAll(Arrays.asList(((SchemaChange.DropColumn) change).fieldNames()));
} else if (change instanceof SchemaChange.UpdateColumnType) {
updateColumnTypes.add((SchemaChange.UpdateColumnType) change);
} else if (change instanceof SchemaChange.UpdateColumnNullability) {
updateColumnNullabilities.add((SchemaChange.UpdateColumnNullability) change);
} else if (change instanceof SchemaChange.UpdateColumnComment) {
updateColumnComments.add((SchemaChange.UpdateColumnComment) change);
} else if (change instanceof SchemaChange.UpdateColumnPosition) {
updateColumnPositions.add(((SchemaChange.UpdateColumnPosition) change).move());
}
}
this.setOptions = setOptions;
this.removeOptions = removeOptions;
this.comment = comment;
this.addColumns = addColumns;
this.renameColumns = renameColumns;
this.dropColumns = dropColumns;
this.updateColumnTypes = updateColumnTypes;
this.updateColumnNullabilities = updateColumnNullabilities;
this.updateColumnComments = updateColumnComments;
this.updateColumnPositions = updateColumnPositions;
}

@JsonGetter(FIELD_SET_OPTIONS)
public Map<String, String> getSetOptions() {
return setOptions;
}

@JsonGetter(FIELD_REMOVE_OPTIONS)
public List<String> getRemoveOptions() {
return removeOptions;
}

@JsonGetter(FIELD_COMMENT)
public String getComment() {
return comment;
}

@JsonGetter(FIELD_ADD_COLUMNS)
public List<SchemaChange.AddColumn> getAddColumns() {
return addColumns;
}

@JsonGetter(FIELD_RENAME_COLUMNS)
public List<SchemaChange.RenameColumn> getRenameColumns() {
return renameColumns;
}

public List<SchemaChange.DropColumn> getDropColumns() {
@JsonGetter(FIELD_DROP_COLUMNS)
public List<String> getDropColumns() {
return dropColumns;
}

@JsonGetter(FIELD_UPDATE_COLUMN_TYPES)
public List<SchemaChange.UpdateColumnType> getUpdateColumnTypes() {
return updateColumnTypes;
}

@JsonGetter(FIELD_UPDATE_COLUMN_NULLABILITIES)
public List<SchemaChange.UpdateColumnNullability> getUpdateColumnNullabilities() {
return updateColumnNullabilities;
}

@JsonGetter(FIELD_UPDATE_COLUMN_COMMENTS)
public List<SchemaChange.UpdateColumnComment> getUpdateColumnComments() {
return updateColumnComments;
}

public List<SchemaChange.UpdateColumnPosition> getUpdateColumnPositions() {
@JsonGetter(FIELD_UPDATE_COLUMN_POSITIONS)
public List<SchemaChange.Move> getUpdateColumnPositions() {
return updateColumnPositions;
}
}

This file was deleted.

Loading

0 comments on commit 0b10fe6

Please sign in to comment.