Skip to content

Commit

Permalink
[apache#1724] feat(server):Add server-side REST API support for fileset
Browse files Browse the repository at this point in the history
  • Loading branch information
XIAOMIlipeidian committed Jan 27, 2024
1 parent 26a4b3d commit 85216f2
Show file tree
Hide file tree
Showing 8 changed files with 557 additions and 0 deletions.
14 changes: 14 additions & 0 deletions api/src/main/java/com/datastrato/gravitino/NameIdentifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ public static NameIdentifier ofTable(
return NameIdentifier.of(metalake, catalog, schema, table);
}

/**
* Create the table {@link NameIdentifier} with the given metalake, catalog, schema and fileset
* name.
*
* @param metalake The metalake name
* @param catalog The catalog name
* @param schema The schema name
* @param fileset The fileset name
* @return The created table {@link NameIdentifier}
*/
public static NameIdentifier ofFileset(String metalake, String catalog, String schema, String fileset) {
return NameIdentifier.of(metalake, catalog, schema, fileset);
}

/**
* Check the given {@link NameIdentifier} is a metalake identifier. Throw an {@link
* IllegalNameIdentifierException} if it's not.
Expand Down
12 changes: 12 additions & 0 deletions api/src/main/java/com/datastrato/gravitino/Namespace.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ public static Namespace ofTable(String metalake, String catalog, String schema)
return of(metalake, catalog, schema);
}

/**
* Create a namespace for fileset.
*
* @param metalake The metalake name
* @param catalog The catalog name
* @param schema The schema name
* @return A namespace for table
*/
public static Namespace ofFileset(String metalake, String catalog, String schema) {
return of(metalake, catalog, schema);
}

/**
* Check if the given metalake namespace is legal, throw an {@link IllegalNamespaceException} if
* it's illegal.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright 2023 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
package com.datastrato.gravitino.dto.file;

import com.datastrato.gravitino.Audit;
import com.datastrato.gravitino.file.Fileset;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Map;
import javax.annotation.Nullable;
import lombok.Builder;

/** Represents a Fileset DTO (Data Transfer Object). */
@Builder
public class FilesetDTO implements Fileset {

@JsonProperty("name")
private String name;

@JsonProperty("comment")
private String comment;

@JsonProperty("type")
private Type type;

@JsonProperty("storageLocation")
private String storageLocation;

@JsonProperty("properties")
private Map<String, String> properties;

@JsonProperty("audit")
private Audit audit;

private FilesetDTO() {
}

/**
* Construct a fileset DTO.
* @param name The name of the fileset.
* @param comment The comment of the fileset.
* @param type The type of the fileset.
* @param storageLocation The storageLocation of the fileset.
* @param properties The properties associated with fileset.
* @param audit The audit information of fileset.
*/
private FilesetDTO(
String name, String comment, Type type, String storageLocation, Map<String, String> properties,
Audit audit) {
this.name = name;
this.comment = comment;
this.type = type;
this.storageLocation = storageLocation;
this.properties = properties;
this.audit = audit;
}

@Override
public String name() {
return name;
}

@Nullable
@Override
public String comment() {
return comment;
}

@Override
public Type type() {
return type;
}

@Override
public String storageLocation() {
return storageLocation;
}

@Override
public Map<String, String> properties() {
return properties;
}

@Override
public Audit auditInfo() {
return audit;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2023 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
package com.datastrato.gravitino.dto.requests;

import com.datastrato.gravitino.file.Fileset;
import com.datastrato.gravitino.rest.RESTRequest;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import java.util.Map;
import javax.annotation.Nullable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;
import org.apache.commons.lang3.StringUtils;

@Getter
@EqualsAndHashCode
@ToString
@Builder
@Jacksonized
@NoArgsConstructor
@AllArgsConstructor
public class FilesetCreateRequest implements RESTRequest {

@JsonProperty("name")
private String name;

@Nullable
@JsonProperty("comment")
private String comment;

@Nullable
@JsonProperty("type")
private Fileset.Type type;

@Nullable
@JsonProperty("storageLocation")
private String storageLocation;

@Nullable
@JsonProperty("properties")
private Map<String, String> properties;

@Override
public void validate() throws IllegalArgumentException {
Preconditions.checkArgument(
StringUtils.isNotBlank(name), "\"name\" field is required and cannot be empty");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Copyright 2023 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
package com.datastrato.gravitino.dto.requests;

import com.datastrato.gravitino.file.FilesetChange;
import com.datastrato.gravitino.rest.RESTRequest;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.google.common.base.Preconditions;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY)
@JsonSubTypes({
@JsonSubTypes.Type(value = TableUpdateRequest.RenameTableRequest.class, name = "rename"),
@JsonSubTypes.Type(
value = TableUpdateRequest.UpdateTableCommentRequest.class,
name = "updateComment"),
@JsonSubTypes.Type(
value = TableUpdateRequest.SetTablePropertyRequest.class,
name = "setProperty"),
@JsonSubTypes.Type(
value = TableUpdateRequest.RemoveTablePropertyRequest.class,
name = "removeProperty")
})
public interface FilesetUpdateRequest extends RESTRequest {
FilesetChange filesetChange();

@EqualsAndHashCode
@AllArgsConstructor
@ToString
class RenameFilesetRequest implements FilesetUpdateRequest {

@Getter
@JsonProperty("newName")
private final String newName;

@Override
public FilesetChange filesetChange() {
return FilesetChange.rename(newName);
}

@Override
public void validate() throws IllegalArgumentException {
Preconditions.checkArgument(
StringUtils.isNotBlank(newName), "\"newName\" field is required and cannot be empty");
}
}

@EqualsAndHashCode
@AllArgsConstructor
@ToString
class UpdateFilesetCommentRequest implements FilesetUpdateRequest {

@Getter
@JsonProperty("newComment")
private final String newComment;

@Override
public FilesetChange filesetChange() {
return FilesetChange.updateComment(newComment);
}

@Override
public void validate() throws IllegalArgumentException {
Preconditions.checkArgument(
StringUtils.isNotBlank(newComment),
"\"newComment\" field is required and cannot be empty");
}
}

@EqualsAndHashCode
@AllArgsConstructor
@ToString
class SetFilesetPropertiesRequest implements FilesetUpdateRequest {

@Getter
@JsonProperty("property")
private final String property;

@Getter
@JsonProperty("value")
private final String value;

@Override
public FilesetChange filesetChange() {
return FilesetChange.setProperty(property, value);
}

@Override
public void validate() throws IllegalArgumentException {
Preconditions.checkArgument(
StringUtils.isNotBlank(property), "\"property\" field is required and cannot be empty");
Preconditions.checkArgument(value != null, "\"value\" field is required and cannot be null");
}
}

@EqualsAndHashCode
@AllArgsConstructor
@ToString
class RemoveFilesetPropertiesRequest implements FilesetUpdateRequest {

@Getter
@JsonProperty("property")
private final String property;

@Override
public FilesetChange filesetChange() {
return FilesetChange.removeProperty(property);
}

@Override
public void validate() throws IllegalArgumentException {
Preconditions.checkArgument(
StringUtils.isNotBlank(property), "\"property\" field is required and cannot be empty");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2023 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
package com.datastrato.gravitino.dto.requests;

import com.datastrato.gravitino.rest.RESTMessage;
import com.datastrato.gravitino.rest.RESTRequest;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

@Getter
@EqualsAndHashCode
@AllArgsConstructor
@ToString
public class FilesetUpdatesRequest implements RESTRequest {

@JsonProperty("updates")
private final List<FilesetUpdateRequest> updates;
@Override
public void validate() throws IllegalArgumentException {
updates.forEach(RESTMessage::validate);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2023 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
package com.datastrato.gravitino.dto.responses;

import com.datastrato.gravitino.dto.file.FilesetDTO;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

@Getter
@ToString
@EqualsAndHashCode(callSuper = true)
public class FilesetResponse extends BaseResponse {

@JsonProperty("fileset")
private final FilesetDTO fileset;

public FilesetResponse() {
super(0);
this.fileset = null;
}

public FilesetResponse(FilesetDTO fileset) {
super(0);
this.fileset = fileset;
}

@Override
public void validate() throws IllegalArgumentException {
super.validate();
Preconditions.checkArgument(fileset != null, "fileset must not be null");
Preconditions.checkArgument(
StringUtils.isNotBlank(fileset.name()), "fileset 'name' must not be null and empty");
}
}
Loading

0 comments on commit 85216f2

Please sign in to comment.