diff --git a/src/splunk-wdc.js b/src/splunk-wdc.js index 34057cc..7c2fc01 100644 --- a/src/splunk-wdc.js +++ b/src/splunk-wdc.js @@ -5,6 +5,7 @@ var res = []; // Response Handler var max_record_limit = 10000; // Max record splunk would return in one go. (max is 50K) var myConnector = new tableau.makeConnector(); // Create the connector object + var fields = {}; // Response field types dictionary // returns array of SPL Query string and Auth string _params = lzw_decode(b64DecodeUnicode(window.location.href.split("?")[1].split("query=")[1])).split("[-][-][-]"); @@ -200,12 +201,71 @@ log("added colum definition"); Object.keys(res[0]).forEach(function (key) { log('Key : ' + key + ', Value : ' + res[0][key]); - cols.push({ - id: key, - alias: key, - dataType: tableau.dataTypeEnum.string - }); - }); + + if ( res[0][key].match(/^-?\d+$/) ) { + + // Integer column definition (int) + cols.push({ + id: key, + alias: key, + dataType: tableau.dataTypeEnum.int + }); + fields[key] = "int"; + //log("Column " + key + " added as an integer"); + + } else if ( res[0][key].match(/^\d*\.\d+$/)) { + + // Float column definition (float) + cols.push({ + id: key, + alias: key, + dataType: tableau.dataTypeEnum.float + }); + fields[key] = "float"; + //log("Column " + key + " added as a float"); + + } else if ( res[0][key].match(/^(t|f|true|false)$/i) ) { + // Boolean column definition (bool) + cols.push({ + id: key, + alias: key, + dataType: tableau.dataTypeEnum.bool + }); + fields[key] = "bool"; + //log("Column " + key + " added as a boolean"); + + } else if ( res[0][key].match(/^\d{4}[\/-]\d{2}[\/-]\d{2}$/) + || res[0][key].match(/^\d{2}[\/-]\d{2}[\/-]\d{4}$/) + || res[0][key].match(/^\d{1,2}[\/ -][A-Z][a-z]+(\s\d{2,4})?$/) + || res[0][key].match(/^[A-Z][a-z]+\s+\d{1,2}(\s\d{2,4})?$/) ) { + // Date column definition + cols.push({ + id: key, + alias: key, + dataType: tableau.dataTypeEnum.date + }); + fields[key] = "date"; + //log("Column " + key + " added as a date"); + + } else if ( ! isNaN(Date.parse(res[0][key])) ) { + // Datetime column definition + cols.push({ + id: key, + alias: key, + dataType: tableau.dataTypeEnum.datetime + }); + fields[key] = "datetime"; + //log("Column " + key + " added as a datetime"); + + } else { + // String column definition + cols.push({ + id: key, + alias: key, + dataType: tableau.dataTypeEnum.string + }); + } + }); // End foreach key log('tableInfo'); @@ -242,13 +302,6 @@ if (err) console.log("Error: " + err); } ); // Async Ends - - - - - - - } }); } @@ -262,7 +315,20 @@ var tableData = []; log("Total records: "); log(res.length); - for (var i = 0; i < res.length; ++i) { + d = new Date(); + date_offset = 0; + // Correct the displayed time to be local time + // Comment the following line to get the true time in UTC + date_offset = d.getTimezoneOffset(); + for (var i=0; i