Commit 37d7b8b8 by rmani Committed by Madhan Neethiraj

ATLAS-2535: import-hive doesn't update entity already present in Atlas

parent a1fd4068
...@@ -67,6 +67,7 @@ import java.io.BufferedReader; ...@@ -67,6 +67,7 @@ import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -235,10 +236,6 @@ public class HiveMetaStoreBridge { ...@@ -235,10 +236,6 @@ public class HiveMetaStoreBridge {
return hiveClient; return hiveClient;
} }
public AtlasClientV2 getAtlasClient() {
return atlasClientV2;
}
public boolean isConvertHdfsPathToLowerCase() { public boolean isConvertHdfsPathToLowerCase() {
return convertHdfsPathToLowerCase; return convertHdfsPathToLowerCase;
} }
...@@ -458,6 +455,8 @@ public class HiveMetaStoreBridge { ...@@ -458,6 +455,8 @@ public class HiveMetaStoreBridge {
} }
} }
clearRelationshipAttributes(ret);
return ret; return ret;
} }
...@@ -494,6 +493,8 @@ public class HiveMetaStoreBridge { ...@@ -494,6 +493,8 @@ public class HiveMetaStoreBridge {
} }
} }
clearRelationshipAttributes(ret);
return ret; return ret;
} }
...@@ -589,10 +590,6 @@ public class HiveMetaStoreBridge { ...@@ -589,10 +590,6 @@ public class HiveMetaStoreBridge {
tableEntity.setAttribute(ATTRIBUTE_PARTITION_KEYS, BaseHiveEvent.getObjectIds(partKeys)); tableEntity.setAttribute(ATTRIBUTE_PARTITION_KEYS, BaseHiveEvent.getObjectIds(partKeys));
tableEntity.setAttribute(ATTRIBUTE_COLUMNS, BaseHiveEvent.getObjectIds(columns)); tableEntity.setAttribute(ATTRIBUTE_COLUMNS, BaseHiveEvent.getObjectIds(columns));
if (MapUtils.isNotEmpty(table.getReferredEntities())) {
table.getReferredEntities().clear();
}
table.addReferredEntity(database); table.addReferredEntity(database);
table.addReferredEntity(sdEntity); table.addReferredEntity(sdEntity);
...@@ -608,6 +605,8 @@ public class HiveMetaStoreBridge { ...@@ -608,6 +605,8 @@ public class HiveMetaStoreBridge {
} }
} }
table.setEntity(tableEntity);
return table; return table;
} }
...@@ -758,10 +757,10 @@ public class HiveMetaStoreBridge { ...@@ -758,10 +757,10 @@ public class HiveMetaStoreBridge {
} }
private AtlasEntityWithExtInfo findEntity(final String typeName, final String qualifiedName) throws AtlasServiceException { private AtlasEntityWithExtInfo findEntity(final String typeName, final String qualifiedName) throws AtlasServiceException {
AtlasClientV2 atlasClientV2 = getAtlasClient(); AtlasEntityWithExtInfo ret = null;
try { try {
return atlasClientV2.getEntityByAttribute(typeName, Collections.singletonMap(ATTRIBUTE_QUALIFIED_NAME, qualifiedName)); ret = atlasClientV2.getEntityByAttribute(typeName, Collections.singletonMap(ATTRIBUTE_QUALIFIED_NAME, qualifiedName));
} catch (AtlasServiceException e) { } catch (AtlasServiceException e) {
if(e.getStatus() == ClientResponse.Status.NOT_FOUND) { if(e.getStatus() == ClientResponse.Status.NOT_FOUND) {
return null; return null;
...@@ -769,6 +768,10 @@ public class HiveMetaStoreBridge { ...@@ -769,6 +768,10 @@ public class HiveMetaStoreBridge {
throw e; throw e;
} }
clearRelationshipAttributes(ret);
return ret;
} }
private String getCreateTableString(Table table, String location){ private String getCreateTableString(Table table, String location){
...@@ -879,4 +882,42 @@ public class HiveMetaStoreBridge { ...@@ -879,4 +882,42 @@ public class HiveMetaStoreBridge {
public static long getTableCreatedTime(Table table) { public static long getTableCreatedTime(Table table) {
return table.getTTable().getCreateTime() * MILLIS_CONVERT_FACTOR; return table.getTTable().getCreateTime() * MILLIS_CONVERT_FACTOR;
} }
private void clearRelationshipAttributes(AtlasEntitiesWithExtInfo entities) {
if (entities != null) {
if (entities.getEntities() != null) {
for (AtlasEntity entity : entities.getEntities()) {
clearRelationshipAttributes(entity);;
}
}
if (entities.getReferredEntities() != null) {
clearRelationshipAttributes(entities.getReferredEntities().values());
}
}
}
private void clearRelationshipAttributes(AtlasEntityWithExtInfo entity) {
if (entity != null) {
clearRelationshipAttributes(entity.getEntity());
if (entity.getReferredEntities() != null) {
clearRelationshipAttributes(entity.getReferredEntities().values());
}
}
}
private void clearRelationshipAttributes(Collection<AtlasEntity> entities) {
if (entities != null) {
for (AtlasEntity entity : entities) {
clearRelationshipAttributes(entity);
}
}
}
private void clearRelationshipAttributes(AtlasEntity entity) {
if (entity != null && entity.getRelationshipAttributes() != null) {
entity.getRelationshipAttributes().clear();
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment