OLAP analysis (three) - footmart example installation mondrian

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/wh_xia_jun/article/details/90027638

Encounter problems, you want to see with the example mondrian, mondrian would deploy footmart example of a band

There olap4j package:

I understand it is a tool that simplifies mdx query, but do not support all of the official presentation mdx statement.

Here a small scale:

        // olap4j的mdx接口,是一个jdbc实现,推荐
        System.out.println("\r\n===================olap4j接口==================");
        String mdxStr = "select {[年].Members} on columns,{[组织].Members} on rows from 模型一";
        // 建立连接
        String strUrl = "jdbc:mondrian:";
        strUrl += "Jdbc=" + url;
        strUrl += ";JdbcUser=" + userName;
        strUrl += ";JdbcPassword=" + password;
        // strUrl += ";Catalog=" + xmlFile;
        strUrl += ";CatalogContent=" + getCatalogContent();
        Class.forName("mondrian.olap4j.MondrianOlap4jDriver");
        Connection olap4jConn = DriverManager.getConnection(strUrl);
        OlapConnection olapConn = (OlapConnection) olap4jConn.unwrap(OlapConnection.class);

        NamedList<Cube> cubes =
                olapConn.getOlapSchema().getCubes();
        Cube cube = cubes.get("模型一");
        Query myQuery =
                new Query("model1Query", cube);
        myQuery.execute();
       System.out.println("------------myQuery------------:"+myQuery);

        QueryDimension productDim = myQuery.getDimension("年");

        QueryDimension storeDim = myQuery.getDimension("组织");
        //QueryDimension timeDim = myQuery.getDimension("Time");

        myQuery.getAxis(Axis.COLUMNS).addDimension(productDim);
        myQuery.getAxis(Axis.ROWS).addDimension(storeDim);
        //myQuery.getAxis(Axis.FILTER).addDimension(timeDim);

        myQuery.validate();
        System.out.println(
                myQuery.getSelect().toString());

        String s=myQuery.getSelect().toString();

        CellSet cellSet =   myQuery.execute();
        // 输出结果
        CellSetFormatter formatter = new RectangularCellSetFormatter(false);
        formatter.format(cellSet, new PrintWriter(System.out, true));

This tool can generate mdx, query. The resulting statement is as follows:

SELECT
{[年].[年]} ON COLUMNS,
{[组织].[组织]} ON ROWS
FROM [模型一]

However, implementation of the sentence, given:

Caused by: mondrian.olap.MondrianException: Mondrian Error:No function matches signature '{<Level>}'

Yes, I write by hand in front of the statement is: {[years] .members}, so that, how do examples mondrain mounted, and see what's different.

First to a simple configuration foodmart access the database, configuration odbc data source, took a very long time, or connection problems, maybe there is a problem with the connection url wrote,

Mysql decisive change it.

MYSQL:

Login mysql command-line mode as follows:

mysql -h localhost -u root -p password

Error: mysql ERROR 1049 (42000): Unknown database

Find https://blog.csdn.net/dongdekun369/article/details/47175295 article, check that:

mysql -h localhost -u root -ppassword 

-p password and are linked, and quickly a try, it really can visit!

Well ..... I'm really angry ah! ! !

Damn ah! A careless, have been misled for so long. I had some how found in full format -p spaces behind with it.

PS: back -r can keep up with a user name, you can also add spaces, but spaces must not be behind a password.

If you want to omit -h, it seems to have required authorization.

Online download a foodmart_mysql.tar.gz, mysql create footmart database, run foodmart_mysql.sql, foodmart database installation ok.

Also honestly redeploy a foodmart application.

Specify the tomcat jdk, tomcat to modify the startup window title

My machine deployed on tomcat too much, do not sign, the tomcat start command window change the name, mark this:

In the tomcat catalina.bat file, modify:

if "%TITLE%" == "" set TITLE=foodmart_8068

Meanwhile, at the beginning of this document modifications:

set JAVA_HOME=C:\Program Files\Java\Java6\jdk1.6
set JRE_HOME=C:\Program Files\Java\Java6\jre6

copy mondrian.war to the next tomcat. Foreigners to borrow a map:

å¾ç

Browser running:

The rest have to configure the database connection.

Browse to the Mondrian application queries folder, you can find a few examples in which jsp files. Here, I opened my E: \ olap \ service \ tomcat6.0.20_8068 \ webapps \ mondrian \ WEB-INF \ queries folder, locate the following jsp file:

  •     fourheir.jsp
  •     mondrian.jsp
  •     colors.jsp
  •     arrows.jsp
<jp:mondrianQuery id="query01" jdbcDriver="com.mysql.jdbc.Driver" jdbcUrl="jdbc:mysql://localhost:3306/foodmart?characterEncoding=utf8&useSSL=true" catalogUri="/WEB-INF/queries/FoodMart.xml"
   jdbcUser="root" jdbcPassword="****" connectionPooling="false">

Browse the local host address Mondrian: HTTP: // localhost: 8080 / mondrian , mondrian select the first example of "  JPivot Pivot the Table  ."

Since its initial Mondrian needed to fill the cache before view appears, therefore it takes time.

Then, you will see a hierarchical manner can drill table and a caption toolbar that contains the configuration icon.

image

mondrian example program is finished!

The whole configuration process, with reference to

http://hamdihasnaoui.weebly.com/tutorials/category/mondrian   completed, a shape!

Some online with mondrian command-line installation database, the old lady did not try, older, too lazy to look.

foodmart database scripts uploaded, I do not know why five minutes, I was just given a score of 1.

Back to the original question, I used to look at the olap4j .query , I was wrong Where is it?

Or write test code to run it:

public class TestMondrian_footmart1 {
    // 数据库连接信息,这里用的mysql
    private static String url="jdbc:mysql://localhost:3306/foodmart?characterEncoding=utf8&useSSL=true";
    private static String userName = "root";
    private static String password = "***";
    private static String xmlFile = "FoodMart.xml";

    public static void main(String[] args) throws Exception {
        // 建立连接
        String strUrl = "jdbc:mondrian:";
        strUrl += "Jdbc=" + url;
        strUrl += ";JdbcUser=" + userName;
        strUrl += ";JdbcPassword=" + password;
        // strUrl += ";Catalog=" + xmlFile;
        strUrl += ";CatalogContent=" + getCatalogContent();

        Connection connection =
                DriverManager.getConnection(strUrl);
        OlapConnection olapConn = (OlapConnection) connection.unwrap(OlapConnection.class);
    }
    /**
     * 初始化数据库,建表
     * @throws Exception
     */
    private static void initDB() throws Exception {}

    private static String getCatalogContent() throws Exception {
        //InputStream inputStream = mondrian.olap.Util.readVirtualFile(xmlFile);
        InputStream inputStream =null;

        try {

            inputStream=mondrian.olap.Util.readVirtualFile(xmlFile);
            final byte[] bytes = Util.readFully(inputStream, 1024);

            // 下面是mondrian原来的实现,由于byte被强制转化为char,汉字全为乱码,故将这段处理处理掉。
            // final char[] chars = new char[bytes.length];
            // for (int i = 0; i < chars.length; i++) {
            // chars[i] = (char) bytes[i];
            // }
            String s=new String(bytes, "UTF-8");
            return s;
        }catch(Exception e){
            e.printStackTrace();
            return "";
        }
        finally {
            if (inputStream != null) {
                inputStream.close();
            }
        }
    }
}

Ah, error:

xception in thread "main" java.lang.RuntimeException: quoted value ended too soon, at position 5545 in 'Jdbc=jdbc:mysql://localhost:3306/foodmart?characterEncoding=utf8&useSSL=true;JdbcUser=root;JdbcPassword=***;CatalogContent=<?xml version="1.0"?>
<Schema name="FoodMart">
...

</Schema>
'
	at mondrian.olap.Util$ConnectStringParser.parseValue(Util.java:2848)
	at mondrian.olap.Util$ConnectStringParser.parsePair(Util.java:2776)
	at mondrian.olap.Util$ConnectStringParser.parse(Util.java:2757)
	at mondrian.olap.Util.parseConnectString(Util.java:2736)
	at mondrian.olap4j.MondrianOlap4jConnection.<init>(MondrianOlap4jConnection.java:156)
	at mondrian.olap4j.FactoryJdbc4Plus$AbstractConnection.<init>(FactoryJdbc4Plus.java:323)
	at mondrian.olap4j.FactoryJdbc41Impl$MondrianOlap4jConnectionJdbc41.<init>(FactoryJdbc41Impl.java:118)
	at mondrian.olap4j.FactoryJdbc41Impl.newConnection(FactoryJdbc41Impl.java:32)
	at mondrian.olap4j.MondrianOlap4jDriver.connect(MondrianOlap4jDriver.java:97)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:270)
	at com.muge.as.dao.TestMondrian_footmart1.main(TestMondrian_footmart1.java:54)

Guess is caused by the connection string symbols, check the connection string, found String strUrl = "jdbc: mondrian:"; inside; written:

Instead String strUrl = "jdbc: mondrian;"; eliminate this problem.

再次运行:报告:No suitable driver found for jdbc:mondrian;JdbcDrivers=...错误。

驱动类没有加载?检查发现没有

Class.forName("mondrian.olap4j.MondrianOlap4jDriver");

加上,再运行测试代码。

Exception in thread "main" java.lang.NoClassDefFoundError: mondrian/xmla/XmlaHandler$XmlaExtra

嗯,我昨天在pom.xml把mondrian3.17 升级为mondrian4.7 版本;查资料得知,xmla,从mondrain 中分离了,试引入新包olap4j-xmla-1.2.jar,pom.xml中添加olap4j-xmla-1.2.jar,再运行,这个错误不报告了

再运行测试,还是报告:No suitable driver found for jdbc:mondrian;JdbcDrivers=...错误。

各种调整connect string,但不奏效;

猜测原因:

  1. mysql连接有问题,解决办法:先单独测试mysql,单独测试mysql 连接没有问题;
  2. mondrian 版本问题 解决办法:换个mondrian版本;

              换版本idea当中,好像得执行

用如下字符串测试连接:

 Provider=mondrian;Catalog=FoodMart.xml;JdbcDrivers=com.mysql.jdbc.Driver;Jdbc=jdbc:mysql://localhost:3306/foodmart?characterEncoding=utf8&useSSL=true;JdbcUser=root;JdbcPassword=**

Still the same error; and this connection string, mysql the url user name, password, JdbcDrivers will not be wrong, is wrong is Provider = mondrian; Catalog = FoodMart.xml ;? This two part? Catalog = FoodMart.xml; into

;CatalogContent=" + getCatalogContent()

Or invalid;

Each jar package come first guide,

3, lack of relevant jar package jar fill a variety of solutions to the Internet, said a jar ,, are introduced, still the same error message

4, the connection string error online search solutions, test;

The above methods are tried, the old lady spent much time n, invalid, then adjust their thinking.

1) lead into the mysql Oracle database;

2) replace the derby database

I am here using Method 1

Using data-integration conversion, to convert the database foodmart oracle.

And then perform tests:

Error reported:

Exception in thread "main" mondrian.olap.MondrianException: Mondrian Error:Named set in cube 'Sales' has bad formula
...
...
...
Caused by: mondrian.olap.MondrianException: Mondrian Error:Internal error: Populating member cache with members for [[Time].[Year]]; sql=[select "time_by_day"."the_year" as "c0" from "time_by_day" "time_by_day" group by "time_by_day"."the_year" order by "time_by_day"."the_year" ASC NULLS LAST]

plsql test, did not find the error report, the field names, table names changed size, plsql test.

Typically, tables and columns are not case sensitive, but if the use of quotation marks, they will be case sensitive. Automatically generated statement with quotation marks;

Hands prompted, in the idea, while mad press Ctrl + Shift + U, modify foodmart.xml related table name and field name in uppercase. Foodmart and database connection success!

Back to the original question, I write the query olap4 of what is wrong with it?

Compare database table structure example, mondrain documents say.

Previous: Configuration

The next section: schemal

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/wh_xia_jun/article/details/90027638