Package mondrian.spi

Examples of mondrian.spi.Dialect


            assertQueryFails(sb.toString(), errs);
        }
    }

    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 "
                    + 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.*"));
        }
    }
View Full Code Here


     * are in the middle of the regexp.
     */
    public void testComplexRegularExpression() throws Exception {
        final String regexp =
            "(?i).*\\QJeanne\\E.*|.*\\QSheri\\E.*|.*\\QJonathan\\E.*|.*\\QJewel\\E.*";
        Dialect dialect = getDialect();
        if (dialect.allowsRegularExpressionInWhereClause()) {
            assertNotNull(
                dialect.generateRegularExpression(
                    dialect.quoteIdentifier("customer", "fname"),
                    regexp));
            StringBuilder sb =
                new StringBuilder(
                    "select "
                    + dialect.quoteIdentifier("customer", "fname")
                    + " from "
                    + dialect.quoteIdentifier("customer")
                    + " group by "
                    + dialect.quoteIdentifier("customer", "fname")
                    + " having "
                    + dialect.generateRegularExpression(
                        dialect.quoteIdentifier("customer", "fname"),
                        regexp));
            final ResultSet resultSet =
                getConnection().createStatement().executeQuery(sb.toString());
            int i = 0;
            while (resultSet.next()) {
                i++;
            }
            assertEquals(7, i);
            resultSet.close();
        } else {
            assertNull(
                dialect.generateRegularExpression(
                    "Foo",
                    "(?i).*\\QBar\\E.*"));
        }
    }
View Full Code Here

     * @param regex Java regular expression string
     * @return Whether dialect could translate regex to SQL.
     * @throws SQLException on error
     */
    private boolean checkRegex(String regex) throws SQLException {
        Dialect dialect = getDialect();
        final String sqlRegex =
            dialect.generateRegularExpression(
                dialect.quoteIdentifier("customer", "fname"),
                regex);
        if (sqlRegex != null) {
            String sql =
                "select * from "
                + dialect.quoteIdentifier("customer")
                + " where "
                + sqlRegex;
            final ResultSet resultSet =
                getConnection().createStatement().executeQuery(sql);
            assertFalse(resultSet.next());
View Full Code Here

        }
    }

    public void testOracleTypeMapQuirks() throws SQLException {
        MockResultSetMetadata mockResultSetMeta = new MockResultSetMetadata();
        Dialect oracleDialect = new OracleDialect();

        assertTrue(
            "Oracle dialect NUMERIC type with 0 precision, 0 scale should map "
            + "to INT, unless column starts with 'm'",
            oracleDialect.getType(
                mockResultSetMeta.withColumnName("c0")
                    .withColumnType(Types.NUMERIC)
                    .withPrecision(0)
                    .withScale(0)
                    .build(),
                0) == SqlStatement.Type.INT);

        assertTrue(
            "Oracle dialect NUMERIC type with non-zero precision, -127 scale "
            + " should map to DOUBLE.  MONDRIAN-1044",
            oracleDialect.getType(
                mockResultSetMeta.withColumnName("c0")
                    .withColumnType(Types.NUMERIC)
                    .withPrecision(5)
                    .withScale(-127)
                    .build(),
                0) == SqlStatement.Type.DOUBLE);
        assertTrue(
            "Oracle dialect NUMERIC type with precision less than 10, 0 scale "
            + " should map to INT. ",
            oracleDialect.getType(
                mockResultSetMeta.withColumnName("c0")
                    .withColumnType(Types.NUMERIC)
                    .withPrecision(9)
                    .withScale(0)
                    .build(),
                0) == SqlStatement.Type.INT);
        assertTrue(
            "Oracle dialect NUMERIC type with precision = 38, scale = 0"
            + " should map to INT.  38 is a magic number in Oracle "
            + " for integers of unspecified precision.",
            oracleDialect.getType(
                mockResultSetMeta.withColumnName("c0")
                    .withColumnType(Types.NUMERIC)
                    .withPrecision(38)
                    .withScale(0)
                    .build(),
                0) == SqlStatement.Type.INT);
        assertTrue(
            "Oracle dialect DECIMAL type with precision > 9, scale = 0"
            + " should map to DOUBLE (unless magic #38)",
            oracleDialect.getType(
                mockResultSetMeta.withColumnName("c0")
                    .withColumnType(Types.NUMERIC)
                    .withPrecision(20)
                    .withScale(0)
                    .build(),
                0) == SqlStatement.Type.DOUBLE);

        assertTrue(
            "Oracle dialect NUMBER type with precision =0 , scale = -127"
            + " should map to INT.  GROUPING SETS queries can shift"
            + " scale for columns to -127, whether INT or other NUMERIC."
            + " Assume INT unless the column name indicates it is a measure.",
            oracleDialect.getType(
                mockResultSetMeta.withColumnName("c0")
                    .withColumnType(Types.NUMERIC)
                    .withPrecision(0)
                    .withScale(-127)
                    .build(),
                0) == SqlStatement.Type.INT);
        assertTrue(
            "Oracle dialect NUMBER type with precision =0 , scale = -127"
            + " should map to OBJECT if measure name starts with 'm'",
            oracleDialect.getType(
                mockResultSetMeta.withColumnName("m0")
                    .withColumnType(Types.NUMERIC)
                    .withPrecision(0)
                    .withScale(-127)
                    .build(),
View Full Code Here

                0) == SqlStatement.Type.OBJECT);
    }

    public void testPostgresGreenplumTypeMapQuirks() throws SQLException {
        MockResultSetMetadata mockResultSetMeta = new MockResultSetMetadata();
        Dialect greenplumDialect =
            TestContext.getFakeDialect(Dialect.DatabaseProduct.GREENPLUM);
        assertTrue(
            "Postgres/Greenplum dialect NUMBER with precision =0, scale = 0"
            + ", measure name starts with 'm' maps to OBJECT",
            greenplumDialect.getType(
                mockResultSetMeta.withColumnName("m0")
                    .withColumnType(Types.NUMERIC)
                    .withPrecision(0)
                    .withScale(0)
                    .build(),
View Full Code Here

                0) == SqlStatement.Type.OBJECT);
    }

    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(),
View Full Code Here

                0) == SqlStatement.Type.DOUBLE);
    }

    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(),
View Full Code Here

                0) == SqlStatement.Type.DOUBLE);
    }

    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(),
View Full Code Here

        assertEquals(SqlStatement.Type.OBJECT, type);
    }

    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());
    }
View Full Code Here

    public Dialect getDialect() {
        return dialect;
    }

    public static SqlQuery newQuery(DataSource dataSource, String err) {
        final Dialect dialect =
            DialectManager.createDialect(dataSource, null);
        return new SqlQuery(dialect);
    }
View Full Code Here

TOP

Related Classes of mondrian.spi.Dialect

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.