Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Hive Jasper Report with PHP using Cloudera

Hive Jasper Report with PHP using Cloudera

Explorer

Hello,

 

I want to integrate hive jasper report with my PHP application using cloudera. I have successfully created hive report using Jasper. But when i integrate this hive report with my PHP Application, it gives error.

 

Program:

 

<?php
require_once("Jasper/java/Java.inc");

class JasperReports {

public function report_generator($jrxml, $arr) {
$format = $arr['format'];
try {

$jasperxml = new java("net.sf.jasperreports.engine.xml.JRXmlLoader");
$jasperDesign = $jasperxml->load(realpath($jrxml));
/*$query = new java("net.sf.jasperreports.engine.design.JRDesignQuery");
$query->setText($sql);
$jasperDesign->setQuery($query);*/
$compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
$report = $compileManager->compileReport($jasperDesign);
} catch (JavaException $ex) {
print $ex;
}

$fillManager = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");

$params = new Java("java.util.HashMap");
foreach ($arr as $key => $value) {
$params->put($key, $value);
}

$class = new JavaClass("java.lang.Class");
$class->forName("org.apache.hadoop.hive.jdbc.HiveDriver");
$driverManager = new JavaClass("java.sql.DriverManager");

//db username and password
$conn = $driverManager->getConnection("jdbc:hive://192.168.1.177:10001/default", "", "");
$jasperPrint = $fillManager->fillReport($report, $params, $conn);

$exporter = new java("net.sf.jasperreports.engine.JRExporter");

switch ($format) {
case 'xls':
$outputPath = realpath(".") . "\\" . "report.xls";

try {
$exporter = new java("net.sf.jasperreports.engine.export.JRXlsExporter");
$exporter->setParameter(java("net.sf.jasperreports.engine.export.JRXlsExporterParameter")->IS_ONE_PAGE_PER_SHEET, java("java.lang.Boolean")->TRUE);
$exporter->setParameter(java("net.sf.jasperreports.engine.export.JRXlsExporterParameter")->IS_WHITE_PAGE_BACKGROUND, java("java.lang.Boolean")->FALSE);
$exporter->setParameter(java("net.sf.jasperreports.engine.export.JRXlsExporterParameter")->IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, java("java.lang.Boolean")->TRUE);
$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->JASPER_PRINT, $jasperPrint);
$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->OUTPUT_FILE_NAME, $outputPath);
} catch (JavaException $ex) {
print $ex;
}

header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=report.xls");
break;
case 'csv':
$outputPath = realpath(".") . "\\" . "report.csv";

try {
$exporter = new java("net.sf.jasperreports.engine.export.JRCsvExporter");
$exporter->setParameter(java("net.sf.jasperreports.engine.export.JRCsvExporterParameter")->FIELD_DELIMITER, ",");
$exporter->setParameter(java("net.sf.jasperreports.engine.export.JRCsvExporterParameter")->RECORD_DELIMITER, "\n");
$exporter->setParameter(java("net.sf.jasperreports.engine.export.JRCsvExporterParameter")->CHARACTER_ENCODING, "UTF-8");
$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->JASPER_PRINT, $jasperPrint);
$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->OUTPUT_FILE_NAME, $outputPath);
} catch (JavaException $ex) {
print $ex;
}

header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=report.csv");
break;
case 'docx':
$outputPath = realpath(".") . "\\" . "report.docx";

try {
$exporter = new java("net.sf.jasperreports.engine.export.ooxml.JRDocxExporter");
$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->JASPER_PRINT, $jasperPrint);
$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->OUTPUT_FILE_NAME, $outputPath);


} catch (JavaException $ex) {
print $ex;
}

header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment; filename=report.docx");
break;
case 'html':
$outputPath = realpath(".") . "\\" . "report.html";

try {
$exporter = new java("net.sf.jasperreports.engine.export.JRHtmlExporter");
$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->JASPER_PRINT, $jasperPrint);
$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->OUTPUT_FILE_NAME, $outputPath);


} catch (JavaException $ex) {
print $ex;
}
break;
case 'pdf':
$outputPath = realpath(".") . "\\" . "XeReport.pdf";

$exporter = new java("net.sf.jasperreports.engine.export.JRPdfExporter");
$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->JASPER_PRINT, $jasperPrint);
$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->OUTPUT_FILE_NAME, $outputPath);

header("Content-type: application/pdf");
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-Disposition: inline; filename=report.pdf");
break;
case 'ods':
$outputPath = realpath(".") . "\\" . "report.ods";

try {
$exporter = new java("net.sf.jasperreports.engine.export.oasis.JROdsExporter");
$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->JASPER_PRINT, $jasperPrint);
$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->OUTPUT_FILE_NAME, $outputPath);
} catch (JavaException $ex) {
print $ex;
}

header("Content-type: application/vnd.oasis.opendocument.spreadsheet");
header("Content-Disposition: attachment; filename=report.ods");
break;
case 'odt':
$outputPath = realpath(".") . "\\" . "report.odt";

try {
$exporter = new java("net.sf.jasperreports.engine.export.oasis.JROdtExporter");
$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->JASPER_PRINT, $jasperPrint);
$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->OUTPUT_FILE_NAME, $outputPath);
} catch (JavaException $ex) {
print $ex;
}

header("Content-type: application/vnd.oasis.opendocument.text");
header("Content-Disposition: attachment; filename=report.odt");
break;
case 'txt':
$outputPath = realpath(".") . "\\" . "report.txt";

try {
$exporter = new java("net.sf.jasperreports.engine.export.JRTextExporter");
$exporter->setParameter(java("net.sf.jasperreports.engine.export.JRTextExporterParameter")->PAGE_WIDTH, 120);
$exporter->setParameter(java("net.sf.jasperreports.engine.export.JRTextExporterParameter")->PAGE_HEIGHT, 60);
$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->JASPER_PRINT, $jasperPrint);
$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->OUTPUT_FILE_NAME, $outputPath);
} catch (JavaException $ex) {
print $ex;
}

header("Content-type: text/plain");
break;
case 'rtf':
$outputPath = realpath(".") . "\\" . "report.rtf";

try {
$exporter = new java("net.sf.jasperreports.engine.export.JRRtfExporter");
$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->JASPER_PRINT, $jasperPrint);
$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->OUTPUT_FILE_NAME, $outputPath);
} catch (JavaException $ex) {
print $ex;
}

header("Content-type: application/rtf");
header("Content-Disposition: attachment; filename=report.rtf");
break;
case 'pptx':
$outputPath = realpath(".") . "\\" . "report.pptx";
try {
$exporter = new java("net.sf.jasperreports.engine.export.ooxml.JRPptxExporter");
$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->JASPER_PRINT, $jasperPrint);
$exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->OUTPUT_FILE_NAME, $outputPath);
} catch (JavaException $ex) {
print $ex;
}

header("Content-type: aapplication/vnd.ms-powerpoint");
header("Content-Disposition: attachment; filename=report.pptx");
break;
}
$exporter->exportReport();

readfile($outputPath);
//unlink($outputPath);
}
}


?>

 

Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: Invoke failed: [[c:JasperFillManager]]->fillReport((o:JasperReport)[o:JasperReport], (i:Map)[o:HashMap], (i:Connection)[o:HiveConnection]). Cause: java.lang.ClassCastException: org.apache.hadoop.hive.jdbc.HiveConnection cannot be cast to com.jaspersoft.hadoop.hive.connection.HiveConnection VM: 1.7.0_03@http://java.oracle.com/" at: #-20 com.jaspersoft.hadoop.hive.query.HiveQueryExecuter.<init>(HiveQueryExecuter.java:48) #-19 com.jaspersoft.hadoop.hive.query.HiveQueryExecuterFactory.createQueryExecuter(HiveQueryExecuterFactory.java:49) #-18 net.sf.jasperreports.engine.util.JRQueryExecuterUtils$WrappingQueryExecuterFactory.createQueryExecuter(JRQueryExecuterUtils.java:155) #-17 net.sf.jasperreports.engine.fill.JRFillDataset.createQueryDatasource(JRFillDataset.java:1083) #-16 net.sf.jasperreports.engine.fill.JRFillDataset.initDatasource(JRFillDataset.java:667) #-15 net.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:1258) #-14 net.sf.jasperre in D:\workspace\sdp\Jasper\java\Java.inc on line 195

 

 

Please help me in solving this issue as soon as possible.

 

 

Thanks

Surbhi Singh

3 REPLIES 3

Re: Hive Jasper Report with PHP using Cloudera

Rising Star

java.lang.ClassCastException: org.apache.hadoop.hive.jdbc.HiveConnection cannot be cast to com.jaspersoft.hadoop.hive.connection.HiveConnection 

 


org.apache.hadoop.hive.jdbc.HiveConnection value is being assigned to a reference variable of type com.jaspersoft.hadoop.hive.connection.HiveConnection.

 

Make the reference variable of type org.apache.hadoop.hive.jdbc.HiveConnection.

 

 

Re: Hive Jasper Report with PHP using Cloudera

Rising Star

The following statement is throwing the exception.

 

$jasperPrint = $fillManager->fillReport($report, $params, $conn);

 

The fillReport is expecting a com.jaspersoft.hadoop.hive.connection.HiveConnection value and is being invoked with a org.apache.hadoop.hive.jdbc.HiveConnection type value.

Highlighted

Re: Hive Jasper Report with PHP using Cloudera

Explorer

Hey thnks for your reply, but I have com-jaspersoft-ireport-hadoop-hive jar file but i can't find com.jaspersoft.hadoop.hive.connection.HiveConnection jar file...

 

If I am using com-jaspersoft-ireport-hadoop-hive still same error occur.

 

Can you please suugest from where i can get this file.

 

Thanks 

Surbhi

Don't have an account?
Coming from Hortonworks? Activate your account here