Repository: atlas
Updated Branches:
  refs/heads/master 3f7c5811f -> 810aceb5d


ATLAS-2611: fix for NPE in Hive hook

Signed-off-by: Madhan Neethiraj <mad...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/810aceb5
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/810aceb5
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/810aceb5

Branch: refs/heads/master
Commit: 810aceb5dc212ec68b598227677aa9c5683db8e9
Parents: 3f7c581
Author: Peter Gergő Barna <bpge...@gmail.com>
Authored: Fri Apr 27 18:23:31 2018 +0200
Committer: Madhan Neethiraj <mad...@apache.org>
Committed: Sat Apr 28 12:06:37 2018 -0700

----------------------------------------------------------------------
 .../hive/hook/events/CreateHiveProcess.java     | 31 +++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/810aceb5/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/CreateHiveProcess.java
----------------------------------------------------------------------
diff --git 
a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/CreateHiveProcess.java
 
b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/CreateHiveProcess.java
index 86027f2..33a2633 100644
--- 
a/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/CreateHiveProcess.java
+++ 
b/addons/hive-bridge/src/main/java/org/apache/atlas/hive/hook/events/CreateHiveProcess.java
@@ -36,7 +36,10 @@ import org.apache.hadoop.hive.ql.plan.HiveOperation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
@@ -141,7 +144,7 @@ public class CreateHiveProcess extends BaseHiveEvent {
 
             List<AtlasEntity> inputColumns = new ArrayList<>();
 
-            for (BaseColumnInfo baseColumn : entry.getValue().getBaseCols()) {
+            for (BaseColumnInfo baseColumn : getBaseCols(entry.getValue())) {
                 String      inputColName = getQualifiedName(baseColumn);
                 AtlasEntity inputColumn  = context.getEntity(inputColName);
 
@@ -172,6 +175,32 @@ public class CreateHiveProcess extends BaseHiveEvent {
         }
     }
 
+    private Collection<BaseColumnInfo> getBaseCols(Dependency lInfoDep) {
+        Collection<BaseColumnInfo> ret = Collections.emptyList();
+
+        if (lInfoDep != null) {
+            try {
+                Method getBaseColsMethod = 
lInfoDep.getClass().getMethod("getBaseCols");
+
+                Object retGetBaseCols = getBaseColsMethod.invoke(lInfoDep);
+
+                if (retGetBaseCols != null) {
+                    if (retGetBaseCols instanceof Collection) {
+                        ret = (Collection) retGetBaseCols;
+                    } else {
+                        LOG.warn("{}: unexpected return type from 
LineageInfo.Dependency.getBaseCols(), expected type {}",
+                                retGetBaseCols.getClass().getName(), 
"Collection");
+                    }
+                }
+            } catch (NoSuchMethodException | InvocationTargetException | 
IllegalAccessException ex) {
+                LOG.warn("getBaseCols()", ex);
+            }
+        }
+
+        return ret;
+    }
+
+
     private boolean skipProcess() {
         Set<ReadEntity>  inputs  = getHiveContext().getInputs();
         Set<WriteEntity> outputs = getHiveContext().getOutputs();

Reply via email to