Skip to content

Commit

Permalink
add ParentChildRelationSqlService
Browse files Browse the repository at this point in the history
  • Loading branch information
Yingjian Wu committed Jun 6, 2024
1 parent c54dbda commit 787f394
Show file tree
Hide file tree
Showing 16 changed files with 1,860 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.netflix.metacat.common.server.model;

import lombok.Data;

/**
* ChildInfo.
*/
@Data
public abstract class BaseRelEntityInfo {
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
@@ -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,17 @@
package com.netflix.metacat.common.server.usermetadata;

import com.netflix.metacat.common.dto.TableDto;

import java.util.Optional;

/**
* Default Table UUID Provider.
*
* @author yingjianw
*/
public class DefaultTableUUIDProvider implements TableUUIDProvider {
@Override
public Optional<String> getUUID(final TableDto tableDto) {
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.netflix.metacat.common.server.usermetadata;

/**
* ParentChildRelMetadataConstants.
*
* @author yingjianw
*/
public final class ParentChildRelMetadataConstants {
/**
* Key specified in DefinitionMetadata that indicate the parent table name.
*/
public static final String PARENTNAME = "root_table_name";
/**
* During create, the key specified in DefinitionMetadata that indicates the parent table uuid.
*/
public static final String PARENTUUID = "root_table_uuid";
/**
* During create, the key specified in DefinitionMetadata that indicates the child table uuid.
*/
public static final String CHILDUUID = "child_table_uuid";

/**
* During create, the key specified in DefinitionMetadata that indicates relationType.
*/
public static final String RELATIONTYPE = "relationType";

/**
* During get, the key specified in DefinitionMetadata that indicates the parent child infos.
*/
public static final String PARENTCHILDRELINFO = "parentChildRelationInfo";

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

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

private ParentChildRelMetadataConstants() {

}

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

import java.util.Optional;
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. 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.
*
* @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`
* and if the uuid is present also include it in the sql search string.
* 2. Rename all records where the parent is `oldName` to `newName`
* and if the uuid is present also include it in the sql search string.
* For now, since a child cannot be a parent of another entity, only one of these actions will need to be performed.
*
* @param oldName the current name to be renamed
* @param newName the new name to rename to
* @param uuid the uuid of the table
*/
void rename(
QualifiedName oldName,
QualifiedName newName,
Optional<String> uuid
);

/**
* Removes the entity from the parentChildRelationship store.
* An exception is thrown if an attempt is made to drop a parent table that still has existing child tables.
* Note that only dropping a child table will result in the physical deletion of records.
* When all children of a parent table are dropped, no records remain.
* Consequently, at then time when dropping the parent table, there should not have any database records
* with a parent reference to the dropping parent table.
*
* @param name the name of the entity to drop
* @param uuid the uuid of the entity
*/
void drop(
QualifiedName name,
Optional<String> uuid
);

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

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

import com.netflix.metacat.common.dto.TableDto;

import java.util.Optional;

/**
* Interface for TableUUIDPorvider.
* @author yingjianw
*/
public interface TableUUIDProvider {
/**
* Given a tableDto, get the corresponding table uuid if applicable.
* @param tableDto dto for table
* @return the uuid of the table
**/
Optional<String> getUUID(TableDto tableDto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ CREATE TABLE data_metadata_delete (
KEY date_created (date_created)
) DEFAULT CHARSET=latin1;

--
-- Table structure for table `parent_child_relation`
--
DROP TABLE IF EXISTS `parent_child_relation`;
CREATE TABLE `parent_child_relation` (
`parent` varchar(255) NOT NULL,
`parent_uuid` varchar(255) NOT NULL,
`child` varchar(255) NOT NULL,
`child_uuid` varchar(255) NOT NULL,
`relation_type` varchar(255) NOT NULL,
PRIMARY KEY (`parent`, `child`, `parent_uuid`, `child_uuid`, `relation_type`),
INDEX `idx_child` (`child`)
) ENGINE=InnoDB AUTO_INCREMENT=10078235 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `definition_metadata`
--
Expand Down
Loading

0 comments on commit 787f394

Please sign in to comment.