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;
}
}
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);
}
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");
}
}
}
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());
}
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);
}
}
Aggregations