Search in sources :

Example 1 with Dialect

use of mondrian.spi.Dialect in project mondrian by pentaho.

the class SqlStatementTest method testCreateDialect.

public void testCreateDialect() {
    statement = mock(SqlStatement.class);
    Dialect dialect = mock(Dialect.class);
    when(statement.getDialect(any())).thenCallRealMethod();
    when(statement.createDialect()).thenReturn(dialect);
    Dialect dialectReturn = statement.getDialect(null);
    assertNotNull(dialectReturn);
    assertEquals(dialect, dialectReturn);
}
Also used : Dialect(mondrian.spi.Dialect)

Example 2 with Dialect

use of mondrian.spi.Dialect in project mondrian by pentaho.

the class RolapCell method drillThroughInternal.

/**
 * Generates an executes a SQL statement to drill through this cell.
 *
 * <p>Throws if this cell is not drillable.
 *
 * <p>Enforces limits on the starting and last row.
 *
 * <p>If tabFields is not null, returns the specified columns. (This option
 * is deprecated.)
 *
 * @param maxRowCount Maximum number of rows to retrieve, <= 0 if unlimited
 * @param firstRowOrdinal Ordinal of row to skip to (1-based), or 0 to
 *   start from beginning
 * @param fields            List of field expressions to return as the
 *                          result set columns.
 * @param extendedContext   If true, add non-constraining columns to the
 *                          query for levels below each current member.
 *                          This additional context makes the drill-through
 *                          queries easier for humans to understand.
 * @param logger Logger. If not null and debug is enabled, log SQL here
 * @return executed SQL statement
 */
public SqlStatement drillThroughInternal(int maxRowCount, int firstRowOrdinal, List<OlapElement> fields, boolean extendedContext, Logger logger) {
    if (!canDrillThrough()) {
        throw Util.newError("Cannot do DrillThrough operation on the cell");
    }
    // Generate SQL.
    String sql = getDrillThroughSQL(fields, extendedContext);
    if (logger != null && logger.isDebugEnabled()) {
        logger.debug("drill through sql: " + sql);
    }
    // Choose the appropriate scrollability. If we need to start from an
    // offset row, it is useful that the cursor is scrollable, but not
    // essential.
    final Statement statement = result.getExecution().getMondrianStatement();
    final Execution execution = new Execution(statement, 0);
    final Connection connection = statement.getMondrianConnection();
    int resultSetType = ResultSet.TYPE_SCROLL_INSENSITIVE;
    int resultSetConcurrency = ResultSet.CONCUR_READ_ONLY;
    final Schema schema = statement.getSchema();
    Dialect dialect = ((RolapSchema) schema).getDialect();
    if (!dialect.supportsResultSetConcurrency(resultSetType, resultSetConcurrency) || firstRowOrdinal <= 1) {
        // downgrade to non-scroll cursor, since we can
        // fake absolute() via forward fetch
        resultSetType = ResultSet.TYPE_FORWARD_ONLY;
    }
    return RolapUtil.executeQuery(connection.getDataSource(), sql, null, maxRowCount, firstRowOrdinal, new SqlStatement.StatementLocus(execution, "RolapCell.drillThrough", "Error in drill through", SqlStatementEvent.Purpose.DRILL_THROUGH, 0), resultSetType, resultSetConcurrency, null);
}
Also used : Dialect(mondrian.spi.Dialect)

Example 3 with Dialect

use of mondrian.spi.Dialect in project mondrian by pentaho.

the class DialectTest method testAllowsRegularExpressionInWhereClause.

public void testAllowsRegularExpressionInWhereClause() throws Exception {
    Dialect dialect = getDialect();
    if (dialect.allowsRegularExpressionInWhereClause()) {
        assertNotNull(dialect.generateRegularExpression(dialect.quoteIdentifier("customer", "fname"), "(?i).*\\QJeanne\\E.*"));
        StringBuilder sb = new StringBuilder("select " + dialect.quoteIdentifier("customer", "fname") + " from " + dialectizeTableName(dialect.quoteIdentifier("customer")) + " group by " + dialect.quoteIdentifier("customer", "fname") + " having " + dialect.generateRegularExpression(dialect.quoteIdentifier("customer", "fname"), "(?i).*\\QJeanne\\E.*"));
        final ResultSet resultSet = getConnection().createStatement().executeQuery(sb.toString());
        assertTrue(resultSet.next());
        resultSet.close();
    } else {
        assertNull(dialect.generateRegularExpression("Foo", "(?i).*\\QBar\\E.*"));
    }
}
Also used : Dialect(mondrian.spi.Dialect)

Example 4 with Dialect

use of mondrian.spi.Dialect in project mondrian by pentaho.

the class DialectTest method testMonetDBTypeMapQuirks.

public void testMonetDBTypeMapQuirks() throws SQLException {
    MockResultSetMetadata mockResultSetMeta = new MockResultSetMetadata();
    Dialect monetDbDialect = TestContext.getFakeDialect(Dialect.DatabaseProduct.MONETDB);
    assertTrue("MonetDB dialect NUMERIC with precision =0, scale = 0" + " may be an aggregated decimal, should assume DOUBLE", monetDbDialect.getType(mockResultSetMeta.withColumnType(Types.NUMERIC).withPrecision(0).withScale(0).build(), 0) == SqlStatement.Type.DOUBLE);
}
Also used : Dialect(mondrian.spi.Dialect)

Example 5 with Dialect

use of mondrian.spi.Dialect in project mondrian by pentaho.

the class DialectTest method testDateLiteralString.

public void testDateLiteralString() {
    // verify correct construction of the date literal string.
    // With Oracle this can get interesting, because depending on the
    // driver version the string may be a DATE or a TIMESTAMP.
    // We need to construct a valid date literal in either case.
    // See http://jira.pentaho.com/browse/MONDRIAN-1819 and
    // http://jira.pentaho.com/browse/MONDRIAN-626
    // 
    // verify jdbc dialect - some jdbc drivers return TIMESTAMP too
    // http://jira.pentaho.com/browse/MONDRIAN-2038
    Dialect jdbcDialect = new JdbcDialectImpl();
    StringBuilder buf = new StringBuilder();
    jdbcDialect.quoteDateLiteral(buf, "2003-12-12");
    assertEquals("DATE '2003-12-12'", buf.toString());
    buf = new StringBuilder();
    jdbcDialect.quoteDateLiteral(buf, "2007-01-15 00:00:00.0");
    assertEquals("DATE '2007-01-15'", buf.toString());
    if (getDialect().getDatabaseProduct() != Dialect.DatabaseProduct.ORACLE) {
        // the following test is specifically for Oracle.
        return;
    }
    final TestContext context = TestContext.instance().withSchema("<?xml version=\"1.0\"?>\n" + "<Schema name=\"FoodMart\">\n" + "  <Dimension  name=\"Time\" type=\"TimeDimension\">\n" + "    <Hierarchy hasAll='true' primaryKey=\"time_id\">\n" + "      <Table name=\"time_by_day\"/>\n" + "      <Level name=\"Day\"  type=\"Date\" uniqueMembers=\"true\"\n" + "          levelType=\"TimeYears\">\n" + "        <KeyExpression>\n" + "          <SQL>\n" + "            cast(\"the_date\" as DATE)\n" + "          </SQL>\n" + "        </KeyExpression>\n" + "      </Level>\n" + "    </Hierarchy>\n" + "  </Dimension>\n" + "  <Cube name=\"DateLiteralTest\" defaultMeasure=\"expression\">\n" + "    <Table name=\"sales_fact_1997\" />\n" + "    <DimensionUsage name=\"Time\" source=\"Time\" foreignKey=\"time_id\"/>\n" + "    <Measure name=\"Unit Sales\" column=\"unit_sales\"  aggregator=\"sum\"\n" + "    formatString=\"Standard\" />\n" + "  </Cube>\n" + "</Schema>\n");
    // if date literal is incorrect the following query will give the error
    // ORA-01861: literal does not match format string
    Result result = context.executeQuery("select Time.[All Times].FirstChild on 0 from DateLiteralTest");
    String firstChild = result.getAxes()[0].getPositions().get(0).get(0).getName().toString();
    // the member name may have timestamp info, for example if using
    // Oracle with ojdbc5+.  Make sure it starts w/ the expected date.
    assertTrue(firstChild.startsWith("1997-01-01"));
}
Also used : Dialect(mondrian.spi.Dialect)

Aggregations

Dialect (mondrian.spi.Dialect)53 SqlPattern (mondrian.test.SqlPattern)8 Execution (mondrian.server.Execution)4 Result (mondrian.olap.Result)3 SqlQuery (mondrian.rolap.sql.SqlQuery)3 StatisticsProvider (mondrian.spi.StatisticsProvider)3 DataSource (javax.sql.DataSource)2 Query (mondrian.olap.Query)2 TestContext (mondrian.test.TestContext)2 java.sql (java.sql)1 ArrayList (java.util.ArrayList)1 InitialContext (javax.naming.InitialContext)1 Connection (mondrian.olap.Connection)1 MondrianException (mondrian.olap.MondrianException)1 Util (mondrian.olap.Util)1 RolapCube (mondrian.rolap.RolapCube)1 Column (mondrian.rolap.RolapStar.Column)1 Table (mondrian.rolap.RolapStar.Table)1 ListColumnPredicate (mondrian.rolap.agg.ListColumnPredicate)1 AggStar (mondrian.rolap.aggmatcher.AggStar)1