Commit 0c1d599d by Madhan Neethiraj

ATLAS-1598: fix for NPE in Hive hook while processing create-table

parent 08944c54
...@@ -248,7 +248,7 @@ public class HiveHook extends AtlasHook implements ExecuteWithHookContext { ...@@ -248,7 +248,7 @@ public class HiveHook extends AtlasHook implements ExecuteWithHookContext {
case CREATETABLE: case CREATETABLE:
LinkedHashMap<Type, Referenceable> tablesCreated = handleEventOutputs(dgiBridge, event, Type.TABLE); LinkedHashMap<Type, Referenceable> tablesCreated = handleEventOutputs(dgiBridge, event, Type.TABLE);
if (tablesCreated.size() > 0) { if (tablesCreated != null && tablesCreated.size() > 0) {
handleExternalTables(dgiBridge, event, tablesCreated); handleExternalTables(dgiBridge, event, tablesCreated);
} }
break; break;
...@@ -730,7 +730,7 @@ public class HiveHook extends AtlasHook implements ExecuteWithHookContext { ...@@ -730,7 +730,7 @@ public class HiveHook extends AtlasHook implements ExecuteWithHookContext {
final String location = lower(hiveTable.getDataLocation().toString()); final String location = lower(hiveTable.getDataLocation().toString());
final ReadEntity dfsEntity = new ReadEntity(); final ReadEntity dfsEntity = new ReadEntity();
dfsEntity.setTyp(Type.DFS_DIR); dfsEntity.setTyp(Type.DFS_DIR);
dfsEntity.setName(location); dfsEntity.setD(new Path(location));
SortedMap<ReadEntity, Referenceable> hiveInputsMap = new TreeMap<ReadEntity, Referenceable>(entityComparator) {{ SortedMap<ReadEntity, Referenceable> hiveInputsMap = new TreeMap<ReadEntity, Referenceable>(entityComparator) {{
put(dfsEntity, dgiBridge.fillHDFSDataSet(location)); put(dfsEntity, dgiBridge.fillHDFSDataSet(location));
......
...@@ -21,7 +21,6 @@ package org.apache.atlas.repository.store.graph.v1; ...@@ -21,7 +21,6 @@ package org.apache.atlas.repository.store.graph.v1;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
import org.apache.atlas.GraphTransaction; import org.apache.atlas.GraphTransaction;
import org.apache.atlas.RequestContextV1; import org.apache.atlas.RequestContextV1;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
...@@ -38,12 +37,10 @@ import org.apache.atlas.repository.store.graph.AtlasEntityStore; ...@@ -38,12 +37,10 @@ import org.apache.atlas.repository.store.graph.AtlasEntityStore;
import org.apache.atlas.repository.store.graph.EntityGraphDiscovery; import org.apache.atlas.repository.store.graph.EntityGraphDiscovery;
import org.apache.atlas.repository.store.graph.EntityGraphDiscoveryContext; import org.apache.atlas.repository.store.graph.EntityGraphDiscoveryContext;
import org.apache.atlas.type.AtlasEntityType; import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasStructType.AtlasAttribute; import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.type.AtlasTypeUtil; import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.typesystem.persistence.Id;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -326,17 +323,18 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore { ...@@ -326,17 +323,18 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
// Retrieve vertices for requested guids. // Retrieve vertices for requested guids.
AtlasVertex vertex = AtlasGraphUtilsV1.findByGuid(guid); AtlasVertex vertex = AtlasGraphUtilsV1.findByGuid(guid);
Collection<AtlasVertex> deletionCandidates = new ArrayList<>();
if (vertex != null) {
deletionCandidates.add(vertex);
} else {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
if (vertex == null) {
// Entity does not exist - treat as non-error, since the caller // Entity does not exist - treat as non-error, since the caller
// wanted to delete the entity and it's already gone. // wanted to delete the entity and it's already gone.
LOG.debug("Deletion request ignored for non-existent entity with guid " + guid); LOG.debug("Deletion request ignored for non-existent entity with guid " + guid);
} }
} }
Collection<AtlasVertex> deletionCandidates = new ArrayList<>();
deletionCandidates.add(vertex);
EntityMutationResponse ret = deleteVertices(deletionCandidates); EntityMutationResponse ret = deleteVertices(deletionCandidates);
// Notify the change listeners // Notify the change listeners
...@@ -357,15 +355,16 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore { ...@@ -357,15 +355,16 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
for (String guid : guids) { for (String guid : guids) {
// Retrieve vertices for requested guids. // Retrieve vertices for requested guids.
AtlasVertex vertex = AtlasGraphUtilsV1.findByGuid(guid); AtlasVertex vertex = AtlasGraphUtilsV1.findByGuid(guid);
if (vertex != null) {
deletionCandidates.add(vertex);
} else {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
if (vertex == null) {
// Entity does not exist - treat as non-error, since the caller // Entity does not exist - treat as non-error, since the caller
// wanted to delete the entity and it's already gone. // wanted to delete the entity and it's already gone.
LOG.debug("Deletion request ignored for non-existent entity with guid " + guid); LOG.debug("Deletion request ignored for non-existent entity with guid " + guid);
} }
} }
deletionCandidates.add(vertex);
} }
if (deletionCandidates.isEmpty()) { if (deletionCandidates.isEmpty()) {
...@@ -391,7 +390,16 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore { ...@@ -391,7 +390,16 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
final AtlasVertex vertex = AtlasGraphUtilsV1.findByUniqueAttributes(entityType, uniqAttributes); final AtlasVertex vertex = AtlasGraphUtilsV1.findByUniqueAttributes(entityType, uniqAttributes);
Collection<AtlasVertex> deletionCandidates = new ArrayList<>(); Collection<AtlasVertex> deletionCandidates = new ArrayList<>();
if (vertex != null) {
deletionCandidates.add(vertex); deletionCandidates.add(vertex);
} else {
if (LOG.isDebugEnabled()) {
// Entity does not exist - treat as non-error, since the caller
// wanted to delete the entity and it's already gone.
LOG.debug("Deletion request ignored for non-existent entity with uniqueAttributes " + uniqAttributes);
}
}
EntityMutationResponse ret = deleteVertices(deletionCandidates); EntityMutationResponse ret = deleteVertices(deletionCandidates);
......
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