use of mondrian.rolap.agg.CellRequest in project mondrian by pentaho.
the class GroupingSetQueryTest method testGroupingSetForMultipleColumnConstraint.
public void testGroupingSetForMultipleColumnConstraint() {
if (prop.ReadAggregates.get() && prop.UseAggregates.get()) {
return;
}
propSaver.set(prop.EnableGroupingSets, true);
CellRequest request1 = createRequest(cubeNameSales2, measureUnitSales, new String[] { tableCustomer, tableTime }, new String[] { fieldGender, fieldYear }, new String[] { "M", "1997" });
CellRequest request2 = createRequest(cubeNameSales2, measureUnitSales, new String[] { tableCustomer, tableTime }, new String[] { fieldGender, fieldYear }, new String[] { "F", "1997" });
CellRequest request3 = createRequest(cubeNameSales2, measureUnitSales, tableTime, fieldYear, "1997");
SqlPattern[] patternsWithGsets = { new SqlPattern(ORACLE_TERADATA, "select \"time_by_day\".\"the_year\" as \"c0\", \"customer\".\"gender\" as \"c1\", " + "sum(\"sales_fact_1997\".\"unit_sales\") as \"m0\", grouping(\"customer\".\"gender\") as \"g0\" " + "from \"time_by_day\" =as= \"time_by_day\", \"sales_fact_1997\" =as= \"sales_fact_1997\", \"customer\" =as= \"customer\" " + "where \"sales_fact_1997\".\"time_id\" = \"time_by_day\".\"time_id\" and \"time_by_day\".\"the_year\" = 1997 " + "and \"sales_fact_1997\".\"customer_id\" = \"customer\".\"customer_id\" " + "group by grouping sets ((\"time_by_day\".\"the_year\", \"customer\".\"gender\"), (\"time_by_day\".\"the_year\"))", 150) };
// Sometimes this query causes Oracle 10.2 XE to give
// ORA-12516, TNS:listener could not find available handler with
// matching protocol stack
//
// You need to configure Oracle:
// $ su - oracle
// $ sqlplus / as sysdba
// SQL> ALTER SYSTEM SET sessions=320 SCOPE=SPFILE;
// SQL> SHUTDOWN
assertRequestSql(new CellRequest[] { request3, request1, request2 }, patternsWithGsets);
propSaver.set(prop.EnableGroupingSets, false);
SqlPattern[] patternsWithoutGsets = { new SqlPattern(Dialect.DatabaseProduct.ACCESS, "select \"time_by_day\".\"the_year\" as \"c0\", \"customer\".\"gender\" as \"c1\", " + "sum(\"sales_fact_1997\".\"unit_sales\") as \"m0\" " + "from \"time_by_day\" as \"time_by_day\", \"sales_fact_1997\" as \"sales_fact_1997\", " + "\"customer\" as \"customer\" " + "where \"sales_fact_1997\".\"time_id\" = \"time_by_day\".\"time_id\" and " + "\"time_by_day\".\"the_year\" = 1997 and " + "\"sales_fact_1997\".\"customer_id\" = \"customer\".\"customer_id\" " + "group by \"time_by_day\".\"the_year\", \"customer\".\"gender\"", 50), new SqlPattern(ORACLE_TERADATA, "select \"time_by_day\".\"the_year\" as \"c0\", \"customer\".\"gender\" as \"c1\", " + "sum(\"sales_fact_1997\".\"unit_sales\") as \"m0\" " + "from \"time_by_day\" =as= \"time_by_day\", \"sales_fact_1997\" =as= \"sales_fact_1997\", " + "\"customer\" =as= \"customer\" " + "where \"sales_fact_1997\".\"time_id\" = \"time_by_day\".\"time_id\" and " + "\"time_by_day\".\"the_year\" = 1997 " + "and \"sales_fact_1997\".\"customer_id\" = \"customer\".\"customer_id\" " + "group by \"time_by_day\".\"the_year\", \"customer\".\"gender\"", 50) };
assertRequestSql(new CellRequest[] { request3, request1, request2 }, patternsWithoutGsets);
}
use of mondrian.rolap.agg.CellRequest in project mondrian by pentaho.
the class GroupingSetQueryTest method testNotUsingGroupingSetWhenGroupUsesDifferentAggregateTable.
public void testNotUsingGroupingSetWhenGroupUsesDifferentAggregateTable() {
if (!(prop.UseAggregates.get() && prop.ReadAggregates.get())) {
return;
}
CellRequest request1 = createRequest(cubeNameSales, measureUnitSales, tableCustomer, fieldGender, "M");
CellRequest request2 = createRequest(cubeNameSales, measureUnitSales, tableCustomer, fieldGender, "F");
CellRequest request3 = createRequest(cubeNameSales, measureUnitSales, null, "", "");
propSaver.set(prop.EnableGroupingSets, true);
SqlPattern[] patternsWithoutGsets = { new SqlPattern(Dialect.DatabaseProduct.ACCESS, "select \"agg_g_ms_pcat_sales_fact_1997\".\"gender\" as \"c0\", " + "sum(\"agg_g_ms_pcat_sales_fact_1997\".\"unit_sales\") as \"m0\" " + "from \"agg_g_ms_pcat_sales_fact_1997\" as \"agg_g_ms_pcat_sales_fact_1997\" " + "group by \"agg_g_ms_pcat_sales_fact_1997\".\"gender\"", 26), new SqlPattern(ORACLE_TERADATA, "select \"agg_g_ms_pcat_sales_fact_1997\".\"gender\" as \"c0\", " + "sum(\"agg_g_ms_pcat_sales_fact_1997\".\"unit_sales\") as \"m0\" " + "from \"agg_g_ms_pcat_sales_fact_1997\" \"agg_g_ms_pcat_sales_fact_1997\" " + "group by \"agg_g_ms_pcat_sales_fact_1997\".\"gender\"", 26) };
assertRequestSql(new CellRequest[] { request3, request1, request2 }, patternsWithoutGsets);
}
use of mondrian.rolap.agg.CellRequest in project mondrian by pentaho.
the class GroupingSetQueryTest method testGroupingSetForMultipleMeasureAndSingleConstraint.
public void testGroupingSetForMultipleMeasureAndSingleConstraint() {
if (prop.ReadAggregates.get() && prop.UseAggregates.get()) {
return;
}
propSaver.set(prop.EnableGroupingSets, true);
CellRequest request1 = createRequest(cubeNameSales2, measureUnitSales, tableCustomer, fieldGender, "M");
CellRequest request2 = createRequest(cubeNameSales2, measureUnitSales, tableCustomer, fieldGender, "F");
CellRequest request3 = createRequest(cubeNameSales2, measureUnitSales, null, "", "");
CellRequest request4 = createRequest(cubeNameSales2, measureStoreSales, tableCustomer, fieldGender, "M");
CellRequest request5 = createRequest(cubeNameSales2, measureStoreSales, tableCustomer, fieldGender, "F");
CellRequest request6 = createRequest(cubeNameSales2, measureStoreSales, null, "", "");
SqlPattern[] patternsWithGsets = { new SqlPattern(ORACLE_TERADATA, "select \"customer\".\"gender\" as \"c0\", sum(\"sales_fact_1997\".\"unit_sales\") as \"m0\", " + "sum(\"sales_fact_1997\".\"store_sales\") as \"m1\", grouping(\"customer\".\"gender\") as \"g0\" " + "from \"customer\" =as= \"customer\", \"sales_fact_1997\" =as= \"sales_fact_1997\" " + "where \"sales_fact_1997\".\"customer_id\" = \"customer\".\"customer_id\" " + "group by grouping sets ((\"customer\".\"gender\"), ())", 26) };
assertRequestSql(new CellRequest[] { request1, request2, request3, request4, request5, request6 }, patternsWithGsets);
propSaver.set(prop.EnableGroupingSets, false);
SqlPattern[] patternsWithoutGsets = { new SqlPattern(Dialect.DatabaseProduct.ACCESS, "select \"customer\".\"gender\" as \"c0\", sum(\"sales_fact_1997\".\"unit_sales\") as \"m0\", " + "sum(\"sales_fact_1997\".\"store_sales\") as \"m1\" " + "from \"customer\" as \"customer\", \"sales_fact_1997\" as \"sales_fact_1997\" " + "where \"sales_fact_1997\".\"customer_id\" = \"customer\".\"customer_id\" " + "group by \"customer\".\"gender\"", 26), new SqlPattern(ORACLE_TERADATA, "select \"customer\".\"gender\" as \"c0\", sum(\"sales_fact_1997\".\"unit_sales\") as \"m0\", " + "sum(\"sales_fact_1997\".\"store_sales\") as \"m1\" " + "from \"customer\" =as= \"customer\", \"sales_fact_1997\" =as= \"sales_fact_1997\" " + "where \"sales_fact_1997\".\"customer_id\" = \"customer\".\"customer_id\" " + "group by \"customer\".\"gender\"", 26) };
assertRequestSql(new CellRequest[] { request1, request2, request3, request4, request5, request6 }, patternsWithoutGsets);
}
use of mondrian.rolap.agg.CellRequest in project mondrian by pentaho.
the class SqlTupleReader method chooseAggStar.
/**
* Obtains the AggStar instance which corresponds to an aggregate table
* which can be used to support the member constraint.
*
* @param constraint The tuple constraint to apply.
* @param evaluator the current evaluator to obtain the cube and members to
* be queried @return AggStar for aggregate table
* @param baseCube The base cube from which to choose an aggregation star.
* Can be null, in which case we use the evaluator's cube.
*/
AggStar chooseAggStar(TupleConstraint constraint, Evaluator evaluator, RolapCube baseCube) {
if (!MondrianProperties.instance().UseAggregates.get()) {
return null;
}
if (evaluator == null || !constraint.supportsAggTables()) {
return null;
}
if (baseCube == null) {
baseCube = (RolapCube) evaluator.getCube();
}
// Current cannot support aggregate tables for virtual cubes
if (baseCube.isVirtual()) {
return null;
}
RolapStar star = baseCube.getStar();
final int starColumnCount = star.getColumnCount();
BitKey measureBitKey = BitKey.Factory.makeBitKey(starColumnCount);
BitKey levelBitKey = BitKey.Factory.makeBitKey(starColumnCount);
// Convert global ordinal to cube based ordinal (the 0th dimension
// is always [Measures]). In the case of filter constraint this will
// be the measure on which the filter will be done.
// Since we support aggregated members as arguments, we'll expand
// this too.
// Failing to do so could result in chosing the wrong aggstar, as the
// level would not be passed to the bitkeys
final Member[] members = SqlConstraintUtils.expandSupportedCalculatedMembers(Arrays.asList(evaluator.getNonAllMembers()), evaluator).getMembersArray();
// if measure is calculated, we can't continue
if (!(members[0] instanceof RolapBaseCubeMeasure)) {
return null;
}
RolapBaseCubeMeasure measure = (RolapBaseCubeMeasure) members[0];
int bitPosition = ((RolapStar.Measure) measure.getStarMeasure()).getBitPosition();
// set a bit for each level which is constrained in the context
final CellRequest request = RolapAggregationManager.makeRequest(members);
if (request == null) {
// One or more calculated members. Cannot use agg table.
return null;
}
// TODO: RME why is this using the array of constrained columns
// from the CellRequest rather than just the constrained columns
// BitKey (method getConstrainedColumnsBitKey)?
RolapStar.Column[] columns = request.getConstrainedColumns();
for (RolapStar.Column column1 : columns) {
levelBitKey.set(column1.getBitPosition());
}
// set the masks
for (TargetBase target : targets) {
RolapLevel level = target.level;
if (!level.isAll()) {
RolapStar.Column column = ((RolapCubeLevel) level).getBaseStarKeyColumn(baseCube);
if (column != null) {
levelBitKey.set(column.getBitPosition());
}
}
}
// Set the bits for limited rollup members
RolapUtil.constraintBitkeyForLimitedMembers(evaluator, evaluator.getMembers(), baseCube, levelBitKey);
measureBitKey.set(bitPosition);
if (constraint instanceof RolapNativeCrossJoin.NonEmptyCrossJoinConstraint) {
// Cannot evaluate NonEmptyCrossJoinConstraint using an agg
// table if one of its args is a DescendantsConstraint.
RolapNativeCrossJoin.NonEmptyCrossJoinConstraint necj = (RolapNativeCrossJoin.NonEmptyCrossJoinConstraint) constraint;
for (CrossJoinArg arg : necj.args) {
if (arg instanceof DescendantsCrossJoinArg || arg instanceof MemberListCrossJoinArg) {
final RolapLevel level = arg.getLevel();
if (level != null && !level.isAll()) {
RolapStar.Column column = ((RolapCubeLevel) level).getBaseStarKeyColumn(baseCube);
if (column == null) {
// target group.
continue;
}
// with name columns in agg table is not supported
if (arg instanceof MemberListCrossJoinArg) {
if (level.getNameExp() != null && !Util.equals(level.getNameExp(), level.getKeyExp())) {
LOGGER.warn("" + "Member constraint" + " is not supported with name column in agg table");
return null;
}
}
levelBitKey.set(column.getBitPosition());
}
}
}
} else if (constraint instanceof RolapNativeFilter.FilterConstraint) {
for (Member slicer : ((RolapEvaluator) evaluator).getSlicerMembers()) {
final Level level = slicer.getLevel();
if (level != null && !level.isAll()) {
final RolapStar.Column column = ((RolapCubeLevel) level).getBaseStarKeyColumn(baseCube);
levelBitKey.set(column.getBitPosition());
}
}
}
// find the aggstar using the masks
return AggregationManager.findAgg(star, levelBitKey, measureBitKey, new boolean[] { false });
}
use of mondrian.rolap.agg.CellRequest in project mondrian by pentaho.
the class SqlMemberSource method chooseAggStar.
private static AggStar chooseAggStar(MemberChildrenConstraint constraint, RolapMember member) {
if (!MondrianProperties.instance().UseAggregates.get() || !(constraint instanceof SqlContextConstraint)) {
return null;
}
SqlContextConstraint contextConstraint = (SqlContextConstraint) constraint;
Evaluator evaluator = contextConstraint.getEvaluator();
RolapCube cube = (RolapCube) evaluator.getCube();
RolapStar star = cube.getStar();
final int starColumnCount = star.getColumnCount();
BitKey measureBitKey = BitKey.Factory.makeBitKey(starColumnCount);
BitKey levelBitKey = BitKey.Factory.makeBitKey(starColumnCount);
// Convert global ordinal to cube based ordinal (the 0th dimension
// is always [Measures])
// Expand calculated so we don't miss their bitkeys
final Member[] members = SqlConstraintUtils.expandSupportedCalculatedMembers(Arrays.asList(evaluator.getNonAllMembers()), evaluator).getMembersArray();
// if measure is calculated, we can't continue
if (!(members[0] instanceof RolapBaseCubeMeasure)) {
return null;
}
RolapBaseCubeMeasure measure = (RolapBaseCubeMeasure) members[0];
// we need to do more than this! we need the rolap star ordinal, not
// the rolap cube
int bitPosition = ((RolapStar.Measure) measure.getStarMeasure()).getBitPosition();
// childLevel will always end up being a RolapCubeLevel, but the API
// calls into this method can be both shared RolapMembers and
// RolapCubeMembers so this cast is necessary for now. Also note that
// this method will never be called in the context of a virtual cube
// so baseCube isn't necessary for retrieving the correct column
// get the level using the current depth
RolapCubeLevel childLevel = (RolapCubeLevel) member.getLevel().getChildLevel();
RolapStar.Column column = childLevel.getStarKeyColumn();
// set a bit for each level which is constrained in the context
final CellRequest request = RolapAggregationManager.makeRequest(members);
if (request == null) {
// One or more calculated members. Cannot use agg table.
return null;
}
// TODO: RME why is this using the array of constrained columns
// from the CellRequest rather than just the constrained columns
// BitKey (method getConstrainedColumnsBitKey)?
RolapStar.Column[] columns = request.getConstrainedColumns();
for (RolapStar.Column column1 : columns) {
levelBitKey.set(column1.getBitPosition());
}
// set the masks
levelBitKey.set(column.getBitPosition());
measureBitKey.set(bitPosition);
// Set the bits for limited rollup members
RolapUtil.constraintBitkeyForLimitedMembers(evaluator, members, cube, levelBitKey);
// find the aggstar using the masks
return AggregationManager.findAgg(star, levelBitKey, measureBitKey, new boolean[] { false });
}
Aggregations