Skip to content

Commit

Permalink
add ParentChildRelationSqlService (#595)
Browse files Browse the repository at this point in the history
* add ParentChildRelationSqlService

* add search endpoint

* add isParent field + address comments

---------

Co-authored-by: Yingjian Wu <yingjianw@netflix.com>
  • Loading branch information
stevie9868 and Yingjian Wu authored Jul 2, 2024
1 parent 8ca992e commit e9fce8d
Show file tree
Hide file tree
Showing 20 changed files with 1,767 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
import com.fasterxml.jackson.datatype.guava.GuavaModule;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
import com.google.common.base.Preconditions;
import com.netflix.metacat.client.api.MetacatV1;
import com.netflix.metacat.client.api.MetadataV1;
import com.netflix.metacat.client.api.ParentChildRelV1;
import com.netflix.metacat.client.api.PartitionV1;
import com.netflix.metacat.client.api.ResolverV1;
import com.netflix.metacat.client.api.TagV1;
import com.netflix.metacat.client.module.JacksonDecoder;
import com.netflix.metacat.client.module.JacksonEncoder;
import com.netflix.metacat.client.module.MetacatErrorDecoder;
import com.netflix.metacat.common.MetacatRequestContext;
import com.netflix.metacat.client.api.MetacatV1;
import com.netflix.metacat.client.api.MetadataV1;
import com.netflix.metacat.client.api.PartitionV1;
import com.netflix.metacat.client.api.ResolverV1;
import com.netflix.metacat.common.json.MetacatJsonLocator;
import feign.Feign;
import feign.Request;
Expand Down Expand Up @@ -58,6 +59,8 @@ public final class Client {
private final ResolverV1 resolverApi;
private final TagV1 tagApi;

private final ParentChildRelV1 parentChildRelApi;

private Client(
final String host,
final feign.Client client,
Expand Down Expand Up @@ -93,6 +96,7 @@ private Client(
metadataApi = getApiClient(MetadataV1.class);
resolverApi = getApiClient(ResolverV1.class);
tagApi = getApiClient(TagV1.class);
parentChildRelApi = getApiClient(ParentChildRelV1.class);
}

/**
Expand Down Expand Up @@ -163,6 +167,15 @@ public TagV1 getTagApi() {
return tagApi;
}

/**
* Return an API instance that can be used to interact with
* the metacat server for parent child relationship metadata.
* @return An instance api conforming to ParentChildRelV1 interface
*/
public ParentChildRelV1 getParentChildRelApi() {
return parentChildRelApi;
}

/**
* Builder class to build the metacat client.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.netflix.metacat.client.api;

import javax.ws.rs.Path;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.GET;
import javax.ws.rs.PathParam;

import javax.ws.rs.core.MediaType;
import com.netflix.metacat.common.dto.notifications.ChildInfoDto;

import java.util.Set;

/**
* Metacat API for managing parent child relation.
*
* @author Yingjianw
*/

@Path("/mds/v1/parentChildRel")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public interface ParentChildRelV1 {
/**
* Return the list of children.
* @param catalogName catalogName
* @param databaseName databaseName
* @param tableName tableName
* @return list of childInfos
*/
@GET
@Path("children/catalog/{catalog-name}/database/{database-name}/table/{table-name}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
Set<ChildInfoDto> getChildren(
@PathParam("catalog-name")
String catalogName,
@PathParam("database-name")
String databaseName,
@PathParam("table-name")
String tableName
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.netflix.metacat.common.dto.Sort;
import com.netflix.metacat.common.dto.StorageDto;
import com.netflix.metacat.common.dto.TableDto;
import com.netflix.metacat.common.dto.notifications.ChildInfoDto;
import com.netflix.metacat.common.server.connectors.ConnectorRequestContext;
import com.netflix.metacat.common.server.connectors.model.AuditInfo;
import com.netflix.metacat.common.server.connectors.model.CatalogInfo;
Expand All @@ -46,6 +47,7 @@
import com.netflix.metacat.common.server.connectors.model.PartitionsSaveResponse;
import com.netflix.metacat.common.server.connectors.model.StorageInfo;
import com.netflix.metacat.common.server.connectors.model.TableInfo;
import com.netflix.metacat.common.server.model.ChildInfo;
import lombok.NonNull;
import org.dozer.CustomConverter;
import org.dozer.DozerBeanMapper;
Expand Down Expand Up @@ -276,5 +278,13 @@ public PartitionsSaveResponseDto toPartitionsSaveResponseDto(final PartitionsSav
return mapper.map(partitionsSaveResponse, PartitionsSaveResponseDto.class);
}


/**
* Convert ChildInfo to ChildInfoDto.
*
* @param childInfo childInfo
* @return childInfo dto
*/
public ChildInfoDto toChildInfoDto(final ChildInfo childInfo) {
return mapper.map(childInfo, ChildInfoDto.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.netflix.metacat.common.server.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* Base class to represent relation entity.
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public abstract class BaseRelEntityInfo implements Serializable {
private static final long serialVersionUID = 9121109874202888889L;
private String name;
private String relationType;
private String uuid;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.netflix.metacat.common.server.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
* ChildInfo.
*/
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@Data
public class ChildInfo extends BaseRelEntityInfo {
/**
Constructor with all params.
@param name name of the entity
@param relationType type of the relation
@param uuid uuid of the entity
*/
public ChildInfo(final String name, final String relationType, final String uuid) {
super(name, relationType, uuid);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.netflix.metacat.common.server.model;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
* ParentInfo.
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class ParentInfo extends BaseRelEntityInfo {

/**
Empty Constructor.
*/
public ParentInfo() {

}

/**
Constructor with all params.
@param name name of the entity
@param relationType type of the relation
@param uuid uuid of the entity
*/
public ParentInfo(final String name, final String relationType, final String uuid) {
super(name, relationType, uuid);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.netflix.metacat.common.server.usermetadata;

/**
* ParentChildRelMetadataConstants.
*
* @author yingjianw
*/
public final class ParentChildRelMetadataConstants {
/**
* During get and create, top level key specified in DefinitionMetadata that indicates the parent child infos.
*/
public static final String PARENT_CHILD_RELINFO = "parentChildRelationInfo";
/**
* During create, nested level key specified in DefinitionMetadata['parentChildRelationInfo']
* that indicate the parent table name.
*/
public static final String PARENT_NAME = "root_table_name";
/**
* During create, nested level key specified in DefinitionMetadata['parentChildRelationInfo']
* that indicates the parent table uuid.
*/
public static final String PARENT_UUID = "root_table_uuid";
/**
* During create, nested level key specified in DefinitionMetadata['parentChildRelationInfo']
* that indicates the child table uuid.
*/
public static final String CHILD_UUID = "child_table_uuid";

/**
* During create, nested level key specified in DefinitionMetadata['parentChildRelationInfo']
* that indicates relationType.
*/
public static final String RELATION_TYPE = "relationType";

/**
* During get, the nested key specified in DefinitionMetadata[PARENTCHILDRELINFO] that indicates parent infos.
*/
public static final String PARENT_INFOS = "parentInfos";

/**
* During get, the nested key specified in DefinitionMetadata[PARENTCHILDRELINFO] that indicates child infos.
*/
public static final String CHILD_INFOS = "childInfos";

/**
* During get, the nested key specified in DefinitionMetadata[PARENTCHILDRELINFO]
* that indicates if a table is parent.
*/
public static final String IS_PARENT = "isParent";

private ParentChildRelMetadataConstants() {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.netflix.metacat.common.server.usermetadata;
import com.netflix.metacat.common.QualifiedName;
import com.netflix.metacat.common.dto.notifications.ChildInfoDto;
import com.netflix.metacat.common.server.model.ChildInfo;
import com.netflix.metacat.common.server.model.ParentInfo;

import java.util.Set;

/**
* Parent-Child Relationship Metadata Service API.
*
* @author yingjianw
*/
public interface ParentChildRelMetadataService {
/**
* Establishes a parent-child relationship with a specified relation type.
* Currently, exceptions are thrown in the following cases:
* 1. Attempting to create a child table as the parent of another child table.
* 2. Attempting to create a parent table on top of a parent table
* 3. A child table having more than one parent.
*
* @param parentName the name of the parent entity
* @param parentUUID the uuid of the parent
* @param childName the name of the child entity
* @param childUUID the uuid of the child
* @param relationType the type of the relationship
*/
void createParentChildRelation(
QualifiedName parentName,
String parentUUID,
QualifiedName childName,
String childUUID,
String relationType
);

/**
* Deletes a parent-child relationship with a specified relation type.
* This function is only called in the recovery process when
* we first create the parent-child relationship but fail to create the table.
*
* @param parentName the name of the parent entity
* @param parentUUID the uuid of the parent
* @param childName the name of the child entity
* @param childUUID the uuid of the child
* @param type the type of the relationship
*/
void deleteParentChildRelation(
QualifiedName parentName,
String parentUUID,
QualifiedName childName,
String childUUID,
String type
);

/**
* Renames `oldName` to `newName` in the parentChildRelationship store.
* This involves two steps:
* 1. Rename all records where the child is `oldName` to `newName`
* 2. Rename all records where the parent is `oldName` to `newName`
*
* @param oldName the current name to be renamed
* @param newName the new name to rename to
*/
void rename(
QualifiedName oldName,
QualifiedName newName
);

/**
* Removes the entity from the parentChildRelationship store.
* This involves two steps:
* 1. drop all records where the child column = `name`
* 2. drop all records where the parent column = `name`
* @param name the name of the entity to drop
*/
void drop(
QualifiedName name
);

/**
* get the set of parent for the input name.
* @param name name
* @return parentInfo
*/
Set<ParentInfo> getParents(
QualifiedName name
);

/**
* get the set of children for the input name.
* @param name name
* @return a set of ChildInfo
*/
Set<ChildInfo> getChildren(
QualifiedName name
);

/**
* get the set of children dto for the input name.
* @param name name
* @return a set of ChildInfo
*/
Set<ChildInfoDto> getChildrenDto(
QualifiedName name
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.netflix.metacat.common.server.usermetadata;

/**
* Parent Child Rel Service exception.
*/
public class ParentChildRelServiceException extends RuntimeException {
/**
* Constructor.
*
* @param m message
*/
public ParentChildRelServiceException(final String m) {
super(m);
}

/**
* Constructor.
*
* @param m message
* @param e exception
*/
public ParentChildRelServiceException(final String m, final Exception e) {
super(m, e);
}
}
Loading

0 comments on commit e9fce8d

Please sign in to comment.