001/*
002// This software is subject to the terms of the Eclipse Public License v1.0
003// Agreement, available at the following URL:
004// http://www.eclipse.org/legal/epl-v10.html.
005// You must accept the terms of that agreement to use this software.
006//
007// Copyright (C) 2008-2009 Millersoft
008// Copyright (C) 2011-2013 Pentaho and others
009// All Rights Reserved.
010*/
011package mondrian.spi.impl;
012
013import java.sql.Connection;
014import java.sql.SQLException;
015
016/**
017 * Implementation of {@link mondrian.spi.Dialect} for the GreenplumSQL database.
018 *
019 * @author Millersoft
020 * @since Dec 23, 2009
021 */
022public class GreenplumDialect extends PostgreSqlDialect {
023
024    /**
025     * Creates a GreenplumDialect.
026     *
027     * @param connection Connection
028     */
029    public GreenplumDialect(Connection connection) throws SQLException {
030        super(connection);
031    }
032
033
034    public static final JdbcDialectFactory FACTORY =
035        new JdbcDialectFactory(
036            GreenplumDialect.class,
037            // While we're choosing dialects, this still looks like a Postgres
038            // connection.
039            DatabaseProduct.POSTGRESQL)
040        {
041            protected boolean acceptsConnection(Connection connection) {
042                return super.acceptsConnection(connection)
043                   && isDatabase(DatabaseProduct.GREENPLUM, connection);
044            }
045        };
046
047    public boolean supportsGroupingSets() {
048        return true;
049    }
050
051    public boolean requiresGroupByAlias() {
052        return true;
053    }
054
055    public boolean requiresAliasForFromQuery() {
056        return false;
057    }
058
059    public boolean allowsCountDistinct() {
060        return true;
061    }
062
063    public boolean allowsFromQuery() {
064        return false;
065    }
066
067    public DatabaseProduct getDatabaseProduct() {
068        return DatabaseProduct.GREENPLUM;
069    }
070
071    public String generateCountExpression(String exp) {
072        return caseWhenElse(exp + " ISNULL", "'0'", "TEXT(" + exp + ")");
073    }
074
075    public boolean allowsRegularExpressionInWhereClause() {
076        // Support for regexp was added in GP 3.2+
077        if (productVersion.compareTo("3.2") >= 0) {
078            return true;
079        } else {
080            return false;
081        }
082    }
083}
084
085// End GreenplumDialect.java