Search in sources :

Example 46 with Dialect

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

the class DialectTest method testDialectVsDatabaseProduct.

public void testDialectVsDatabaseProduct() throws SQLException {
    final Dialect dialect = getDialect();
    final Dialect.DatabaseProduct databaseProduct = dialect.getDatabaseProduct();
    final DatabaseMetaData databaseMetaData = getConnection().getMetaData();
    switch(databaseProduct) {
        case MARIADB:
            // Dialect has identified that it is MariaDB.
            assertTrue(dialect instanceof MySqlDialect);
            assertFalse(dialect instanceof InfobrightDialect);
            assertTrue(dialect instanceof MariaDBDialect);
            assertFalse(MySqlDialect.isInfobright(databaseMetaData));
            assertEquals("MariaDB", databaseMetaData.getDatabaseProductName());
            break;
        case MYSQL:
            // Dialect has identified that it is MySQL.
            assertTrue(dialect instanceof MySqlDialect);
            assertFalse(dialect instanceof InfobrightDialect);
            assertFalse(MySqlDialect.isInfobright(databaseMetaData));
            assertEquals("MySQL", databaseMetaData.getDatabaseProductName());
            break;
        case HIVE:
            // Dialect has identified that it is Hive.
            assertTrue(dialect instanceof HiveDialect);
            break;
        case INFOBRIGHT:
            // Dialect has identified that it is MySQL.
            assertTrue(dialect instanceof MySqlDialect);
            assertTrue(dialect instanceof InfobrightDialect);
            assertTrue(MySqlDialect.isInfobright(databaseMetaData));
            assertEquals("MySQL", databaseMetaData.getDatabaseProductName());
            break;
        case POSTGRESQL:
            // Dialect has identified that it is PostgreSQL.
            assertTrue(dialect instanceof PostgreSqlDialect);
            assertFalse(dialect instanceof NetezzaDialect);
            assertTrue(databaseMetaData.getDatabaseProductName().indexOf("PostgreSQL") >= 0);
            break;
        case MSSQL:
            // Dialect has identified that it is MSSQL.
            assertTrue(dialect instanceof MicrosoftSqlServerDialect);
            assertTrue(databaseMetaData.getDatabaseProductName().contains("Microsoft"));
            break;
        case NETEZZA:
            // Dialect has identified that it is Netezza and a sub class of
            // PostgreSql.
            assertTrue(dialect instanceof PostgreSqlDialect);
            assertTrue(dialect instanceof NetezzaDialect);
            assertTrue(databaseMetaData.getDatabaseProductName().indexOf("Netezza") >= 0);
            break;
        case NUODB:
            // Dialect has identified that it is NUODB.
            assertTrue(dialect instanceof NuoDbDialect);
            assertTrue(databaseMetaData.getDatabaseProductName().contains("NuoDB"));
            break;
        case GOOGLEBIGQUERY:
            assertTrue(dialect instanceof GoogleBigQueryDialect);
            assertTrue(databaseMetaData.getDatabaseProductName().contains("Google BigQuery"));
            break;
        default:
            // Neither MySQL nor Infobright.
            assertFalse(dialect instanceof MySqlDialect);
            assertFalse(dialect instanceof InfobrightDialect);
            assertNotSame("MySQL", databaseMetaData.getDatabaseProductName());
            break;
    }
}
Also used : Dialect(mondrian.spi.Dialect)

Example 47 with Dialect

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

the class DialectTest method testNetezzaTypeMapQuirks.

public void testNetezzaTypeMapQuirks() throws SQLException {
    MockResultSetMetadata mockResultSetMeta = new MockResultSetMetadata();
    Dialect netezzaDialect = TestContext.getFakeDialect(Dialect.DatabaseProduct.NETEZZA);
    assertTrue("Netezza dialect NUMERIC/DECIMAL with precision =38, scale = 0" + " means long.  Should be mapped to DOUBLE", netezzaDialect.getType(mockResultSetMeta.withColumnType(Types.NUMERIC).withPrecision(38).withScale(0).build(), 0) == SqlStatement.Type.DOUBLE);
    assertTrue("Netezza dialect NUMERIC/DECIMAL with precision =38, scale = 0" + " means long.  Should be mapped to DOUBLE", netezzaDialect.getType(mockResultSetMeta.withColumnType(Types.DECIMAL).withPrecision(38).withScale(0).build(), 0) == SqlStatement.Type.DOUBLE);
}
Also used : Dialect(mondrian.spi.Dialect)

Example 48 with Dialect

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

the class DialectTest method checkForceNullCollation.

/**
 * Checks that the dialect can generate a valid query to sort in a given
 * direction, with NULL values appearing last.
 *
 * @param ascending Whether ascending
 * @param nullsLast Force nulls last or not.
 */
private void checkForceNullCollation(boolean ascending, boolean nullsLast) throws SQLException {
    Dialect dialect = getDialect();
    String query = "select " + dialect.quoteIdentifier("store_manager") + " from " + dialectizeTableName(dialect.quoteIdentifier("store")) + " order by " + dialect.generateOrderItem(dialect.quoteIdentifier("store_manager"), true, ascending, nullsLast);
    if (ascending) {
        if (nullsLast) {
            assertFirstLast(query, "Brown", null);
        } else {
            assertFirstLast(query, null, "Williams");
        }
    } else {
        // Largest value comes first, null comes last.
        switch(dialect.getDatabaseProduct()) {
            case GREENPLUM:
                // Postgres 8.3
                return;
            case HIVE:
                // Hive cannot force nulls to appear last
                return;
            case NEOVIEW:
                // Neoview cannot force nulls to appear last
                return;
        }
        if (nullsLast) {
            assertFirstLast(query, "Williams", null);
        } else {
            assertFirstLast(query, null, "Brown");
        }
    }
}
Also used : Dialect(mondrian.spi.Dialect)

Example 49 with Dialect

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

the class DialectTest method testHiveTimestampQuoteLiteral.

public void testHiveTimestampQuoteLiteral() throws SQLException {
    /*MONDRIAN-2208*/
    Dialect hiveDbDialect = TestContext.getFakeDialect(Dialect.DatabaseProduct.HIVE);
    StringBuilder buf = new StringBuilder();
    hiveDbDialect.quoteTimestampLiteral(buf, "2014-10-29 10:27:55.12");
    assertEquals("TIMESTAMP literal for Hive requires special syntax (cast)", "cast( '2014-10-29 10:27:55.12' as timestamp )", buf.toString());
}
Also used : Dialect(mondrian.spi.Dialect)

Example 50 with Dialect

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

the class DialectTest method testHavingRequiresAlias.

public void testHavingRequiresAlias() throws Exception {
    Dialect dialect = getDialect();
    StringBuilder sb = new StringBuilder("select upper(" + dialect.quoteIdentifier("customer", "fname") + ") as c from " + dialectizeTableName(dialect.quoteIdentifier("customer")) + " group by " + dialect.quoteIdentifier("customer", "fname") + " having " + dialect.quoteIdentifier("customer", "fname") + " LIKE ");
    dialect.quoteStringLiteral(sb, "%");
    if (!dialect.requiresHavingAlias()) {
        final ResultSet resultSet = getConnection().createStatement().executeQuery(sb.toString());
        assertTrue(resultSet.next());
        resultSet.close();
    } else {
        String[] errs = { // mysql
        "Unknown column 'customer\\.fname' in 'having clause'", // vectorwise
        "No conversion defined for result data type\\." };
        assertQueryFails(sb.toString(), errs);
    }
}
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