use of org.olap4j.CellSet in project pentaho-kettle by pentaho.
the class OlapHelper method openQuery.
public void openQuery() throws Exception {
Class.forName(olap4jDriver);
OlapConnection connection = null;
if (Utils.isEmpty(username) && Utils.isEmpty(password)) {
connection = (OlapConnection) DriverManager.getConnection(olap4jUrl);
} else {
connection = (OlapConnection) DriverManager.getConnection(olap4jUrl, username, password);
}
OlapWrapper wrapper = connection;
olapConnection = wrapper.unwrap(OlapConnection.class);
try {
if (!Utils.isEmpty(catalogName)) {
olapConnection.setCatalog(catalogName);
}
} catch (SQLException e) {
throw new OlapException("Error setting catalog for MDX statement: '" + catalogName + "'");
}
OlapStatement stmt = olapConnection.createStatement();
if (!Utils.isEmpty(mdx)) {
CellSet tmp = stmt.executeOlapQuery(mdx);
result = tmp;
} else {
throw new Exception("Error executing empty MDX query");
}
}
use of org.olap4j.CellSet in project mondrian by pentaho.
the class MonitorTest method testMe.
/**
* Exercises as many fields of the monitoring stats classes as possible.
* So that we can check that they are being populated.
*/
public void testMe() throws SQLException {
String queryString = "WITH MEMBER [Measures].[Foo] AS\n" + " [Measures].[Unit Sales]" + " + case when [Measures].[Unit Sales] > 0\n" + " then CInt( ([Measures].[Foo], [Time].PrevMember) )\n" + " end\n" + "SELECT [Measures].[Foo] on 0\n" + "from [Sales]\n" + "where [Time].[1997].[Q3].[9]";
final OlapStatement statement1 = getTestContext().getOlap4jConnection().createStatement();
CellSet cellSet = statement1.executeOlapQuery(queryString);
StringWriter stringWriter = new StringWriter();
new RectangularCellSetFormatter(true).format(cellSet, new PrintWriter(stringWriter));
statement1.close();
println(stringWriter);
final MondrianServer mondrianServer = MondrianServer.forConnection(getConnection());
final Monitor monitor = mondrianServer.getMonitor();
final ServerInfo server = monitor.getServer();
println("# stmts open: " + server.getStatementCurrentlyOpenCount());
println("# connections open: " + server.getConnectionCurrentlyOpenCount());
println("# rows fetched: " + server.sqlStatementRowFetchCount);
println("# sql stmts open: " + server.getSqlStatementCurrentlyOpenCount());
// # sql stmts by category (cell query, member query, other)
// -- if you want to do this, capture sql statement events
// cell cache requests
// cell cache misses
// cell cache hits
final List<ConnectionInfo> connections = monitor.getConnections();
ConnectionInfo lastConnection = connections.get(connections.size() - 1);
// Cannot reliably retrieve the last statement, since statements are
// removed from the map on completion.
// final List<StatementInfo> statements = monitor.getStatements();
// StatementInfo lastStatement = statements.get(statements.size() - 1);
println("# cell cache requests, misses, hits; " + "by server, connection, mdx statement: " + server.cellCacheRequestCount + ", " + server.getCellCacheMissCount() + ", " + server.cellCacheHitCount + "; " + lastConnection.cellCacheRequestCount + ", " + (lastConnection.cellCacheRequestCount - lastConnection.cellCacheHitCount) + ", " + lastConnection.cellCacheHitCount);
// cache misses in the last minute
// cache hits in the last minute
// -- build a layer on top of monitor that polls say every 15 seconds,
// and keeps results for a few minutes
println("number of mdx statements currently open: " + server.getStatementCurrentlyOpenCount());
println("number of mdx statements currently executing: " + server.getStatementCurrentlyExecutingCount());
println("jvm memory: " + server.jvmHeapBytesUsed + ", max: " + server.jvmHeapBytesMax + ", committed: " + server.jvmHeapBytesCommitted);
println("number of segments: " + server.segmentCount + ", ever created: " + server.segmentCreateCount + ", number of cells: " + server.cellCount + ", number of cell coordinates: " + server.cellCoordinateCount + ", average cell dimensionality: " + ((float) server.cellCoordinateCount / (float) server.cellCount));
println("Connection: " + lastConnection);
println("Server: " + server);
// number of mdx function calls cumulative
// how many operations have been evaluated in sql?
// number of members in cache
// number of cells in segments
// mdx query time
// sql query time
// sql rows
// olap4j connection pool size
// sql connection pool size
// thread count
// # schemas in schema cache
// cells fulfilled by sql statements
// mondrian server count (other stats relate to just one server)
//
// Events:
//
// SQL statement start
// SQL statment stop
// external cache call
// sort
// (other expensive operations similar to sort?)
}
use of org.olap4j.CellSet in project bamboobsc by billchen198318.
the class OlapUtils method getResultSet.
/**
* 取CellSet
*
* @param connection
* @param mdx
* @return
* @throws OlapException
* @throws Exception
*/
public static CellSet getResultSet(OlapConnection connection, String mdx) throws OlapException, Exception {
OlapStatement olapStatement = connection.createStatement();
CellSet cellSet = olapStatement.executeOlapQuery(mdx);
return cellSet;
}
use of org.olap4j.CellSet in project mondrian by pentaho.
the class XmlaHandlerTypeTest method testDatatypeConsistency.
/**
* Checks whether Cell.getValue() returns a consistent datatype whether
* retrieved from Olap4jXmla, Olap4j, or native Mondrian.
* @throws SQLException
*/
public void testDatatypeConsistency() throws SQLException {
TestContext context = getTestContext();
// MDX cast expressions
String[] castedTypes = { "Cast(1 as String)", "Cast(1 as Numeric)", "Cast(1 as Boolean)", "Cast(1 as Integer)" };
for (String castedType : castedTypes) {
String mdx = "with member measures.type as '" + castedType + "' " + "select measures.type on 0 from sales";
CellSet olap4jXmlaCellset = context.executeOlap4jXmlaQuery(mdx);
CellSet olap4jCellset = context.executeOlap4jQuery(mdx);
Result nativeMondrianResult = context.executeQuery(mdx);
assertEquals("Checking olap4jXmla datatype against native Mondrian. \n" + "Unexpected datatype when running mdx " + mdx + "\n", nativeMondrianResult.getCell(new int[] { 0 }).getValue().getClass(), olap4jXmlaCellset.getCell(0).getValue().getClass());
assertEquals("Checking olap4jXmla datatype against native Mondrian. \n" + "Unexpected datatype when running mdx " + mdx + "\n", olap4jXmlaCellset.getCell(0).getValue().getClass(), olap4jCellset.getCell(0).getValue().getClass());
}
RolapCube cube = (RolapCube) context.executeQuery("select from sales").getQuery().getCube();
Dialect dialect = cube.getStar().getSqlQueryDialect();
if (!dialect.getDatabaseProduct().equals(Dialect.DatabaseProduct.MYSQL) && !dialect.getDatabaseProduct().equals(Dialect.DatabaseProduct.ORACLE)) {
return;
}
// map of sql expressions to the corresponding (optional) datatype
// attribute (RolapBaseCubeMeasure.Datatype)
Map<String, String> expressionTypeMap = new HashMap<String, String>();
expressionTypeMap.put("'StringValue'", "String");
expressionTypeMap.put("cast(1.0001 as decimal)", null);
expressionTypeMap.put("cast(1.0001 as decimal)", "Numeric");
expressionTypeMap.put("cast(10.101 as decimal(10,8))", null);
expressionTypeMap.put("cast(10.101 as decimal(10,8))", "Numeric");
for (String expression : expressionTypeMap.keySet()) {
String query = "Select measures.typeMeasure on 0 from Sales";
context = getContextWithMeasureExpression(expression, expressionTypeMap.get(expression));
CellSet olap4jXmlaCellset = context.executeOlap4jXmlaQuery(query);
CellSet olap4jCellset = context.executeOlap4jQuery(query);
Result nativeMondrianResult = context.executeQuery(query);
assertEquals("Checking olap4jXmla datatype against native Mondrian. \n" + "Unexpected datatype for measure expression " + expression + " with datatype attribute " + expressionTypeMap.get(expression) + "\n", nativeMondrianResult.getCell(new int[] { 0 }).getValue().getClass(), olap4jXmlaCellset.getCell(0).getValue().getClass());
assertEquals("Checking olap4jXmla datatype against olap4j in process. \n" + "Unexpected datatype for expression " + expression + " with datatype attribute " + expressionTypeMap.get(expression) + "\n", olap4jXmlaCellset.getCell(0).getValue().getClass(), olap4jCellset.getCell(0).getValue().getClass());
}
}
use of org.olap4j.CellSet in project mondrian by pentaho.
the class CmdRunner method runQuery.
/**
* Executes a query and processes the result using a callback.
*
* @param queryString MDX query text
*/
public <T> T runQuery(String queryString, Util.Functor1<T, CellSet> f) {
long start = System.currentTimeMillis();
OlapConnection connection = null;
OlapStatement statement = null;
CellSet cellSet = null;
try {
connection = getOlapConnection();
statement = connection.createStatement();
debug("CmdRunner.runQuery: AFTER createStatement");
start = System.currentTimeMillis();
cellSet = statement.executeOlapQuery(queryString);
return f.apply(cellSet);
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
queryTime = (System.currentTimeMillis() - start);
totalQueryTime += queryTime;
debug("CmdRunner.runQuery: BOTTOM");
Util.close(cellSet, statement, connection);
}
}
Aggregations