Search in sources :

Example 1 with JdbcDialectImpl

use of mondrian.spi.impl.JdbcDialectImpl 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 : GoogleBigQueryDialect(mondrian.spi.impl.GoogleBigQueryDialect) MicrosoftSqlServerDialect(mondrian.spi.impl.MicrosoftSqlServerDialect) MonetDbDialect(mondrian.spi.impl.MonetDbDialect) HiveDialect(mondrian.spi.impl.HiveDialect) InfobrightDialect(mondrian.spi.impl.InfobrightDialect) Dialect(mondrian.spi.Dialect) PostgreSqlDialect(mondrian.spi.impl.PostgreSqlDialect) NetezzaDialect(mondrian.spi.impl.NetezzaDialect) MariaDBDialect(mondrian.spi.impl.MariaDBDialect) OracleDialect(mondrian.spi.impl.OracleDialect) MySqlDialect(mondrian.spi.impl.MySqlDialect) VectorwiseDialect(mondrian.spi.impl.VectorwiseDialect) NuoDbDialect(mondrian.spi.impl.NuoDbDialect) JdbcDialectImpl(mondrian.spi.impl.JdbcDialectImpl) Result(mondrian.olap.Result)

Example 2 with JdbcDialectImpl

use of mondrian.spi.impl.JdbcDialectImpl in project mondrian by pentaho.

the class DialectTest method testMondrian2253.

public void testMondrian2253() throws SQLException {
    String expected = "    1 ASC";
    // "1" is supposed to be a column number
    String expr = "1";
    JdbcDialectImpl dialect = new VectorwiseDialect(getConnection());
    SqlQuery query = new SqlQuery(dialect, true);
    query.addOrderBy(expr, null, true, false, dialect.requiresUnionOrderByOrdinal(), true);
    assertTrue(query.toString().contains(expected));
}
Also used : SqlQuery(mondrian.rolap.sql.SqlQuery) JdbcDialectImpl(mondrian.spi.impl.JdbcDialectImpl) VectorwiseDialect(mondrian.spi.impl.VectorwiseDialect)

Example 3 with JdbcDialectImpl

use of mondrian.spi.impl.JdbcDialectImpl in project mondrian by pentaho.

the class DialectTest method testJdbcDialectTypeMap.

public void testJdbcDialectTypeMap() throws SQLException {
    MockResultSetMetadata mockResultSetMeta = new MockResultSetMetadata();
    Dialect postgresDialect = new JdbcDialectImpl();
    assertTrue("JdbcDialectImpl NUMERIC/DECIMAL types w/ precision 0-9" + " and scale=0 should return INT", postgresDialect.getType(mockResultSetMeta.withColumnType(Types.NUMERIC).withPrecision(5).withScale(0).build(), 0) == SqlStatement.Type.INT);
    assertTrue("JdbcDialectImpl NUMERIC/DECIMAL types w/ precision 0-9" + " and scale=0 should return INT", postgresDialect.getType(mockResultSetMeta.withColumnType(Types.DECIMAL).withPrecision(5).withScale(0).build(), 0) == SqlStatement.Type.INT);
}
Also used : GoogleBigQueryDialect(mondrian.spi.impl.GoogleBigQueryDialect) MicrosoftSqlServerDialect(mondrian.spi.impl.MicrosoftSqlServerDialect) MonetDbDialect(mondrian.spi.impl.MonetDbDialect) HiveDialect(mondrian.spi.impl.HiveDialect) InfobrightDialect(mondrian.spi.impl.InfobrightDialect) Dialect(mondrian.spi.Dialect) PostgreSqlDialect(mondrian.spi.impl.PostgreSqlDialect) NetezzaDialect(mondrian.spi.impl.NetezzaDialect) MariaDBDialect(mondrian.spi.impl.MariaDBDialect) OracleDialect(mondrian.spi.impl.OracleDialect) MySqlDialect(mondrian.spi.impl.MySqlDialect) VectorwiseDialect(mondrian.spi.impl.VectorwiseDialect) NuoDbDialect(mondrian.spi.impl.NuoDbDialect) JdbcDialectImpl(mondrian.spi.impl.JdbcDialectImpl)

Aggregations

JdbcDialectImpl (mondrian.spi.impl.JdbcDialectImpl)3 VectorwiseDialect (mondrian.spi.impl.VectorwiseDialect)3 Dialect (mondrian.spi.Dialect)2 GoogleBigQueryDialect (mondrian.spi.impl.GoogleBigQueryDialect)2 HiveDialect (mondrian.spi.impl.HiveDialect)2 InfobrightDialect (mondrian.spi.impl.InfobrightDialect)2 MariaDBDialect (mondrian.spi.impl.MariaDBDialect)2 MicrosoftSqlServerDialect (mondrian.spi.impl.MicrosoftSqlServerDialect)2 MonetDbDialect (mondrian.spi.impl.MonetDbDialect)2 MySqlDialect (mondrian.spi.impl.MySqlDialect)2 NetezzaDialect (mondrian.spi.impl.NetezzaDialect)2 NuoDbDialect (mondrian.spi.impl.NuoDbDialect)2 OracleDialect (mondrian.spi.impl.OracleDialect)2 PostgreSqlDialect (mondrian.spi.impl.PostgreSqlDialect)2 Result (mondrian.olap.Result)1 SqlQuery (mondrian.rolap.sql.SqlQuery)1