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 Pentaho
008// All Rights Reserved.
009*/
010package mondrian.spi.impl;
011
012import java.sql.Connection;
013import java.sql.SQLException;
014import java.util.List;
015
016/**
017 * Implementation of {@link mondrian.spi.Dialect} for the Teradata database.
018 *
019 * @author jhyde
020 * @since Nov 23, 2008
021 */
022public class TeradataDialect extends JdbcDialectImpl {
023
024    public static final JdbcDialectFactory FACTORY =
025        new JdbcDialectFactory(
026            TeradataDialect.class,
027            DatabaseProduct.TERADATA);
028
029    /**
030     * Creates a TeradataDialect.
031     *
032     * @param connection Connection
033     */
034    public TeradataDialect(Connection connection) throws SQLException {
035        super(connection);
036    }
037
038    public boolean requiresAliasForFromQuery() {
039        return true;
040    }
041
042    public String generateInline(
043        List<String> columnNames,
044        List<String> columnTypes,
045        List<String[]> valueList)
046    {
047        String fromClause = null;
048        if (valueList.size() > 1) {
049            // In Teradata, "SELECT 1,2" is valid but "SELECT 1,2 UNION
050            // SELECT 3,4" gives "3888: SELECT for a UNION,INTERSECT or
051            // MINUS must reference a table."
052            fromClause = " FROM (SELECT 1 a) z ";
053        }
054        return generateInlineGeneric(
055            columnNames, columnTypes, valueList, fromClause, true);
056    }
057
058    public boolean supportsGroupingSets() {
059        return true;
060    }
061
062    public boolean requiresUnionOrderByOrdinal() {
063        return true;
064    }
065}
066
067// End TeradataDialect.java