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));
}
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();
}
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));
}
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();
}
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();
}
Aggregations