Package mondrian.spi

Examples of mondrian.spi.Dialect


                continue;
            }

            // some DB2 (AS400) versions throw an error, if a column alias is
            // there and *not* used in a subsequent order by/group by
            final Dialect dialect = sqlQuery.getDialect();
            final String alias;
            final Dialect.DatabaseProduct databaseProduct =
                dialect.getDatabaseProduct();
            if (databaseProduct == Dialect.DatabaseProduct.DB2_AS400) {
                alias = sqlQuery.addSelect(expr, null);
            } else {
                alias = sqlQuery.addSelect(expr, getColumnAlias(i));
            }
View Full Code Here


    public String generateSqlQuery() {
        SqlQuery sqlQuery = newSqlQuery();

        int k = getDistinctMeasureCount();
        final Dialect dialect = sqlQuery.getDialect();
        if (!dialect.allowsCountDistinct() && k > 0
            || !dialect.allowsMultipleCountDistinct() && k > 1)
        {
            distinctGenerateSql(sqlQuery, countOnly);
        } else {
            nonDistinctGenerateSql(sqlQuery);
        }
View Full Code Here

     */
    protected void distinctGenerateSql(
        final SqlQuery outerSqlQuery,
        boolean countOnly)
    {
        final Dialect dialect = outerSqlQuery.getDialect();
        final Dialect.DatabaseProduct databaseProduct =
            dialect.getDatabaseProduct();
        // Generate something like
        //
        //  select d0, d1, count(m0)
        //  from (
        //    select distinct dim1.x as d0, dim2.y as d1, f.z as m0
        //    from f, dim1, dim2
        //    where dim1.k = f.k1
        //    and dim2.k = f.k2) as dummyname
        //  group by d0, d1
        //
        // or, if countOnly=true
        //
        //  select count(m0)
        //  from (
        //    select distinct f.z as m0
        //    from f, dim1, dim2
        //    where dim1.k = f.k1
        //    and dim2.k = f.k2) as dummyname

        final SqlQuery innerSqlQuery = newSqlQuery();
        if (databaseProduct == Dialect.DatabaseProduct.GREENPLUM) {
            innerSqlQuery.setDistinct(false);
        } else {
            innerSqlQuery.setDistinct(true);
        }
        // add constraining dimensions
        RolapStar.Column[] columns = getColumns();
        int arity = columns.length;
        for (int i = 0; i < arity; i++) {
            RolapStar.Column column = columns[i];
            RolapStar.Table table = column.getTable();
            if (table.isFunky()) {
                // this is a funky dimension -- ignore for now
                continue;
            }
            table.addToFrom(innerSqlQuery, false, true);
            String expr = column.generateExprString(innerSqlQuery);
            StarColumnPredicate predicate = getColumnPredicate(i);
            final String where = RolapStar.Column.createInExpr(
                expr,
                predicate,
                column.getDatatype(),
                innerSqlQuery);
            if (!where.equals("true")) {
                innerSqlQuery.addWhere(where);
            }
            if (countOnly) {
                continue;
            }
            final String alias = "d" + i;
            innerSqlQuery.addSelect(expr, alias);
            if (databaseProduct == Dialect.DatabaseProduct.GREENPLUM) {
                innerSqlQuery.addGroupBy(expr, alias);
            }
            final String quotedAlias = dialect.quoteIdentifier(alias);
            outerSqlQuery.addSelectGroupBy(quotedAlias);
        }

        // add predicates not associated with columns
        extraPredicates(innerSqlQuery);

        // add measures
        for (int i = 0, count = getMeasureCount(); i < count; i++) {
            RolapStar.Measure measure = getMeasure(i);

            Util.assertTrue(measure.getTable() == getStar().getFactTable());
            measure.getTable().addToFrom(innerSqlQuery, false, true);

            String alias = getMeasureAlias(i);
            String expr = measure.generateExprString(outerSqlQuery);
            innerSqlQuery.addSelect(expr, alias);
            if (databaseProduct == Dialect.DatabaseProduct.GREENPLUM) {
                innerSqlQuery.addGroupBy(expr, alias);
            }
            outerSqlQuery.addSelect(
                measure.getAggregator().getNonDistinctAggregator()
                    .getExpression(
                    dialect.quoteIdentifier(alias)));
        }
        outerSqlQuery.addFrom(innerSqlQuery, "dummyname", true);
    }
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

        // essential.
        final Connection connection = result.getQuery().getConnection();
        int resultSetType = ResultSet.TYPE_SCROLL_INSENSITIVE;
        int resultSetConcurrency = ResultSet.CONCUR_READ_ONLY;
        final Schema schema = connection.getSchema();
        Dialect dialect = ((RolapSchema) schema).getDialect();
        if (!dialect.supportsResultSetConcurrency(
            resultSetType, resultSetConcurrency)
            || firstRowOrdinal <= 1)
        {
            // downgrade to non-scroll cursor, since we can
            // fake absolute() via forward fetch
View Full Code Here

            Map<String, List<String>> tableFieldMap =
                new HashMap<String, List<String>>();
            for (MondrianDef.Relation relation1 : relationList) {
                final String tableName = relation1.toString();
                List<String> fieldNameList = new ArrayList<String>();
                Dialect dialect =
                    ((RolapSchema) connection.getSchema()).getDialect();
                // FIXME: Include schema name, if specified.
                // FIXME: Deal with relations that are not tables.
                final StringBuilder buf = new StringBuilder();
                buf.append("SELECT * FROM ");
                dialect.quoteIdentifier(buf, tableName);
                buf.append(" WHERE 1=2");
                String sql = buf.toString();
                ResultSet rs = stmt.executeQuery(sql);
                ResultSetMetaData rsMeta = rs.getMetaData();
                for (int j = 1; j <= rsMeta.getColumnCount(); j++) {
View Full Code Here

                // DataSource.getConnection does not return null. But
                // a null value here would cause infinite recursion, so
                // let's be cautious.
                throw new IllegalArgumentException();
            }
            final Dialect dialect =
                factory.createDialect(dataSource, connection);

            // Close the connection in such a way that if there is a
            // SQLException,
            // (a) we propagate the exception,
View Full Code Here

            // the members are requested; whether we should get just the cells
            // requested or expand to a n-cube

            // If the database cannot execute "count(distinct ...)", split the
            // distinct aggregations out.
            final Dialect dialect = getDialect();

            int distinctMeasureCount = getDistinctMeasureCount(measuresList);
            boolean tooManyDistinctMeasures =
                distinctMeasureCount > 0
                && !dialect.allowsCountDistinct()
                || distinctMeasureCount > 1
                   && !dialect.allowsMultipleCountDistinct();

            if (tooManyDistinctMeasures) {
                doSpecialHandlingOfDistinctCountMeasures(
                    aggmgr, predicates, groupingSetsCollector);
            }

            // Load agg(distinct <SQL expression>) measures individually
            // for DBs that does allow multiple distinct SQL measures.
            if (!dialect.allowsMultipleDistinctSqlMeasures()) {
                // Note that the intention was orignially to capture the
                // subquery SQL measures and separate them out; However,
                // without parsing the SQL string, Mondrian cannot distinguish
                // between "col1" + "col2" and subquery. Here the measure list
                // contains both types.
View Full Code Here

            AggStar aggStar)
        {
            if (orderByExpr != null) {
                RolapNativeSql sql = new RolapNativeSql(sqlQuery, aggStar);
                String orderBySql = sql.generateTopCountOrderBy(orderByExpr);
                Dialect dialect = sqlQuery.getDialect();
                boolean nullable = deduceNullability(orderByExpr);
                if (dialect.requiresOrderByAlias()) {
                    String alias = sqlQuery.nextColumnAlias();
                    alias = dialect.quoteIdentifier(alias);
                    sqlQuery.addSelect(orderBySql, alias);
                    sqlQuery.addOrderBy(alias, ascending, true, nullable);
                } else {
                    sqlQuery.addOrderBy(orderBySql, ascending, true, nullable);
                }
View Full Code Here

            // a union, so the order by columns need to be numbers,
            // not column name strings or expressions.
            switch (whichSelect) {
            case LAST:
                boolean nullable = true;
                final Dialect dialect = sqlQuery.getDialect();
                if (dialect.requiresUnionOrderByExprToBeInSelectClause()
                    || dialect.requiresUnionOrderByOrdinal())
                {
                    // If the expression is nullable and the dialect
                    // sorts NULL values first, the dialect will try to
                    // add an expression 'Iif(expr IS NULL, 1, 0)' into
                    // the ORDER BY clause, and that is not allowed by this
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.