Search in sources :

Example 1 with SqlQuery

use of mondrian.rolap.sql.SqlQuery in project mondrian by pentaho.

the class SqlTupleReaderTest method testAddLevelMemberSql.

public void testAddLevelMemberSql() throws Exception {
    TupleConstraint constraint = mock(TupleConstraint.class);
    SqlQuery sqlQuery = mock(SqlQuery.class, Answers.RETURNS_MOCKS.get());
    RolapCube baseCube = mock(RolapCube.class);
    RolapLevel targetLevel = mock(RolapLevel.class);
    RolapCubeLevel levelIter = mock(RolapCubeLevel.class, Answers.RETURNS_MOCKS.get());
    RolapProperty rolapProperty = mock(RolapProperty.class, Answers.RETURNS_MOCKS.get());
    String propertyName = "property_1";
    when(rolapProperty.getName()).thenReturn(propertyName);
    RolapProperty[] properties = { rolapProperty };
    when(levelIter.getProperties()).thenReturn(properties);
    when(levelIter.getKeyExp()).thenReturn(mock(MondrianDef.Expression.class));
    when(levelIter.getOrdinalExp()).thenReturn(mock(MondrianDef.Expression.class));
    when(levelIter.getParentExp()).thenReturn(null);
    RolapHierarchy hierarchy = mock(RolapHierarchy.class, Answers.RETURNS_MOCKS.get());
    when(targetLevel.getHierarchy()).thenReturn(hierarchy);
    when(hierarchy.getLevels()).thenReturn(new RolapLevel[] { levelIter });
    SqlTupleReader.WhichSelect whichSelect = SqlTupleReader.WhichSelect.LAST;
    JdbcSchema.Table dbTable = mock(JdbcSchema.Table.class, Answers.RETURNS_MOCKS.get());
    when(dbTable.getColumnUsages(any())).thenReturn(mock(Iterator.class));
    RolapStar star = mock(RolapStar.class);
    when(star.getColumnCount()).thenReturn(1);
    AggStar aggStar = spy(AggStar.makeAggStar(star, dbTable, mock(MessageRecorder.class), 10));
    AggStar.Table.Column column = mock(AggStar.Table.Column.class, Answers.RETURNS_MOCKS.get());
    doReturn(column).when(aggStar).lookupColumn(0);
    RolapStar.Column starColumn = mock(RolapStar.Column.class, Answers.RETURNS_MOCKS.get());
    when(starColumn.getBitPosition()).thenReturn(0);
    doReturn(starColumn).when(levelIter).getStarKeyColumn();
    AggStar.FactTable factTable = (AggStar.FactTable) createInstance("mondrian.rolap.aggmatcher.AggStar$FactTable", new Class[] { mondrian.rolap.aggmatcher.AggStar.class, JdbcSchema.Table.class }, new Object[] { aggStar, dbTable }, AggStar.FactTable.class.getClassLoader());
    factTable = spy(factTable);
    Map<String, MondrianDef.Expression> propertiesAgg = new HashMap<>();
    propertiesAgg.put(propertyName, mock(MondrianDef.Expression.class));
    Class[] constructorArgsClasses = { mondrian.rolap.aggmatcher.AggStar.Table.class, String.class, MondrianDef.Expression.class, int.class, RolapStar.Column.class, boolean.class, MondrianDef.Expression.class, MondrianDef.Expression.class, Map.class };
    Object[] constructorArgs = { factTable, "name", mock(MondrianDef.Expression.class), 0, starColumn, true, mock(MondrianDef.Expression.class), null, propertiesAgg };
    AggStar.Table.Level aggStarLevel = (AggStar.Table.Level) createInstance("mondrian.rolap.aggmatcher.AggStar$Table$Level", constructorArgsClasses, constructorArgs, AggStar.Table.Level.class.getClassLoader());
    when(aggStar.lookupLevel(0)).thenReturn(aggStarLevel);
    doReturn(factTable).when(column).getTable();
    SqlTupleReader reader = new SqlTupleReader(constraint);
    reader.addLevelMemberSql(sqlQuery, targetLevel, baseCube, whichSelect, aggStar);
    verify(factTable).addToFrom(any(), eq(false), eq(true));
}
Also used : HashMap(java.util.HashMap) Iterator(java.util.Iterator) AggStar(mondrian.rolap.aggmatcher.AggStar) SqlQuery(mondrian.rolap.sql.SqlQuery) JdbcSchema(mondrian.rolap.aggmatcher.JdbcSchema) TupleConstraint(mondrian.rolap.sql.TupleConstraint) MondrianDef(mondrian.olap.MondrianDef)

Example 2 with SqlQuery

use of mondrian.rolap.sql.SqlQuery in project mondrian by pentaho.

the class CompoundPredicateInfo method getPredicateString.

/**
 * Returns a string representation of the predicate
 */
public static String getPredicateString(RolapStar star, StarPredicate predicate) {
    if (star == null || predicate == null) {
        return null;
    }
    final StringBuilder buf = new StringBuilder();
    SqlQuery query = new SqlQuery(star.getSqlQueryDialect());
    buf.setLength(0);
    predicate.toSql(query, buf);
    return buf.toString();
}
Also used : SqlQuery(mondrian.rolap.sql.SqlQuery)

Example 3 with SqlQuery

use of mondrian.rolap.sql.SqlQuery in project mondrian by pentaho.

the class DialectTest method testMondrian2253.

public void testMondrian2253() throws SQLException {
    String expected = "    1 ASC";
    // "1" is supposed to be a column number
    String expr = "1";
    JdbcDialectImpl dialect = new VectorwiseDialect(getConnection());
    SqlQuery query = new SqlQuery(dialect, true);
    query.addOrderBy(expr, null, true, false, dialect.requiresUnionOrderByOrdinal(), true);
    assertTrue(query.toString().contains(expected));
}
Also used : SqlQuery(mondrian.rolap.sql.SqlQuery)

Example 4 with SqlQuery

use of mondrian.rolap.sql.SqlQuery in project mondrian by pentaho.

the class AbstractQuerySpec method generateSqlQuery.

public Pair<String, List<SqlStatement.Type>> generateSqlQuery() {
    SqlQuery sqlQuery = newSqlQuery();
    int k = getDistinctMeasureCount();
    final Dialect dialect = sqlQuery.getDialect();
    final Map<String, String> groupingSetsAliases;
    if (!dialect.allowsCountDistinct() && k > 0 || !dialect.allowsMultipleCountDistinct() && k > 1) {
        groupingSetsAliases = distinctGenerateSql(sqlQuery, countOnly);
    } else {
        groupingSetsAliases = nonDistinctGenerateSql(sqlQuery);
    }
    if (!countOnly) {
        addGroupingFunction(sqlQuery);
        addGroupingSets(sqlQuery, groupingSetsAliases);
    }
    return sqlQuery.toSqlAndTypes();
}
Also used : SqlQuery(mondrian.rolap.sql.SqlQuery) Dialect(mondrian.spi.Dialect)

Example 5 with SqlQuery

use of mondrian.rolap.sql.SqlQuery in project mondrian by pentaho.

the class DrillThroughQuerySpec method generateSqlQuery.

public Pair<String, List<SqlStatement.Type>> generateSqlQuery() {
    SqlQuery sqlQuery = newSqlQuery();
    nonDistinctGenerateSql(sqlQuery);
    appendInapplicableFields(sqlQuery);
    return sqlQuery.toSqlAndTypes();
}
Also used : SqlQuery(mondrian.rolap.sql.SqlQuery)

Aggregations

SqlQuery (mondrian.rolap.sql.SqlQuery)16 MondrianDef (mondrian.olap.MondrianDef)3 Dialect (mondrian.spi.Dialect)3 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 RolapAggregator (mondrian.rolap.RolapAggregator)2 AggStar (mondrian.rolap.aggmatcher.AggStar)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 RolapStar (mondrian.rolap.RolapStar)1 Column (mondrian.rolap.RolapStar.Column)1 Table (mondrian.rolap.RolapStar.Table)1 JdbcSchema (mondrian.rolap.aggmatcher.JdbcSchema)1 TupleConstraint (mondrian.rolap.sql.TupleConstraint)1 UnmodifiableArrayList (org.olap4j.impl.UnmodifiableArrayList)1