From 590fa3490e762d909f61c80c0de403901a4a2a4d Mon Sep 17 00:00:00 2001 From: zhuol Date: Thu, 18 Feb 2016 22:33:47 -0600 Subject: [PATCH 1/2] [SPARK-13364] Sort App Id column as num rather than str in History Server. --- .../spark/ui/static/historypage-template.html | 2 +- .../org/apache/spark/ui/static/historypage.js | 33 ++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/core/src/main/resources/org/apache/spark/ui/static/historypage-template.html b/core/src/main/resources/org/apache/spark/ui/static/historypage-template.html index 66d111e439096..34d7ec5d7ca88 100644 --- a/core/src/main/resources/org/apache/spark/ui/static/historypage-template.html +++ b/core/src/main/resources/org/apache/spark/ui/static/historypage-template.html @@ -64,7 +64,7 @@ {{#applications}} - {{id}} + {{id}} {{name}} {{#attempts}} {{attemptId}} diff --git a/core/src/main/resources/org/apache/spark/ui/static/historypage.js b/core/src/main/resources/org/apache/spark/ui/static/historypage.js index 689c92e86129e..b69d75a3448ab 100644 --- a/core/src/main/resources/org/apache/spark/ui/static/historypage.js +++ b/core/src/main/resources/org/apache/spark/ui/static/historypage.js @@ -37,6 +37,22 @@ function formatDuration(milliseconds) { return hours.toFixed(1) + " h"; } +function makeIdNumeric(id) { + var strs = id.split("-"); + if (strs.length < 3) { + return id; + } + var appSeqNum = strs[2]; + var resl = strs[0] + "-" + strs[1] + "-"; + var diff = 10 - appSeqNum.length; + while (diff > 0) { + resl += "0"; + diff--; + } + resl += appSeqNum; + return resl; +} + function formatDate(date) { return date.split(".")[0].replace("T", " "); } @@ -62,6 +78,21 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, { } } ); +jQuery.extend( jQuery.fn.dataTableExt.oSort, { + "appid-numeric-pre": function ( a ) { + var x = a.match(/title="*(-?[0-9a-zA-Z\-]+)/)[1]; + return makeIdNumeric(x); + }, + + "appid-numeric-asc": function ( a, b ) { + return ((a < b) ? -1 : ((a > b) ? 1 : 0)); + }, + + "appid-numeric-desc": function ( a, b ) { + return ((a < b) ? 1 : ((a > b) ? -1 : 0)); + } +} ); + $(document).ajaxStop($.unblockUI); $(document).ajaxStart(function(){ $.blockUI({ message: '

Loading history summary...

'}); @@ -109,7 +140,7 @@ $(document).ready(function() { var selector = "#history-summary-table"; var conf = { "columns": [ - {name: 'first'}, + {name: 'first', type: "appid-numeric"}, {name: 'second'}, {name: 'third'}, {name: 'fourth'}, From 94a7f78cfc862fc05599af4710fd2b62821fd945 Mon Sep 17 00:00:00 2001 From: zhuol Date: Fri, 19 Feb 2016 12:52:48 -0600 Subject: [PATCH 2/2] Address comments. --- .../org/apache/spark/ui/static/historypage-template.html | 2 +- .../resources/org/apache/spark/ui/static/historypage.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/main/resources/org/apache/spark/ui/static/historypage-template.html b/core/src/main/resources/org/apache/spark/ui/static/historypage-template.html index 34d7ec5d7ca88..a2b3826dd324b 100644 --- a/core/src/main/resources/org/apache/spark/ui/static/historypage-template.html +++ b/core/src/main/resources/org/apache/spark/ui/static/historypage-template.html @@ -64,7 +64,7 @@ {{#applications}} - {{id}} + {{id}} {{name}} {{#attempts}} {{attemptId}} diff --git a/core/src/main/resources/org/apache/spark/ui/static/historypage.js b/core/src/main/resources/org/apache/spark/ui/static/historypage.js index b69d75a3448ab..6195916195e38 100644 --- a/core/src/main/resources/org/apache/spark/ui/static/historypage.js +++ b/core/src/main/resources/org/apache/spark/ui/static/historypage.js @@ -38,15 +38,15 @@ function formatDuration(milliseconds) { } function makeIdNumeric(id) { - var strs = id.split("-"); + var strs = id.split("_"); if (strs.length < 3) { return id; } var appSeqNum = strs[2]; - var resl = strs[0] + "-" + strs[1] + "-"; + var resl = strs[0] + "_" + strs[1] + "_"; var diff = 10 - appSeqNum.length; while (diff > 0) { - resl += "0"; + resl += "0"; // padding 0 before the app sequence number to make sure it has 10 characters diff--; } resl += appSeqNum; @@ -80,7 +80,7 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, { jQuery.extend( jQuery.fn.dataTableExt.oSort, { "appid-numeric-pre": function ( a ) { - var x = a.match(/title="*(-?[0-9a-zA-Z\-]+)/)[1]; + var x = a.match(/title="*(-?[0-9a-zA-Z\-\_]+)/)[1]; return makeIdNumeric(x); },