Class AbstractQuerySpec

  • All Implemented Interfaces:
    QuerySpec

    public abstract class AbstractQuerySpec
    extends Object
    implements QuerySpec
    Base class for QuerySpec implementations.
    Author:
    jhyde, Richard M. Emberson
    • Field Detail

      • countOnly

        protected final boolean countOnly
    • Constructor Detail

      • AbstractQuerySpec

        protected AbstractQuerySpec​(RolapStar star,
                                    boolean countOnly)
        Creates an AbstractQuerySpec.
        Parameters:
        star - Star which defines columns of interest and their relationships
        countOnly - If true, generate no GROUP BY clause, so the query returns a single row containing a grand total
    • Method Detail

      • newSqlQuery

        protected SqlQuery newSqlQuery()
        Creates a query object.
        Returns:
        a new query object
      • addMeasure

        protected void addMeasure​(int i,
                                  SqlQuery sqlQuery)
        Adds a measure to a query.
        Parameters:
        i - Ordinal of measure
        sqlQuery - Query object
      • isAggregate

        protected abstract boolean isAggregate()
      • isPartOfSelect

        protected boolean isPartOfSelect​(RolapStar.Column col)
        Allows subclasses to specify if a given column must be returned as part of the result set, in the select clause.
      • isPartOfSelect

        protected boolean isPartOfSelect​(RolapStar.Measure measure)
        Allows subclasses to specify if a given column must be returned as part of the result set, in the select clause.
      • isOrdered

        protected boolean isOrdered()
        Whether to add an ORDER BY clause to make results deterministic. Necessary if query returns more than one row and results are for human consumption.
        Returns:
        whether to sort query
      • addGroupingFunction

        protected void addGroupingFunction​(SqlQuery sqlQuery)
      • addGroupingSets

        protected void addGroupingSets​(SqlQuery sqlQuery,
                                       Map<String,​String> groupingSetsAliases)
      • getDistinctMeasureCount

        protected int getDistinctMeasureCount()
        Returns the number of measures whose aggregation function is distinct-count.
        Returns:
        Number of distinct-count measures
      • distinctGenerateSql

        protected Map<String,​String> distinctGenerateSql​(SqlQuery outerSqlQuery,
                                                               boolean countOnly)
        Generates a SQL query to retrieve the values in this segment using an algorithm which converts distinct-aggregates to non-distinct aggregates over subqueries.
        Parameters:
        outerSqlQuery - Query to modify
        countOnly - If true, only generate a single row: no need to generate a GROUP BY clause or put any constraining columns in the SELECT clause
        Returns:
        A map of aliases used in the inner query if grouping sets were enabled.
      • extraPredicates

        protected void extraPredicates​(SqlQuery sqlQuery)
        Adds predicates not associated with columns.
        Parameters:
        sqlQuery - Query
      • getPredicateList

        protected List<StarPredicate> getPredicateList()
        Returns a list of predicates not associated with a particular column.
        Returns:
        list of non-column predicates