Skip to content

Commit e9fce8d

Browse files
stevie9868Yingjian Wu
and
Yingjian Wu
authored
add ParentChildRelationSqlService (#595)
* add ParentChildRelationSqlService * add search endpoint * add isParent field + address comments --------- Co-authored-by: Yingjian Wu <[email protected]>
1 parent 8ca992e commit e9fce8d

File tree

20 files changed

+1767
-23
lines changed

20 files changed

+1767
-23
lines changed

metacat-client/src/main/java/com/netflix/metacat/client/Client.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@
2121
import com.fasterxml.jackson.datatype.guava.GuavaModule;
2222
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
2323
import com.google.common.base.Preconditions;
24+
import com.netflix.metacat.client.api.MetacatV1;
25+
import com.netflix.metacat.client.api.MetadataV1;
26+
import com.netflix.metacat.client.api.ParentChildRelV1;
27+
import com.netflix.metacat.client.api.PartitionV1;
28+
import com.netflix.metacat.client.api.ResolverV1;
2429
import com.netflix.metacat.client.api.TagV1;
2530
import com.netflix.metacat.client.module.JacksonDecoder;
2631
import com.netflix.metacat.client.module.JacksonEncoder;
2732
import com.netflix.metacat.client.module.MetacatErrorDecoder;
2833
import com.netflix.metacat.common.MetacatRequestContext;
29-
import com.netflix.metacat.client.api.MetacatV1;
30-
import com.netflix.metacat.client.api.MetadataV1;
31-
import com.netflix.metacat.client.api.PartitionV1;
32-
import com.netflix.metacat.client.api.ResolverV1;
3334
import com.netflix.metacat.common.json.MetacatJsonLocator;
3435
import feign.Feign;
3536
import feign.Request;
@@ -58,6 +59,8 @@ public final class Client {
5859
private final ResolverV1 resolverApi;
5960
private final TagV1 tagApi;
6061

62+
private final ParentChildRelV1 parentChildRelApi;
63+
6164
private Client(
6265
final String host,
6366
final feign.Client client,
@@ -93,6 +96,7 @@ private Client(
9396
metadataApi = getApiClient(MetadataV1.class);
9497
resolverApi = getApiClient(ResolverV1.class);
9598
tagApi = getApiClient(TagV1.class);
99+
parentChildRelApi = getApiClient(ParentChildRelV1.class);
96100
}
97101

98102
/**
@@ -163,6 +167,15 @@ public TagV1 getTagApi() {
163167
return tagApi;
164168
}
165169

170+
/**
171+
* Return an API instance that can be used to interact with
172+
* the metacat server for parent child relationship metadata.
173+
* @return An instance api conforming to ParentChildRelV1 interface
174+
*/
175+
public ParentChildRelV1 getParentChildRelApi() {
176+
return parentChildRelApi;
177+
}
178+
166179
/**
167180
* Builder class to build the metacat client.
168181
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.netflix.metacat.client.api;
2+
3+
import javax.ws.rs.Path;
4+
import javax.ws.rs.Consumes;
5+
import javax.ws.rs.Produces;
6+
import javax.ws.rs.GET;
7+
import javax.ws.rs.PathParam;
8+
9+
import javax.ws.rs.core.MediaType;
10+
import com.netflix.metacat.common.dto.notifications.ChildInfoDto;
11+
12+
import java.util.Set;
13+
14+
/**
15+
* Metacat API for managing parent child relation.
16+
*
17+
* @author Yingjianw
18+
*/
19+
20+
@Path("/mds/v1/parentChildRel")
21+
@Consumes(MediaType.APPLICATION_JSON)
22+
@Produces(MediaType.APPLICATION_JSON)
23+
public interface ParentChildRelV1 {
24+
/**
25+
* Return the list of children.
26+
* @param catalogName catalogName
27+
* @param databaseName databaseName
28+
* @param tableName tableName
29+
* @return list of childInfos
30+
*/
31+
@GET
32+
@Path("children/catalog/{catalog-name}/database/{database-name}/table/{table-name}")
33+
@Consumes(MediaType.APPLICATION_JSON)
34+
@Produces(MediaType.APPLICATION_JSON)
35+
Set<ChildInfoDto> getChildren(
36+
@PathParam("catalog-name")
37+
String catalogName,
38+
@PathParam("database-name")
39+
String databaseName,
40+
@PathParam("table-name")
41+
String tableName
42+
);
43+
}

metacat-common-server/src/main/java/com/netflix/metacat/common/server/converter/ConverterUtil.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.netflix.metacat.common.dto.Sort;
3434
import com.netflix.metacat.common.dto.StorageDto;
3535
import com.netflix.metacat.common.dto.TableDto;
36+
import com.netflix.metacat.common.dto.notifications.ChildInfoDto;
3637
import com.netflix.metacat.common.server.connectors.ConnectorRequestContext;
3738
import com.netflix.metacat.common.server.connectors.model.AuditInfo;
3839
import com.netflix.metacat.common.server.connectors.model.CatalogInfo;
@@ -46,6 +47,7 @@
4647
import com.netflix.metacat.common.server.connectors.model.PartitionsSaveResponse;
4748
import com.netflix.metacat.common.server.connectors.model.StorageInfo;
4849
import com.netflix.metacat.common.server.connectors.model.TableInfo;
50+
import com.netflix.metacat.common.server.model.ChildInfo;
4951
import lombok.NonNull;
5052
import org.dozer.CustomConverter;
5153
import org.dozer.DozerBeanMapper;
@@ -276,5 +278,13 @@ public PartitionsSaveResponseDto toPartitionsSaveResponseDto(final PartitionsSav
276278
return mapper.map(partitionsSaveResponse, PartitionsSaveResponseDto.class);
277279
}
278280

279-
281+
/**
282+
* Convert ChildInfo to ChildInfoDto.
283+
*
284+
* @param childInfo childInfo
285+
* @return childInfo dto
286+
*/
287+
public ChildInfoDto toChildInfoDto(final ChildInfo childInfo) {
288+
return mapper.map(childInfo, ChildInfoDto.class);
289+
}
280290
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.netflix.metacat.common.server.model;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
import java.io.Serializable;
8+
9+
/**
10+
* Base class to represent relation entity.
11+
*/
12+
@Data
13+
@AllArgsConstructor
14+
@NoArgsConstructor
15+
public abstract class BaseRelEntityInfo implements Serializable {
16+
private static final long serialVersionUID = 9121109874202888889L;
17+
private String name;
18+
private String relationType;
19+
private String uuid;
20+
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.netflix.metacat.common.server.model;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
7+
/**
8+
* ChildInfo.
9+
*/
10+
@EqualsAndHashCode(callSuper = true)
11+
@AllArgsConstructor
12+
@Data
13+
public class ChildInfo extends BaseRelEntityInfo {
14+
/**
15+
Constructor with all params.
16+
@param name name of the entity
17+
@param relationType type of the relation
18+
@param uuid uuid of the entity
19+
*/
20+
public ChildInfo(final String name, final String relationType, final String uuid) {
21+
super(name, relationType, uuid);
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.netflix.metacat.common.server.model;
2+
3+
import lombok.Data;
4+
import lombok.EqualsAndHashCode;
5+
6+
/**
7+
* ParentInfo.
8+
*/
9+
@EqualsAndHashCode(callSuper = true)
10+
@Data
11+
public class ParentInfo extends BaseRelEntityInfo {
12+
13+
/**
14+
Empty Constructor.
15+
*/
16+
public ParentInfo() {
17+
18+
}
19+
20+
/**
21+
Constructor with all params.
22+
@param name name of the entity
23+
@param relationType type of the relation
24+
@param uuid uuid of the entity
25+
*/
26+
public ParentInfo(final String name, final String relationType, final String uuid) {
27+
super(name, relationType, uuid);
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.netflix.metacat.common.server.usermetadata;
2+
3+
/**
4+
* ParentChildRelMetadataConstants.
5+
*
6+
* @author yingjianw
7+
*/
8+
public final class ParentChildRelMetadataConstants {
9+
/**
10+
* During get and create, top level key specified in DefinitionMetadata that indicates the parent child infos.
11+
*/
12+
public static final String PARENT_CHILD_RELINFO = "parentChildRelationInfo";
13+
/**
14+
* During create, nested level key specified in DefinitionMetadata['parentChildRelationInfo']
15+
* that indicate the parent table name.
16+
*/
17+
public static final String PARENT_NAME = "root_table_name";
18+
/**
19+
* During create, nested level key specified in DefinitionMetadata['parentChildRelationInfo']
20+
* that indicates the parent table uuid.
21+
*/
22+
public static final String PARENT_UUID = "root_table_uuid";
23+
/**
24+
* During create, nested level key specified in DefinitionMetadata['parentChildRelationInfo']
25+
* that indicates the child table uuid.
26+
*/
27+
public static final String CHILD_UUID = "child_table_uuid";
28+
29+
/**
30+
* During create, nested level key specified in DefinitionMetadata['parentChildRelationInfo']
31+
* that indicates relationType.
32+
*/
33+
public static final String RELATION_TYPE = "relationType";
34+
35+
/**
36+
* During get, the nested key specified in DefinitionMetadata[PARENTCHILDRELINFO] that indicates parent infos.
37+
*/
38+
public static final String PARENT_INFOS = "parentInfos";
39+
40+
/**
41+
* During get, the nested key specified in DefinitionMetadata[PARENTCHILDRELINFO] that indicates child infos.
42+
*/
43+
public static final String CHILD_INFOS = "childInfos";
44+
45+
/**
46+
* During get, the nested key specified in DefinitionMetadata[PARENTCHILDRELINFO]
47+
* that indicates if a table is parent.
48+
*/
49+
public static final String IS_PARENT = "isParent";
50+
51+
private ParentChildRelMetadataConstants() {
52+
53+
}
54+
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package com.netflix.metacat.common.server.usermetadata;
2+
import com.netflix.metacat.common.QualifiedName;
3+
import com.netflix.metacat.common.dto.notifications.ChildInfoDto;
4+
import com.netflix.metacat.common.server.model.ChildInfo;
5+
import com.netflix.metacat.common.server.model.ParentInfo;
6+
7+
import java.util.Set;
8+
9+
/**
10+
* Parent-Child Relationship Metadata Service API.
11+
*
12+
* @author yingjianw
13+
*/
14+
public interface ParentChildRelMetadataService {
15+
/**
16+
* Establishes a parent-child relationship with a specified relation type.
17+
* Currently, exceptions are thrown in the following cases:
18+
* 1. Attempting to create a child table as the parent of another child table.
19+
* 2. Attempting to create a parent table on top of a parent table
20+
* 3. A child table having more than one parent.
21+
*
22+
* @param parentName the name of the parent entity
23+
* @param parentUUID the uuid of the parent
24+
* @param childName the name of the child entity
25+
* @param childUUID the uuid of the child
26+
* @param relationType the type of the relationship
27+
*/
28+
void createParentChildRelation(
29+
QualifiedName parentName,
30+
String parentUUID,
31+
QualifiedName childName,
32+
String childUUID,
33+
String relationType
34+
);
35+
36+
/**
37+
* Deletes a parent-child relationship with a specified relation type.
38+
* This function is only called in the recovery process when
39+
* we first create the parent-child relationship but fail to create the table.
40+
*
41+
* @param parentName the name of the parent entity
42+
* @param parentUUID the uuid of the parent
43+
* @param childName the name of the child entity
44+
* @param childUUID the uuid of the child
45+
* @param type the type of the relationship
46+
*/
47+
void deleteParentChildRelation(
48+
QualifiedName parentName,
49+
String parentUUID,
50+
QualifiedName childName,
51+
String childUUID,
52+
String type
53+
);
54+
55+
/**
56+
* Renames `oldName` to `newName` in the parentChildRelationship store.
57+
* This involves two steps:
58+
* 1. Rename all records where the child is `oldName` to `newName`
59+
* 2. Rename all records where the parent is `oldName` to `newName`
60+
*
61+
* @param oldName the current name to be renamed
62+
* @param newName the new name to rename to
63+
*/
64+
void rename(
65+
QualifiedName oldName,
66+
QualifiedName newName
67+
);
68+
69+
/**
70+
* Removes the entity from the parentChildRelationship store.
71+
* This involves two steps:
72+
* 1. drop all records where the child column = `name`
73+
* 2. drop all records where the parent column = `name`
74+
* @param name the name of the entity to drop
75+
*/
76+
void drop(
77+
QualifiedName name
78+
);
79+
80+
/**
81+
* get the set of parent for the input name.
82+
* @param name name
83+
* @return parentInfo
84+
*/
85+
Set<ParentInfo> getParents(
86+
QualifiedName name
87+
);
88+
89+
/**
90+
* get the set of children for the input name.
91+
* @param name name
92+
* @return a set of ChildInfo
93+
*/
94+
Set<ChildInfo> getChildren(
95+
QualifiedName name
96+
);
97+
98+
/**
99+
* get the set of children dto for the input name.
100+
* @param name name
101+
* @return a set of ChildInfo
102+
*/
103+
Set<ChildInfoDto> getChildrenDto(
104+
QualifiedName name
105+
);
106+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.netflix.metacat.common.server.usermetadata;
2+
3+
/**
4+
* Parent Child Rel Service exception.
5+
*/
6+
public class ParentChildRelServiceException extends RuntimeException {
7+
/**
8+
* Constructor.
9+
*
10+
* @param m message
11+
*/
12+
public ParentChildRelServiceException(final String m) {
13+
super(m);
14+
}
15+
16+
/**
17+
* Constructor.
18+
*
19+
* @param m message
20+
* @param e exception
21+
*/
22+
public ParentChildRelServiceException(final String m, final Exception e) {
23+
super(m, e);
24+
}
25+
}

0 commit comments

Comments
 (0)