This is an automated email from the ASF dual-hosted git repository.

nitiraj pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 577bf7d  AMBARI-23179 : Hive view 2.0 does not parse the TAB delimited 
CSV files while using 'Upload Table' (nitirajrathore) (#592)
577bf7d is described below

commit 577bf7d08257300d96d6bc05178d6af065fa3afb
Author: nitirajrathore <nitiraj.rath...@gmail.com>
AuthorDate: Tue Mar 13 10:21:06 2018 +0530

    AMBARI-23179 : Hive view 2.0 does not parse the TAB delimited CSV files 
while using 'Upload Table' (nitirajrathore) (#592)
    
    * AMBARI-22833 : change commons-collections-3.2.1.jar being used by ambari 
views to commons-collections-3.2.2.jar (nitirajrathore)
    
    * AMBARI-23179 : Hive view 2.0 does not parse the TAB delimited CSV files 
while using 'Upload Table' (nitirajrathore)
---
 .../databases/database/tables/upload-table.js      | 65 ++++++++++++++--------
 1 file changed, 43 insertions(+), 22 deletions(-)

diff --git 
a/contrib/views/hive20/src/main/resources/ui/app/routes/databases/database/tables/upload-table.js
 
b/contrib/views/hive20/src/main/resources/ui/app/routes/databases/database/tables/upload-table.js
index 799a87a..54acc22 100644
--- 
a/contrib/views/hive20/src/main/resources/ui/app/routes/databases/database/tables/upload-table.js
+++ 
b/contrib/views/hive20/src/main/resources/ui/app/routes/databases/database/tables/upload-table.js
@@ -28,6 +28,10 @@ export default NewTable.extend(UILoggerMixin, {
   COLUMN_NAME_REGEX: "^[a-zA-Z]{1}[a-zA-Z0-9_]*$",
   TABLE_NAME_REGEX: "^[a-zA-Z]{1}[a-zA-Z0-9_]*$",
   HDFS_PATH_REGEX: "^[/]{1}.+",  // unix path allows everything but here we 
have to mention full path so starts with /
+  DEFAULT_CSV_DELIMITER: ',',
+  DEFAULT_CSV_QUOTE: '"',
+  DEFAULT_CSV_ESCAPE: '\\',
+
   i18n : Ember.inject.service("i18n"),
   jobService: Ember.inject.service(constants.services.jobs),
   notifyService: Ember.inject.service(constants.services.alertMessages),
@@ -130,18 +134,30 @@ export default NewTable.extend(UILoggerMixin, {
       reject(error);
     });
   },
+  getCSVParams : function(csvParams){
+    var csvd = String.fromCharCode(csvParams.get('csvDelimiter.id'));
+    if(!csvd && csvd != 0) csvd = this.get('DEFAULT_CSV_DELIMITER');
+
+    var csvq = String.fromCharCode(csvParams.get('csvQuote.id'));
+    if(!csvq && csvq != 0) csvq = this.get('DEFAULT_CSV_QUOTE');
+
+    var csve = String.fromCharCode(csvParams.get('csvEscape.id'));
+    if(!csve && csve != 0) csve = this.get('DEFAULT_CSV_ESCAPE');
+
+    return Ember.Object.create({"csvDelimiter": csvd, "csvQuote" : csvq, 
"csvEscape": csve});
+  },
 
   uploadForPreview: function (sourceObject) {
     console.log("uploaderForPreview called.");
     let files = sourceObject.get("fileInfo.files");
-    let csvParams = sourceObject.get("fileFormatInfo.csvParams");
-
+    let fileFormatCsvParams = sourceObject.get("fileFormatInfo.csvParams");
+    let csvParams = this.getCSVParams(fileFormatCsvParams);
     return this.getUploader().uploadFiles('preview', files, {
       "inputFileType": sourceObject.get("fileFormatInfo.inputFileType").id,
-      "isFirstRowHeader": csvParams.get("isFirstRowHeader"),
-      "csvDelimiter": csvParams.get("csvDelimiter").name,
-      "csvEscape": csvParams.get("csvEscape").name,
-      "csvQuote": csvParams.get("csvQuote").name
+      "isFirstRowHeader": fileFormatCsvParams.get("isFirstRowHeader"),
+      "csvDelimiter": csvParams.get("csvDelimiter"),
+      "csvEscape": csvParams.get("csvEscape"),
+      "csvQuote": csvParams.get("csvQuote")
     });
   },
 
@@ -150,15 +166,16 @@ export default NewTable.extend(UILoggerMixin, {
     // this.validateHDFSPath(hdfsPath);
     var self = sourceObject;
     var hdfsPath = sourceObject.get("fileInfo.hdfsPath");
-    var csvParams = sourceObject.get("fileFormatInfo.csvParams");
+    var fileFormatCsvParams = sourceObject.get("fileFormatInfo.csvParams");
+    let csvParams = this.getCSVParams(fileFormatCsvParams);
 
     return this.getUploader().previewFromHDFS({
       "inputFileType": sourceObject.get("fileFormatInfo.inputFileType").id,
       "hdfsPath": hdfsPath,
-      "isFirstRowHeader": csvParams.get("isFirstRowHeader"),
-      "csvDelimiter": csvParams.get("csvDelimiter").name,
-      "csvEscape": csvParams.get("csvEscape").name,
-      "csvQuote": csvParams.get("csvQuote").name
+      "isFirstRowHeader": fileFormatCsvParams.get("isFirstRowHeader"),
+      "csvDelimiter": csvParams.get("csvDelimiter"),
+      "csvEscape": csvParams.get("csvEscape"),
+      "csvQuote": csvParams.get("csvQuote")
     });
   },
 
@@ -681,8 +698,10 @@ export default NewTable.extend(UILoggerMixin, {
   },
   uploadTableFromHdfs : function(tableData){
     console.log("uploadTableFromHdfs called.");
-    this.pushUploadProgressInfos(this.formatMessage('uploadingFromHdfs'));
-    var csvParams = tableData.get("fileFormatInfo.csvParams");
+    
this.pushUploadProgressInfos(this.formatMessage('hive.messages.uploadingFromHdfs'));
+    var fileFormatCsvParams = tableData.get("fileFormatInfo.csvParams");
+    var csvParams = this.getCSVParams(fileFormatCsvParams);
+
     let columns = tableData.get("tableMeta").columns.map(function (column) {
       return {"name": column.get("name"), "type": column.get("type.label")};
     });
@@ -695,14 +714,16 @@ export default NewTable.extend(UILoggerMixin, {
       "hdfsPath": tableData.get("fileInfo.hdfsPath"),
       "header": header,
       "containsEndlines": tableData.get("fileFormatInfo.containsEndlines"),
-      "isFirstRowHeader": csvParams.get("isFirstRowHeader"),
-      "csvDelimiter": csvParams.get("csvDelimiter").name,
-      "csvEscape": csvParams.get("csvEscape").name,
-      "csvQuote": csvParams.get("csvQuote").name
+      "isFirstRowHeader": fileFormatCsvParams.get("isFirstRowHeader"),
+      "csvDelimiter": csvParams.get("csvDelimiter"),
+      "csvEscape": csvParams.get("csvEscape"),
+      "csvQuote": csvParams.get("csvQuote")
     });
   },
   uploadTable: function (tableData) {
-    var csvParams = tableData.get("fileFormatInfo.csvParams");
+    var fileFormatCsvParams = tableData.get("fileFormatInfo.csvParams");
+    var csvParams = this.getCSVParams(fileFormatCsvParams);
+
     let columns = tableData.get("tableMeta").columns.map(function(column){
       return {"name": column.get("name"), "type": column.get("type.label")};
     });
@@ -713,10 +734,10 @@ export default NewTable.extend(UILoggerMixin, {
       "inputFileType" : tableData.get("fileFormatInfo.inputFileType").id,
       "header": header,
       "containsEndlines": tableData.get("fileFormatInfo.containsEndlines"),
-      "isFirstRowHeader": csvParams.get("isFirstRowHeader"),
-      "csvDelimiter": csvParams.get("csvDelimiter").name,
-      "csvEscape": csvParams.get("csvEscape").name,
-      "csvQuote": csvParams.get("csvQuote").name
+      "isFirstRowHeader": fileFormatCsvParams.get("isFirstRowHeader"),
+      "csvDelimiter": csvParams.get("csvDelimiter"),
+      "csvEscape": csvParams.get("csvEscape"),
+      "csvQuote": csvParams.get("csvQuote")
     });
   },
 

-- 
To stop receiving notification emails like this one, please contact
niti...@apache.org.

Reply via email to