use of org.olap4j.OlapStatement 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.OlapStatement 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.OlapStatement 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.OlapStatement in project teiid by teiid.
the class TestOlapTranslator method testCannedProcedure.
@Test
public void testCannedProcedure() throws Exception {
String ddl = "create foreign procedure proc(arg integer, arg1 date) returns table (x string) options (\"teiid_rel:native-query\" '$2 $1 something')";
String query = "exec proc(2, {d'1970-01-01'})";
TransformationMetadata tm = RealMetadataFactory.fromDDL(ddl, "x", "phy");
CommandBuilder commandBuilder = new CommandBuilder(tm);
Command obj = commandBuilder.getCommand(query);
OlapExecutionFactory oef = new OlapExecutionFactory();
Connection mock = Mockito.mock(java.sql.Connection.class);
OlapWrapper mock2 = Mockito.mock(OlapWrapper.class);
OlapConnection mock3 = Mockito.mock(OlapConnection.class);
OlapStatement mock4 = Mockito.mock(OlapStatement.class);
Mockito.stub(mock4.executeOlapQuery(Mockito.anyString())).toThrow(new TeiidRuntimeException());
Mockito.stub(mock3.createStatement()).toReturn(mock4);
Mockito.stub(mock2.unwrap(OlapConnection.class)).toReturn(mock3);
Mockito.stub(mock.unwrap(OlapWrapper.class)).toReturn(mock2);
ProcedureExecution pe = oef.createProcedureExecution((Call) obj, Mockito.mock(ExecutionContext.class), new RuntimeMetadataImpl(tm), mock);
try {
pe.execute();
fail();
} catch (TeiidRuntimeException e) {
Mockito.verify(mock4).executeOlapQuery("'1970-01-01' 2 something");
}
}
use of org.olap4j.OlapStatement 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