Skip to content

Commit

Permalink
Merge pull request #40 from davidradl/git13
Browse files Browse the repository at this point in the history
git13 update type
  • Loading branch information
davidradl authored Jun 7, 2023
2 parents 123f1de + 336c8f8 commit 6d82708
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ public List<OMRSInstanceEvent> buildAlterTableEvents(Table oldTable, Table newT

Map<String, FieldSchema> oldTableColumnMap = new HashMap<>();
Map<String, FieldSchema> newTableColumnMap = new HashMap<>();
Set<String> batchEntityNamesSet = new HashSet<>();
Set<String> addEntityNamesSet = new HashSet<>();
Set<String> updateEntityNamesSet = new HashSet<>();
// check the columns
Iterator<FieldSchema> oldTableColumnIterator = oldTable.getSd().getColsIterator();
while (oldTableColumnIterator.hasNext()) {
Expand All @@ -253,20 +254,20 @@ public List<OMRSInstanceEvent> buildAlterTableEvents(Table oldTable, Table newT
newTableColumnMap.put(colName, newFieldSchema);
FieldSchema oldFieldSchema = oldTableColumnMap.get(colName);
if (oldFieldSchema == null) {
batchEntityNamesSet.add(colName);
addEntityNamesSet.add(colName);
} else {
// update if there is a change in type
// TODO do comments if required
if (!oldFieldSchema.getType().equals(newFieldSchema.getType())) {
batchEntityNamesSet.add(colName);
updateEntityNamesSet.add(colName);
}
}
}
List<EntityDetail> entities = new ArrayList<>();
List<Relationship> relationships = new ArrayList<>();
Date createTime = new Date(newTable.getCreateTime()*1000L);
InstanceGraph instanceGraph = null;
for (String columnName : batchEntityNamesSet) {
for (String columnName : addEntityNamesSet) {

EntityDetail columnEntity = mapFieldSchemaToEntity(newTableColumnMap.get(columnName), tableQualifiedName, createTime);
Relationship relationship = mapEndGUIDToRelationship(tableEntity.getGUID(), columnEntity.getGUID(), createTime);
Expand All @@ -277,9 +278,13 @@ public List<OMRSInstanceEvent> buildAlterTableEvents(Table oldTable, Table newT
relationship.setCreateTime(createTime);
entities.add(columnEntity);
relationships.add(relationship);
instanceGraph = new InstanceGraph(entities, relationships);
}
if (instanceGraph !=null) {
for (String columnName : updateEntityNamesSet) {
EntityDetail columnEntity = mapFieldSchemaToEntity(newTableColumnMap.get(columnName), tableQualifiedName, createTime);
entities.add(columnEntity);
}
if (!entities.isEmpty() || !relationships.isEmpty()) {
instanceGraph = new InstanceGraph(entities, relationships);
OMRSInstanceEvent batchInstanceEvent = new OMRSInstanceEvent(OMRSInstanceEventType.BATCH_INSTANCES_EVENT, instanceGraph);
batchInstanceEvent.setEventOriginator(eventOriginator);
instanceEvents.add(batchInstanceEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.apache.hadoop.hive.metastore.events.CreateTableEvent;
import org.apache.hadoop.hive.metastore.events.DropTableEvent;

import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
Expand All @@ -26,7 +25,7 @@ public ListenerTesterApp() {
config.set(HMSListener.CONFIG_METADATA_COLLECTION_ID,"TODO");
config.set(HMSListener.CONFIG_SERVER_NAME, "TODO");
config.set(HMSListener.CONFIG_QUALIFIEDNAME_PREFIX, "TODO");

// config.set(HMSListener.CONFIG_ORGANISATION_NAME ,"Coco");
config.set(HMSListener.CONFIG_KAFKA_TOPIC_NAME,"egeriaTopics.openmetadata.repositoryservices.cohort.myCohort2.OMRSTopic.instances");
config.set(HMSListener.CONFIG_KAFKA_BOOTSTRAP_SERVER_URL,"localhost:9092");
Expand Down Expand Up @@ -203,14 +202,15 @@ public void run() throws MetaException {
Table newTable = oldTable.deepCopy();
List<FieldSchema> oldCols = newTable.getSd().getCols();
List<FieldSchema> newCols = new ArrayList<>();
Iterator<FieldSchema> iterator = oldCols.listIterator();
while (iterator.hasNext()) {
FieldSchema fieldSchema = iterator.next();
String name = fieldSchema.getName();
if (name.equals(newTypeName)) {
fieldSchema.setType(newTypeName);

Iterator<FieldSchema> oldColsIterator = oldCols.listIterator();
while (oldColsIterator.hasNext()) {
FieldSchema oldFieldSchema = oldColsIterator.next();
if (!oldFieldSchema.getType().equals(newTypeName)) {
FieldSchema newFieldSchema = oldFieldSchema;
newFieldSchema.setType(newTypeName);
newCols.add(newFieldSchema);
}
newCols.add(fieldSchema);
}
newTable.getSd().setCols(newCols);
AlterTableEvent alterTableEvent = getAlterTableEvent(oldTable, newTable);
Expand Down

0 comments on commit 6d82708

Please sign in to comment.