Menu

SAP HANA XML/A Service : query.execute() giving Internal Error

Nox Bakht
2013-09-24
2014-06-09
  • Nox Bakht

    Nox Bakht - 2013-09-24

    Hi,

    I am trying to connect to a SAP Hana XMLA service using olap4j.
    I am able to create connection and access the dimension members & Hierarchies.
    But when i am trying to execute any olap query it is giving error.

    Please check my class

    Code:

    public class ConnectClass {

    public static void main(String[] args) throws SQLException {
        String connectionUrl = "jdbc:xmla:Server=<MY URL>:8000/user01/services/hello.xsxmla";
        String cubeName = "AN_ARTICLE_FACT1";
    
        Connection connection = null;
        try {
            Class.forName("org.olap4j.driver.xmla.XmlaOlap4jDriver");
            connection = DriverManager.getConnection(connectionUrl, "username",
                    "password");
            final OlapConnection olapConnection = connection
                    .unwrap(OlapConnection.class);
    
            Cube cube = olapConnection.getOlapSchema().getCubes().get(cubeName);
    
            Iterator<Dimension> dimensions = cube.getDimensions().iterator();
            System.out.println("--------Dimensions(" + cubeName + ")------");
            while (dimensions.hasNext()) {
                Dimension dimension = (Dimension) dimensions.next();
                System.out.println(dimension.getName());
            }
    
            Query query = new Query("JavaQuery", cube);
            QueryDimension outlet_dim = query.getDimension("AT_OUTLET");
            QueryDimension calender_dim = query.getDimension("AT_CALENDER");
    
            query.getAxis(Axis.COLUMNS).addDimension(calender_dim);
            query.getAxis(Axis.ROWS).addDimension(outlet_dim);
    
            query.validate();
            System.out.println("--------MDX Query--------");
            System.out.println(query.getSelect().toString());
            System.out.println("---------------------");
    
            CellSet cellSet = query.execute();
            CellSetFormatter formatter = new RectangularCellSetFormatter(false);
    
            formatter.format(cellSet, new PrintWriter(System.out, true));
            connection.close();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
            connection.close();
        }
    }
    

    }

    ----------------- OUTPUT ---------

    --------Dimensions(AN_ARTICLE_FACT1)------
    Measures
    AT_ARTICLE
    AT_OUTLET
    AT_COLOR
    AT_CALENDER
    --------MDX Query--------
    SELECT
    {[AT_CALENDER].[Hie_Year].[All].[(all)]} ON COLUMNS,
    {[AT_OUTLET].[Hie_state].[All].[(all)]} ON ROWS
    FROM [AN_ARTICLE_FACT1]
    ---------------------
    org.olap4j.OlapException: Internal error: hierarchy 'AT_CALENDER].[Hie_Year' not found in cube 'AN_ARTICLE_FACT1'
    at org.olap4j.driver.xmla.XmlaHelper.createException(XmlaHelper.java:38)
    at org.olap4j.driver.xmla.XmlaOlap4jCellSet.lookupHierarchy(XmlaOlap4jCellSet.java:555)
    at org.olap4j.driver.xmla.XmlaOlap4jCellSet.createMetaData(XmlaOlap4jCellSet.java:450)
    at org.olap4j.driver.xmla.XmlaOlap4jCellSet.populate(XmlaOlap4jCellSet.java:184)
    at org.olap4j.driver.xmla.XmlaOlap4jStatement.executeOlapQuery(XmlaOlap4jStatement.java:353)
    at org.olap4j.driver.xmla.XmlaOlap4jStatement.executeOlapQuery(XmlaOlap4jStatement.java:362)
    at org.olap4j.query.Query.execute(Query.java:302)
    at ConnectClass.main(ConnectClass.java:56)
    -----------------

    I am not able to understand where is the error.
    As i try to run the generated MDX query using the SAP Hana Studio it is working fine.
    I tried some other mdx queries also which are working fine in Hana but giving similar issue
    i.e it's removing starting and end bracket "[" of Member Name and giving error member not found.

    Please suggest me where i am doing it wrong.

     
    • Luc Boudreau

      Luc Boudreau - 2013-09-24

      Looks like a bug in olap4j's XmlaOlap4jCellSet.lookupHierarchy. It is
      getting confused by the brackets.

      Luc

       
  • Nox Bakht

    Nox Bakht - 2013-09-25

    Thanks for replying..

    Is there any workaround to run mdx??

     

    Last edit: Nox Bakht 2013-09-25
    • janelv

      janelv - 2014-06-09

      Hello:
      Did you find the solution to this problem yet?

       

Log in to post a comment.