Skip to content

Commit

Permalink
add isParent field + address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Yingjian Wu committed Jun 27, 2024
1 parent 7096045 commit 98f590d
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 91 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +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;

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

}

/**
Constructor with all params.
@param name name of the entity
@param relationType type of the relation
@param uuid uuid of the entity
*/
public BaseRelEntityInfo(final String name, final String relationType, final String uuid) {
this.name = name;
this.relationType = relationType;
this.uuid = uuid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,46 @@
*/
public final class ParentChildRelMetadataConstants {
/**
* During create, top level key specified in DefinitionMetadata that indicate the parent table name.
* During get and create, top level key specified in DefinitionMetadata that indicates the parent child infos.
*/
public static final String PARENTNAME = "root_table_name";
public static final String PARENT_CHILD_RELINFO = "parentChildRelationInfo";
/**
* During create, top level key specified in DefinitionMetadata that indicates the parent table uuid.
* During create, nested level key specified in DefinitionMetadata['parentChildRelationInfo']
* that indicate the parent table name.
*/
public static final String PARENTUUID = "root_table_uuid";
public static final String PARENT_NAME = "root_table_name";
/**
* During create, top level key specified in DefinitionMetadata that indicates the child table uuid.
* During create, nested level key specified in DefinitionMetadata['parentChildRelationInfo']
* that indicates the parent table uuid.
*/
public static final String CHILDUUID = "child_table_uuid";

public static final String PARENT_UUID = "root_table_uuid";
/**
* During create, top level key specified in DefinitionMetadata that indicates relationType.
* During create, nested level key specified in DefinitionMetadata['parentChildRelationInfo']
* that indicates the child table uuid.
*/
public static final String RELATIONTYPE = "relationType";
public static final String CHILD_UUID = "child_table_uuid";

/**
* During get, top level key specified in DefinitionMetadata that indicates the parent child infos.
* During create, nested level key specified in DefinitionMetadata['parentChildRelationInfo']
* that indicates relationType.
*/
public static final String PARENTCHILDRELINFO = "parentChildRelationInfo";
public static final String RELATION_TYPE = "relationType";

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

/**
* During get, the nested key specified in DefinitionMetadata[PARENTCHILDRELINFO] that indicates child infos.
*/
public static final String CHILDINFOS = "childInfos";
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() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.netflix.metacat

import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.metacat.client.Client
import com.netflix.metacat.client.api.MetacatV1
import com.netflix.metacat.client.api.MetadataV1
Expand All @@ -33,6 +35,7 @@ import com.netflix.metacat.common.exception.MetacatUnAuthorizedException
import com.netflix.metacat.common.json.MetacatJson
import com.netflix.metacat.common.json.MetacatJsonLocator
import com.netflix.metacat.common.server.connectors.exception.InvalidMetaException
import com.netflix.metacat.common.server.usermetadata.ParentChildRelMetadataConstants
import com.netflix.metacat.connector.hive.util.PartitionUtil
import com.netflix.metacat.testdata.provider.PigDataDtoProvider
import feign.Logger
Expand Down Expand Up @@ -141,6 +144,19 @@ class MetacatSmokeSpec extends Specification {
}
}

static void initializeParentChildRelDefinitionMetadata(TableDto tableDto,
String parent,
String parent_uuid,
String child_uuid) {
def mapper = new ObjectMapper()
def innerNode = mapper.createObjectNode()
innerNode.put(ParentChildRelMetadataConstants.PARENT_NAME, parent)
innerNode.put(ParentChildRelMetadataConstants.PARENT_UUID, parent_uuid)
innerNode.put(ParentChildRelMetadataConstants.CHILD_UUID, child_uuid)

tableDto.definitionMetadata.put(ParentChildRelMetadataConstants.PARENT_CHILD_RELINFO, innerNode)
}

def createAllTypesTable() {
when:
createTable('embedded-hive-metastore', 'smoke_db', 'metacat_all_types')
Expand Down Expand Up @@ -1977,7 +1993,7 @@ class MetacatSmokeSpec extends Specification {
def parent1UUID = "p1_uuid"
def renameParent1 = "rename_parent1"
def parent1Uri = isLocalEnv ? String.format('file:/tmp/%s/%s', databaseName, parent1) : null
def parent1FullName = catalogName + "." + databaseName + "." + parent1
def parent1FullName = catalogName + "/" + databaseName + "/" + parent1
def child11 = "child11"
def child11UUID = "c11_uuid"
Expand All @@ -1997,7 +2013,7 @@ class MetacatSmokeSpec extends Specification {
def parent2 = "parent2"
def parent2UUID = "p2_uuid"
def parent2Uri = isLocalEnv ? String.format('file:/tmp/%s/%s', databaseName, parent2) : null
def parent2FullName = catalogName + "." + databaseName + "." + parent2
def parent2FullName = catalogName + "/" + databaseName + "/" + parent2
def child21 = "child21"
def child21UUID = "c21_uuid"
def child21Uri = isLocalEnv ? String.format('file:/tmp/%s/%s', databaseName, child21) : null
Expand All @@ -2017,20 +2033,19 @@ class MetacatSmokeSpec extends Specification {
// Create child11 Table with parent = parent1
def child11TableDto = PigDataDtoProvider.getTable(catalogName, databaseName, child11, 'amajumdar', child11Uri)
child11TableDto.definitionMetadata.put("root_table_name", parent1FullName)
child11TableDto.definitionMetadata.put("root_table_uuid", parent1UUID)
child11TableDto.definitionMetadata.put("child_table_uuid", child11UUID)
initializeParentChildRelDefinitionMetadata(child11TableDto, parent1FullName, parent1UUID, child11UUID)
api.createTable(catalogName, databaseName, child11, child11TableDto)
def parent1Table = api.getTable(catalogName, databaseName, parent1, true, true, false)
def child11Table = api.getTable(catalogName, databaseName, child11, true, true, false)
def child11ParentChildRelationInfo = child11Table.definitionMetadata.get("parentChildRelationInfo")
then:
// Test Parent 1 parentChildInfo
assert !parent1Table.definitionMetadata.has("parentChildRelationInfo")
assert parent1Table.definitionMetadata.get("parentChildRelationInfo").get("isParent").booleanValue()
assert parentChildRelV1.getChildren(catalogName, databaseName, parent1) == [new ChildInfoDto("embedded-fast-hive-metastore/iceberg_db/child11", "CLONE", "c11_uuid")] as Set
// Test Child11 parentChildInfo
assert !child11Table.definitionMetadata.get("parentChildRelationInfo").has("isParent")
JSONAssert.assertEquals(child11ParentChildRelationInfo.toString(),
'{"parentInfos":[{"name":"embedded-fast-hive-metastore/iceberg_db/parent1","relationType":"CLONE", "uuid":"p1_uuid"}]}',
false)
Expand All @@ -2042,23 +2057,22 @@ class MetacatSmokeSpec extends Specification {
when:
// Create Child2 Table
def child12TableDto = PigDataDtoProvider.getTable(catalogName, databaseName, child12, 'amajumdar', child12Uri)
child12TableDto.definitionMetadata.put("root_table_name", parent1FullName)
child12TableDto.definitionMetadata.put("root_table_uuid", parent1UUID)
child12TableDto.definitionMetadata.put("child_table_uuid", child12UUID)
initializeParentChildRelDefinitionMetadata(child12TableDto, parent1FullName, parent1UUID, child12UUID)
api.createTable(catalogName, databaseName, child12, child12TableDto)
parent1Table = api.getTable(catalogName, databaseName, parent1, true, true, false)
def child12Table = api.getTable(catalogName, databaseName, child12, true, true, false)
def child12ParentChildRelationInfo = child12Table.definitionMetadata.get("parentChildRelationInfo")
then:
// Test Parent 1 parentChildInfo
assert !parent1Table.definitionMetadata.get("parentChildRelationInfo")
assert parent1Table.definitionMetadata.get("parentChildRelationInfo").get("isParent").booleanValue()
assert parentChildRelV1.getChildren(catalogName, databaseName, parent1) == [
new ChildInfoDto("embedded-fast-hive-metastore/iceberg_db/child11", "CLONE", "c11_uuid"),
new ChildInfoDto("embedded-fast-hive-metastore/iceberg_db/child12", "CLONE", "c12_uuid")
] as Set
// Test Child12 parentChildInfo
assert !child12Table.definitionMetadata.get("parentChildRelationInfo").has("isParent")
JSONAssert.assertEquals(child12ParentChildRelationInfo.toString(),
'{"parentInfos":[{"name":"embedded-fast-hive-metastore/iceberg_db/parent1","relationType":"CLONE","uuid":"p1_uuid"}]}',
false)
Expand Down Expand Up @@ -2088,17 +2102,15 @@ class MetacatSmokeSpec extends Specification {
// Create child21 Table with parent = parent2
def child21TableDto = PigDataDtoProvider.getTable(catalogName, databaseName, child21, 'amajumdar', child21Uri)
child21TableDto.definitionMetadata.put("root_table_name", parent2FullName)
child21TableDto.definitionMetadata.put("root_table_uuid", parent2UUID)
child21TableDto.definitionMetadata.put("child_table_uuid", child21UUID)
initializeParentChildRelDefinitionMetadata(child21TableDto, parent2FullName, parent2UUID, child21UUID)
api.createTable(catalogName, databaseName, child21, child21TableDto)
def parent2Table = api.getTable(catalogName, databaseName, parent2, true, true, false)
def child21Table = api.getTable(catalogName, databaseName, child21, true, true, false)
def child21ParentChildRelationInfo = child21Table.definitionMetadata.get("parentChildRelationInfo")
then:
// Test Parent 2 parentChildInfo
assert !parent2Table.definitionMetadata.has("parentChildRelationInfo")
assert parent2Table.definitionMetadata.get("parentChildRelationInfo").get("isParent").booleanValue()
assert parentChildRelV1.getChildren(catalogName, databaseName, parent2) == [
new ChildInfoDto("embedded-fast-hive-metastore/iceberg_db/child21", "CLONE", "c21_uuid")
] as Set
Expand All @@ -2122,19 +2134,21 @@ class MetacatSmokeSpec extends Specification {
then:
// Test Parent 1 parentChildInfo newName
assert !parent1Table.definitionMetadata.has("parentChildRelationInfo")
assert parent1Table.definitionMetadata.get("parentChildRelationInfo").get("isParent").booleanValue()
assert parentChildRelV1.getChildren(catalogName, databaseName, renameParent1) ==
[
new ChildInfoDto("embedded-fast-hive-metastore/iceberg_db/child11", "CLONE", "c11_uuid"),
new ChildInfoDto("embedded-fast-hive-metastore/iceberg_db/child12", "CLONE", "c12_uuid")
] as Set
// Test Child11 parentChildInfo
assert !child11Table.definitionMetadata.get("parentChildRelationInfo").has("isParent")
JSONAssert.assertEquals(child11ParentChildRelationInfo.toString(),
'{"parentInfos":[{"name":"embedded-fast-hive-metastore/iceberg_db/rename_parent1","relationType":"CLONE","uuid":"p1_uuid"}]}',
false)
assert parentChildRelV1.getChildren(catalogName, databaseName, child11).isEmpty()
// Test Child12 parentChildInfo
assert !child12Table.definitionMetadata.get("parentChildRelationInfo").has("isParent")
JSONAssert.assertEquals(child12ParentChildRelationInfo.toString(),
'{"parentInfos":[{"name":"embedded-fast-hive-metastore/iceberg_db/rename_parent1","relationType":"CLONE","uuid":"p1_uuid"}]}',
false)
Expand All @@ -2149,12 +2163,13 @@ class MetacatSmokeSpec extends Specification {
child11Table = api.getTable(catalogName, databaseName, renameChild11, true, true, false)
child11ParentChildRelationInfo = child11Table.definitionMetadata.get("parentChildRelationInfo")
then:
assert !parent1Table.definitionMetadata.has("parentChildRelationInfo")
assert parent1Table.definitionMetadata.get("parentChildRelationInfo").get("isParent").booleanValue()
assert parentChildRelV1.getChildren(catalogName, databaseName, renameParent1) == [
new ChildInfoDto("embedded-fast-hive-metastore/iceberg_db/rename_child11", "CLONE", "c11_uuid"),
new ChildInfoDto("embedded-fast-hive-metastore/iceberg_db/child12", "CLONE", "c12_uuid")
] as Set
// Test Child11 parentChildInfo with newName
assert !child11Table.definitionMetadata.get("parentChildRelationInfo").has("isParent")
JSONAssert.assertEquals(child11ParentChildRelationInfo.toString(),
'{"parentInfos":[{"name":"embedded-fast-hive-metastore/iceberg_db/rename_parent1","relationType":"CLONE","uuid":"p1_uuid"}]}',
false)
Expand All @@ -2179,7 +2194,7 @@ class MetacatSmokeSpec extends Specification {
then:
// Test parent1 Table
assert !parent1Table.definitionMetadata.has("parentChildRelationInfo")
assert parent1Table.definitionMetadata.get("parentChildRelationInfo").get("isParent").booleanValue()
assert parentChildRelV1.getChildren(catalogName, databaseName, renameParent1) == [
new ChildInfoDto("embedded-fast-hive-metastore/iceberg_db/child12", "CLONE", "c12_uuid")
] as Set
Expand All @@ -2206,12 +2221,13 @@ class MetacatSmokeSpec extends Specification {
// Since all the operations above are on the first connected relationship, the second connected relationship
// should remain the same
// Test Parent 2 parentChildInfo
assert !parent2Table.definitionMetadata.has("parentChildRelationInfo")
assert parent2Table.definitionMetadata.get("parentChildRelationInfo").get("isParent").booleanValue()
assert parentChildRelV1.getChildren(catalogName, databaseName, parent2) == [
new ChildInfoDto("embedded-fast-hive-metastore/iceberg_db/child21", "CLONE", "c21_uuid")
] as Set
// Test Child21 parentChildInfo
assert !child21Table.definitionMetadata.get("parentChildRelationInfo").has("isParent")
JSONAssert.assertEquals(child21ParentChildRelationInfo.toString(),
'{"parentInfos":[{"name":"embedded-fast-hive-metastore/iceberg_db/parent2","relationType":"CLONE","uuid":"p2_uuid"}]}',
false)
Expand All @@ -2230,12 +2246,13 @@ class MetacatSmokeSpec extends Specification {
child21Table = api.getTable(catalogName, databaseName, child21, true, true, false)
child21ParentChildRelationInfo = child21Table.definitionMetadata.get("parentChildRelationInfo")
then:
assert !parent2Table.definitionMetadata.has("parentChildRelationInfo")
assert parent2Table.definitionMetadata.get("parentChildRelationInfo").get("isParent").booleanValue()
assert parentChildRelV1.getChildren(catalogName, databaseName, parent2) == [
new ChildInfoDto("embedded-fast-hive-metastore/iceberg_db/child21", "CLONE", "c21_uuid")
] as Set
// Test Child21 parentChildInfo
assert !child21Table.definitionMetadata.get("parentChildRelationInfo").has("isParent")
JSONAssert.assertEquals(child21ParentChildRelationInfo.toString(),
'{"parentInfos":[{"name":"embedded-fast-hive-metastore/iceberg_db/parent2","relationType":"CLONE","uuid":"p2_uuid"}]}',
false)
Expand All @@ -2255,12 +2272,13 @@ class MetacatSmokeSpec extends Specification {
child21ParentChildRelationInfo = child21Table.definitionMetadata.get("parentChildRelationInfo")
then:
// Test Parent 2 parentChildInfo
assert !parent2Table.definitionMetadata.has("parentChildRelationInfo")
assert parent2Table.definitionMetadata.get("parentChildRelationInfo").get("isParent").booleanValue()
assert parentChildRelV1.getChildren(catalogName, databaseName, parent2) == [
new ChildInfoDto("embedded-fast-hive-metastore/iceberg_db/child21", "CLONE", "c21_uuid")
] as Set
// Test Child21 parentChildInfo
assert !child21Table.definitionMetadata.get("parentChildRelationInfo").has("isParent")
JSONAssert.assertEquals(child21ParentChildRelationInfo.toString(),
'{"parentInfos":[{"name":"embedded-fast-hive-metastore/iceberg_db/parent2","relationType":"CLONE","uuid":"p2_uuid"}]}',
false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* Parent Child Relation V1 API implementation.
*
* @author amajumdar
* @author Yingjian
*/

@RestController
Expand Down
Loading

0 comments on commit 98f590d

Please sign in to comment.