Most people using HANA XS by now are probably familiar with the SHINE demo content:
http://help.sap.com/hana/SAP_HANA_Interactive_Education_SHINE_en.pdf
It has a nice example of downloading the results of a query to EXCEL.
With a small tweak I've taken the idea one step further to enable the results to be downloaded, as a TAB delimited text file, onto the HADOOP Distribute File system (HDFS), using the HADOOP WebHDFS REST API CREATE operation
Storing reports on HADOOP, rather than a traditional file system might then make these user driven snapshots more accessible for future querying, perhaps even being consumed back into HANA via Smart data access.
Here is the new button I added to the SHINE PO Worklist example:
Click the 'Download to HADOOP' button.
Now lets see if a file was created on the HADOOP File System.
SUCCESS!!!!
[checked using HADOOP HDFS Explorer built with HANA XS and SAPUI5]
[checked using standard Hadoop User Interface HUE]
The wedHDFS library I've built for this example is available at https://github.com/AronMacDonald/HanaHdfsExplorer
I also made the following small changes/additions to the SHINE Code:
poWorklistQuery.js
//Changes from ~ line 260 onwards [After downloadExcel() ]
.
.
/****************************************************************************/
/****************** START HADOOP MOD ***********************************/
function downloadHADOOP() {
//import a library for doing PUT & GET to webHDFS
$.import("s0000xxxxxxtrial.trial.HadoopHbase1.webHDFS","webHDFS");
var webHDFS = $.s0000xxxxxxtrial.trial.HadoopHbase1.webHDFS.webHDFS; //$.HanaHbase.Hbase;
var body = '';
try {
var query = 'SELECT TOP 25000 \"PurchaseOrderId\", \"PartnerId\", \"CompanyName\", \"CreatedByLoginName\", \"CreatedAt\", \"GrossAmount\" '
+ 'FROM \"_SYS_BIC\".\"s0000716522trial.trial.shine.data::purchaseOrderHeaderExt\" order by \"PurchaseOrderId\"';
var conn = $.db.getConnection();
var pstmt = conn.prepareStatement(query);
var rs = pstmt.executeQuery();
body = MESSAGES.getMessage('SEPM_POWRK', '002') + "\t" + // Purchase
// Order ID
MESSAGES.getMessage('SEPM_POWRK', '003') + "\t" + // Partner ID
MESSAGES.getMessage('SEPM_POWRK', '001') + "\t" + // Company Name
MESSAGES.getMessage('SEPM_POWRK', '004') + "\t" + // Employee
// Responsible
MESSAGES.getMessage('SEPM_POWRK', '005') + "\t" + // Created At
MESSAGES.getMessage('SEPM_POWRK', '006') + "\n"; // Gross Amount
while (rs.next()) {
body += rs.getNString(1) + "\t" + rs.getNString(2) + "\t"
+ rs.getNString(3) + "\t" + rs.getNString(4) + "\t"
+ rs.getDate(5) + "\t" + rs.getDecimal(6) + "\n";
}
rs.close();
pstmt.close();
} catch (e) {
$.response.status = $.net.http.INTERNAL_SERVER_ERROR;
$.response.setBody(e.message);
return;
}
//Path & Filename to save on HADOOP HDFS
var pathFile = '/user/admin/hanaDownload/POList_';
// append timestamp
pathFile += new Date( Date.now()).toISOString()
.replace("T","")
.replace(/\./g,'')
.replace(/\-/g,'')
.replace(/\:/g,'')
.substring(0,14) + '.txt';
var webHDFSResponse = webHDFS.PutCreate(escape(pathFile), body);
$.response.contentType = "application/json";
$.response.setBody(JSON.stringify(webHDFSResponse));
$.response.status = $.net.http.OK;
}
/****************** STOP HADOOP MOD ***********************************/
/****************************************************************************/
var aCmd = $.request.parameters.get('cmd');
switch (aCmd) {
case "filter":
getFilter();
break;
case "getTotalOrders":
getTotalOrders();
break;
case "Excel":
downloadExcel();
break;
/****************************************************************************/
/****************** START HADOOP MOD ***********************************/
case "HADOOP":
downloadHADOOP();
break;
/****************** STOP HADOOP MOD ***********************************/
/****************************************************************************/
case "getSessionInfo":
SESSIONINFO.fillSessionInfo();
break;
default:
$.response.status = $.net.http.INTERNAL_SERVER_ERROR;
$.response.setBody(MESSAGES.getMessage('SEPM_ADMIN', '002', aCmd));
}
Table.controller.js
//Changes from ~ line 37 onward
.
.
.
//Excel Download
if (oEvent.getSource().getId()=="btnExcel"){
$.download('../../../services/poWorklistQuery.xsjs','cmd=Excel','GET' );
return;
}
/****************************************************************************/
/****************** START HADOOP DOWNLOAD ******************************/
//Download to HADOOP
if (oEvent.getSource().getId()=="btnHADOOP"){
jQuery.ajax({
url: "../../../services/poWorklistQuery.xsjs?cmd=HADOOP" ,
method: 'GET',
success: function(collection) {
sap.ui.commons.MessageBox.show('Download to HADOOP Complete');
return;
},
error: function(xhr, textStatus, errorThrown) {return;} });
return;
}
/****************** STOP HADOOP MOD ***********************************/
/****************************************************************************/
//Check for selected item for all other events
var oTable = sap.ui.getCore().byId("poTable");
var data = oTable.getModel();
.
.
.
Table.view.js
//Changes from ~ line 134 onward
.
.
oToolbar1.addItem(oButton1);
/****************** START HADOOP DOWNLOAD ******************************/
/****************************************************************************/
var oButton2 = new sap.ui.commons.Button("btnHADOOP",{
text : 'Download to HADOOP',
tooltip : 'Download to HADOOP',
press : function(oEvent){
oController.onTBPress(oEvent,oController); }
});
oToolbar1.addItem(oButton2);
/****************** STOP HADOOP MOD ***********************************/
/****************************************************************************/
oTable.setToolbar(oToolbar1);
If you give it a try please let me know how you get on. :cool:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
10 | |
5 | |
5 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 |