Repository: atlas
Updated Branches:
  refs/heads/branch-0.8 9a8d31b8e -> d99cba614


ATLAS-2611: fix for NPE in Hive hook

Signed-off-by: Madhan Neethiraj <[email protected]>
(cherry picked from commit 810aceb5dc212ec68b598227677aa9c5683db8e9)


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

Branch: refs/heads/branch-0.8
Commit: d99cba614b0621db11f031585e8f6296b456009f
Parents: 9a8d31b
Author: Peter Gergő Barna <[email protected]>
Authored: Fri Apr 27 18:23:31 2018 +0200
Committer: Madhan Neethiraj <[email protected]>
Committed: Sat Apr 28 12:08:28 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/d99cba61/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 43016d4..6989d35 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;
@@ -137,7 +140,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);
 
@@ -168,6 +171,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