You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by aw...@apache.org on 2020/04/24 04:56:44 UTC
[kudu] branch master updated: [www] convert human-readable int to
int when compare numeric strings
This is an automated email from the ASF dual-hosted git repository.
awong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new 1d1a858 [www] convert human-readable int to int when compare numeric strings
1d1a858 is described below
commit 1d1a85804b8ce132021661a8fdb053141c2781c2
Author: zhangyifan27 <ch...@163.com>
AuthorDate: Wed Apr 22 19:25:42 2020 +0800
[www] convert human-readable int to int when compare numeric strings
The /tables page show `tablet_count` as a HumanReadableInt, when sort
tables by tablet_count, human-readable int should be converted to int.
Change-Id: Ic7e832beb0dfdf5c2162bf0e9faeb3d0d0d737cd
Reviewed-on: http://gerrit.cloudera.org:8080/15784
Tested-by: Kudu Jenkins
Reviewed-by: Andrew Wong <aw...@cloudera.com>
---
www/kudu.js | 36 +++++++++++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/www/kudu.js b/www/kudu.js
index 9f02320..27d5ebc 100644
--- a/www/kudu.js
+++ b/www/kudu.js
@@ -45,6 +45,36 @@ function toNumBytes(humanReadableBytes) {
return val;
}
+// Converts a human-readable numeric strings like '1.23k' or '985.32M' to int.
+// Returns -1 if there's some failure.
+function toInt(humanReadableNum) {
+ len = humanReadableNum.length;
+ if (len < 1) {
+ return -1;
+ }
+ end = humanReadableNum[len - 1];
+ val = parseFloat(humanReadableNum);
+ if (isNaN(val)) {
+ return -1;
+ }
+ if (end == 'k') {
+ val *= 1e3;
+ } else if (end == 'M') {
+ val *= 1e6;
+ } else if (end == 'B') {
+ val *= 1e9;
+ } else if (end == 'T') {
+ val *= 1e12; // Number bigger than 1E15 use scientific notation.
+ } else if (isNaN(end)) {
+ // Not a number.
+ return -1;
+ }
+ if (val < 0) {
+ return parseInt(val - 0.5);
+ }
+ return parseInt(val + 0.5);
+}
+
// A comparison function for human-readable byte strings.
function bytesSorter(left, right) {
if (right.length == 0 && left.length == 0) {
@@ -80,10 +110,10 @@ function floatsSorter(left, right) {
return 0;
}
-// Converts numeric strings to numbers and then compares them.
+// Converts human-readable numeric strings to numbers and then compares them.
function numericStringsSorter(left, right) {
- left_num = parseInt(left, 10);
- right_num = parseInt(right, 10);
+ left_num = toInt(left);
+ right_num = toInt(right);
if (left_num < right_num) {
return -1;
}