Преглед изворни кода

AMBARI-5436. Map operator displays wrong statistics for TPC-DS Query27. (srimanth)

Srimanth Gunturi пре 11 година
родитељ
комит
2ada153e06

+ 41 - 24
ambari-web/app/utils/helper.js

@@ -36,34 +36,51 @@ String.prototype.capitalize = function () {
   return this.charAt(0).toUpperCase() + this.slice(1);
 };
 
-// Use: stringvalue.findIn(multi_dimensional_array_or_object)
-/***Example:
- var tofind = 'emotion';
- var person = {'name': 'Bob Loblaw', 'age': '28', 'personality': {'smart': 'yes', 'funny': 'yes', 'emotion': 'happy'} };
- tofind.findIn(person)
- ***/
-String.prototype.findIn = function (multi) {
+/**
+ * Finds the value in an object where this string is a key.
+ * Optionally, the index of the key can be provided where the
+ * value of the nth key in the hierarchy is returned.
+ *
+ * Example:
+ *  var tofind = 'smart';
+ *  var person = {'name': 'Bob Bob', 'smart': 'no', 'age': '28', 'personality': {'smart': 'yes', 'funny': 'yes', 'emotion': 'happy'} };
+ *  tofind.findIn(person); // 'no'
+ *  tofind.findIn(person, 0); // 'no'
+ *  tofind.findIn(person, 1); // 'yes'
+ *  tofind.findIn(person, 2); // null
+ *
+ *  @param multi  Object
+ *  @param index  Occurrence count of this key
+ *  @return Value of key at given index
+ */
+String.prototype.findIn = function(multi, index, _foundValues) {
+  if (!index) {
+    index = 0;
+  }
+  if (!_foundValues) {
+    _foundValues = [];
+  }
   multi = multi || '';
-  var val = this.valueOf();
-  if(typeof multi == 'object' || typeof multi == 'array')
-  {
-    if(val in multi)
-    {
-      return multi[val];
-    }
-    else
-    {
-      for(var x in multi)
-      {
-        var found = this.findIn(multi[x]);
-        if(found != false)
-        {
-          return found;
-        }
+  var value = null;
+  var str = this.valueOf();
+  if (typeof multi == 'object') {
+    for ( var key in multi) {
+      if (value != null) {
+        break;
+      }
+      if (key == str) {
+        _foundValues.push(multi[key]);
+      }
+      if (_foundValues.length - 1 == index) {
+        // Found the value
+        return _foundValues[index];
+      }
+      if (typeof multi[key] == 'object') {
+        value = value || this.findIn(multi[key], index, _foundValues);
       }
     }
   }
-  return false;
+  return value;
 };
 
 /**

+ 19 - 11
ambari-web/app/views/main/jobs/hive_job_details_tez_dag_view.js

@@ -292,20 +292,27 @@ App.MainHiveJobDetailsTezDagView = Em.View.extend({
       'content.tezDag.vertices.@each.recordReadCount', 'content.tezDag.vertices.@each.recordWriteCount',
       'content.tezDag.vertices.@each.state', 'content.tezDag.vertices.@each.spilledRecords'),
 
-  createOperationPlanObj: function (vertexName, op) {
+  createOperationPlanObj: function (vertexName, op, opIndex) {
     var operatorPlanObj = [];
     var text = this.get('content.tezDag.vertices').findProperty('name', vertexName).get('operationPlan');
     text = text.replace(/:"/g,'"').replace(/([:,])(?=\S)/g,'$1 ');
     var jsonText =  $.parseJSON(text);
-    var jsonText = op.findIn(jsonText);
-    for (var key in jsonText) {
-      if (jsonText.hasOwnProperty(key) && typeof(jsonText[key]) == "string") {
-        operatorPlanObj.push(
-          {
-            name: key,
-            value: jsonText[key]
-          }
-        );
+    if (!opIndex) {
+      opIndex = 0;
+    } else {
+      opIndex = parseInt(opIndex) - 1;
+    }
+    var jsonText = op.findIn(jsonText, opIndex);
+    if (jsonText!=null) {
+      for (var key in jsonText) {
+        if (jsonText.hasOwnProperty(key) && typeof(jsonText[key]) == "string") {
+          operatorPlanObj.push(
+              {
+                name: key,
+                value: jsonText[key]
+              }
+          );
+        }
       }
     }
     return operatorPlanObj;
@@ -670,7 +677,8 @@ App.MainHiveJobDetailsTezDagView = Em.View.extend({
             operationName: op,
             operatorPlanObj: []
           };
-          var operatorPlanObj = self.createOperationPlanObj(n.name, op);
+          var opIndex = this.getAttribute('opIndex');
+          var operatorPlanObj = self.createOperationPlanObj(n.name, op, opIndex);
           viewContent.operatorPlanObj = operatorPlanObj;
           var template = App.HoverOpTable.create({content: viewContent}) ;
           $(this).find('.svg-tooltip').attr('title', template.renderToBuffer().string()).tooltip('fixTitle').tooltip('show');

+ 82 - 0
ambari-web/test/utils/string_utils_test.js

@@ -17,6 +17,7 @@
  */
 
 var string_utils = require('utils/string_utils');
+require('utils/helper');
 
 describe('string_utils', function () {
 
@@ -152,4 +153,85 @@ describe('string_utils', function () {
       });
     });
   });
+
+  describe('#findIn', function () {
+    var tests = [
+      {
+        obj: {
+          a: '1',
+          b: '2'
+        },
+        key: 'a',
+        index: 0,
+        e: '1'
+      }, {
+        obj: {
+          a: '1',
+          b: '2'
+        },
+        key: 'a',
+        index: 1,
+        e: null
+      }, {
+        obj: {
+          a: '1',
+          b: '2',
+          c: {
+            a: '11',
+            aa: '12'
+          }
+        },
+        key: 'a',
+        index: 1,
+        e: '11'
+      }, {
+        obj: {
+          a: '1',
+          b: '2',
+          c: {
+            a: '11',
+            aa: {
+              a: '22'
+            }
+          }
+        },
+        key: 'a',
+        index: 2,
+        e: '22'
+      }, {
+        obj: {
+          a: '1',
+          b: '2',
+          c: {
+            a: '11',
+            aa: {
+              a: '22'
+            }
+          }
+        },
+        key: 'a',
+        index: 0,
+        e: '1'
+      }, {
+        obj: {
+          a: '1',
+          b: '2',
+          c: {
+            a: '11',
+            aa: {
+              a: '22'
+            }
+          }
+        },
+        key: 'g',
+        index: 0,
+        e: null
+      }
+    ];
+    tests.forEach(function(test) {
+      it(test.key + ' @ ' + test.index + ' = ' + test.e, function () {
+        expect(test.key.findIn(test.obj, test.index)).to.equal(test.e);
+      });
+    });
+  });
 });