Hive report not working with PHP Application

0
My hive server is running on 192.168.220:10001. I am able to connect hive with my PHP Application through this program. I am able to create, insert or select data from hive table in PHP Application.
 
<?php
$GLOBALS['THRIFT_ROOT'] = dirname(__FILE__) . '/lib';
require_once $GLOBALS['THRIFT_ROOT'] . '/packages/hive_service/ThriftHive.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/protocol/TBinaryProtocol.php';
 
require_once dirname(__FILE__) . '/ThriftHiveClientEx.php';
 
$transport = new TSocket('192.168.1.220', 10001);
$transport->setSendTimeout(600 * 1000);
$transport->setRecvTimeout(600 * 1000);
$client = new ThriftHiveClientEx(new TBinaryProtocol($transport));
$client->open();
$client->execute('select * from user');
var_dump($client->fetchAll());
$client->close();
?>
 
Now i want to generate Hive report from my PHP Application. I am able to create jasper report with hive from IReport. Since this is my PHP code for generating reports in PHP.
 
<?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.220:10001/default", "", "");
        $jasperPrint = $fillManager->fillReport($report, $params , $conn);
        print 'hi';
        
        $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(".") . "\\" . "report.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);
    }
}
?>
 
Error :
 
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 find attached java.inc file.
 
 
Please help me by providing the solution as soon as possible.
 
Thanks & Regards
Surbhi Singh
 
Attachments: 
surbhi.singh's picture
Joined: Aug 10 2013 - 12:43am
Last seen: 5 years 12 months ago

2 Answers:

0

Hi,

Are you tried jasper PHP client for your requirement?

Thanks

Ajinkya

ajinkya_c's picture
935
Joined: Aug 29 2012 - 6:13am
Last seen: 2 years 8 months ago
0

Please can any one help me to solve this error. I just want to integrate hive jasper report with my PHP Application.

surbhi.singh's picture
Joined: Aug 10 2013 - 12:43am
Last seen: 5 years 12 months ago
Feedback