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 5, 2024
1 parent c54dbda commit e57cdc9
Show file tree
Hide file tree
Showing 14 changed files with 1,370 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.netflix.metacat.common.server.model;

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

/**
* ChildInfo.
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ChildInfo {
private String name;
private String relationType;
private String uuid;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.netflix.metacat.common.server.model;

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

/**
* ParentInfo.
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ParentInfo {
private String name;
private String relationType;
private String 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,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,38 @@ 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 */;

DROP TABLE IF EXISTS `definition_metadata`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `definition_metadata` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`version` bigint(20) NOT NULL,
`created_by` varchar(255) NOT NULL,
`data` longtext NOT NULL,
`date_created` datetime NOT NULL,
`last_updated` datetime NOT NULL,
`last_updated_by` varchar(255) NOT NULL,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) 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 e57cdc9

Please sign in to comment.