Search in sources :

Example 1 with MemberExpr

use of mondrian.mdx.MemberExpr in project mondrian by pentaho.

the class SqlConstraintUtilsTest method testIsSupportedExpressionForCalculatedMember.

// ~ Test methods ----------------------------------------------------------
public void testIsSupportedExpressionForCalculatedMember() {
    Assert.assertEquals("null expression", false, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(null));
    Exp memberExpr = new MemberExpr(Mockito.mock(Member.class));
    Assert.assertEquals("MemberExpr", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(memberExpr));
    Exp nullFunDefExpr = new ResolvedFunCall(new NullFunDef(), new Exp[] {}, new NullType());
    Assert.assertEquals("ResolvedFunCall-NullFunDef", false, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(nullFunDefExpr));
    // ResolvedFunCall arguments
    final Exp argUnsupported = new ResolvedFunCall(new NullFunDef(), new Exp[] {}, new NullType());
    final Exp argSupported = new MemberExpr(Mockito.mock(Member.class));
    Assert.assertEquals(false, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(argUnsupported));
    Assert.assertEquals(true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(argSupported));
    final Exp[] noArgs = new Exp[] {};
    final Exp[] args1Unsupported = new Exp[] { argUnsupported };
    final Exp[] args1Supported = new Exp[] { argSupported };
    final Exp[] args2Different = new Exp[] { argUnsupported, argSupported };
    final ParenthesesFunDef parenthesesFunDef = new ParenthesesFunDef(Category.Member);
    Type parenthesesReturnType = new DecimalType(1, 1);
    Exp parenthesesExpr = new ResolvedFunCall(parenthesesFunDef, noArgs, parenthesesReturnType);
    Assert.assertEquals("ResolvedFunCall-Parentheses()", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(parenthesesExpr));
    parenthesesExpr = new ResolvedFunCall(parenthesesFunDef, args1Unsupported, parenthesesReturnType);
    Assert.assertEquals("ResolvedFunCall-Parentheses(N)", false, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(parenthesesExpr));
    parenthesesExpr = new ResolvedFunCall(parenthesesFunDef, args1Supported, parenthesesReturnType);
    Assert.assertEquals("ResolvedFunCall-Parentheses(Y)", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(parenthesesExpr));
    parenthesesExpr = new ResolvedFunCall(parenthesesFunDef, args2Different, parenthesesReturnType);
    Assert.assertEquals("ResolvedFunCall-Parentheses(N,Y)", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(parenthesesExpr));
    FunDef dummy = Mockito.mock(FunDef.class);
    Mockito.doReturn(Syntax.Function).when(dummy).getSyntax();
    Mockito.doReturn("dummy").when(dummy).getName();
    FunDef aggregateFunDef = new AggregateFunDef(dummy);
    Type aggregateReturnType = new DecimalType(1, 1);
    Exp aggregateExpr = new ResolvedFunCall(aggregateFunDef, noArgs, aggregateReturnType);
    Assert.assertEquals("ResolvedFunCall-Aggregate()", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(aggregateExpr));
    aggregateExpr = new ResolvedFunCall(aggregateFunDef, args1Unsupported, aggregateReturnType);
    Assert.assertEquals("ResolvedFunCall-Aggregate(N)", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(aggregateExpr));
    aggregateExpr = new ResolvedFunCall(aggregateFunDef, args1Supported, aggregateReturnType);
    Assert.assertEquals("ResolvedFunCall-Aggregate(Y)", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(aggregateExpr));
    aggregateExpr = new ResolvedFunCall(aggregateFunDef, args2Different, aggregateReturnType);
    Assert.assertEquals("ResolvedFunCall-Aggregate(N,Y)", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(aggregateExpr));
}
Also used : FunDef(mondrian.olap.FunDef) ParenthesesFunDef(mondrian.olap.fun.ParenthesesFunDef) AggregateFunDef(mondrian.olap.fun.AggregateFunDef) NullFunDef(mondrian.olap.fun.CrossJoinTest.NullFunDef) NullType(mondrian.olap.type.NullType) DecimalType(mondrian.olap.type.DecimalType) TupleType(mondrian.olap.type.TupleType) Type(mondrian.olap.type.Type) NullFunDef(mondrian.olap.fun.CrossJoinTest.NullFunDef) MemberExpr(mondrian.mdx.MemberExpr) ParenthesesFunDef(mondrian.olap.fun.ParenthesesFunDef) DecimalType(mondrian.olap.type.DecimalType) ResolvedFunCall(mondrian.mdx.ResolvedFunCall) AggregateFunDef(mondrian.olap.fun.AggregateFunDef) NullType(mondrian.olap.type.NullType) Exp(mondrian.olap.Exp) Member(mondrian.olap.Member) TestMember(mondrian.olap.fun.TestMember)

Example 2 with MemberExpr

use of mondrian.mdx.MemberExpr in project mondrian by pentaho.

the class SqlConstraintUtilsTest method testExpandSupportedCalculatedMembers2.

// test with a placeholder member
public void testExpandSupportedCalculatedMembers2() {
    final TestContext testContext = TestContext.instance();
    final Connection connection = testContext.getConnection();
    final String queryText = "SELECT {[Measures].[Customer Count]} ON 0 " + "FROM [Sales] " + "WHERE [Time].[1997]";
    final Query query = connection.parseQuery(queryText);
    final QueryAxis querySlicerAxis = query.getSlicerAxis();
    final Member slicerMember = ((MemberExpr) querySlicerAxis.getSet()).getMember();
    final RolapHierarchy slicerHierarchy = ((RolapCube) query.getCube()).getTimeHierarchy(null);
    final Execution execution = new Execution(query.getStatement(), 0L);
    final RolapEvaluatorRoot rolapEvaluatorRoot = new RolapEvaluatorRoot(execution);
    final RolapEvaluator rolapEvaluator = new RolapEvaluator(rolapEvaluatorRoot);
    final Member expectedMember = slicerMember;
    rolapEvaluator.setSlicerContext(expectedMember);
    RolapResult.CompoundSlicerRolapMember placeHolderMember = Mockito.mock(RolapResult.CompoundSlicerRolapMember.class);
    Mockito.doReturn(slicerHierarchy).when(placeHolderMember).getHierarchy();
    Member endMember0 = makeNoncalculatedMember("0");
    // (0, placeholder)
    Member[] argMembers = new Member[] { endMember0, placeHolderMember };
    Member[] expectedMembers = new Member[] { endMember0, slicerMember };
    Member[] expectedMembersOnDisjoin = new Member[] { endMember0 };
    assertApartExpandSupportedCalculatedMembers("(0, placeholder)", expectedMembers, expectedMembersOnDisjoin, argMembers, rolapEvaluator);
}
Also used : Query(mondrian.olap.Query) TestContext(mondrian.test.TestContext) Connection(mondrian.olap.Connection) Execution(mondrian.server.Execution) MemberExpr(mondrian.mdx.MemberExpr) Member(mondrian.olap.Member) TestMember(mondrian.olap.fun.TestMember) QueryAxis(mondrian.olap.QueryAxis)

Example 3 with MemberExpr

use of mondrian.mdx.MemberExpr in project mondrian by pentaho.

the class SqlConstraintUtilsTest method makeParenthesesExprMember.

private Member makeParenthesesExprMember(Evaluator evaluator, Member parenthesesInnerMember, String toString) {
    Member member = Mockito.mock(Member.class);
    Mockito.doReturn("mock[" + toString + "]").when(member).toString();
    Mockito.doReturn(true).when(member).isCalculated();
    Exp parenthesesArg = new MemberExpr(parenthesesInnerMember);
    FunDef funDef = new ParenthesesFunDef(Category.Member);
    Exp[] args = new Exp[] { parenthesesArg };
    Type returnType = new DecimalType(1, 1);
    Exp memberExp = new ResolvedFunCall(funDef, args, returnType);
    Mockito.doReturn(memberExp).when(member).getExpression();
    Assert.assertEquals(true, member.isCalculated());
    Assert.assertEquals(true, SqlConstraintUtils.isSupportedCalculatedMember(member));
    return member;
}
Also used : FunDef(mondrian.olap.FunDef) ParenthesesFunDef(mondrian.olap.fun.ParenthesesFunDef) AggregateFunDef(mondrian.olap.fun.AggregateFunDef) NullFunDef(mondrian.olap.fun.CrossJoinTest.NullFunDef) NullType(mondrian.olap.type.NullType) DecimalType(mondrian.olap.type.DecimalType) TupleType(mondrian.olap.type.TupleType) Type(mondrian.olap.type.Type) MemberExpr(mondrian.mdx.MemberExpr) ParenthesesFunDef(mondrian.olap.fun.ParenthesesFunDef) DecimalType(mondrian.olap.type.DecimalType) ResolvedFunCall(mondrian.mdx.ResolvedFunCall) Exp(mondrian.olap.Exp) Member(mondrian.olap.Member) TestMember(mondrian.olap.fun.TestMember)

Example 4 with MemberExpr

use of mondrian.mdx.MemberExpr in project mondrian by pentaho.

the class SqlConstraintUtilsTest method makeMemberExprMember.

private Member makeMemberExprMember(Member resultMember) {
    Exp memberExp = new MemberExpr(resultMember);
    Member member = Mockito.mock(Member.class);
    Mockito.doReturn(true).when(member).isCalculated();
    Mockito.doReturn(memberExp).when(member).getExpression();
    return member;
}
Also used : MemberExpr(mondrian.mdx.MemberExpr) Exp(mondrian.olap.Exp) Member(mondrian.olap.Member) TestMember(mondrian.olap.fun.TestMember)

Example 5 with MemberExpr

use of mondrian.mdx.MemberExpr in project mondrian by pentaho.

the class SqlConstraintUtilsTest method testReplaceCompoundSlicerPlaceholder.

public void testReplaceCompoundSlicerPlaceholder() {
    final TestContext testContext = TestContext.instance();
    final Connection connection = testContext.getConnection();
    final String queryText = "SELECT {[Measures].[Customer Count]} ON 0 " + "FROM [Sales] " + "WHERE [Time].[1997]";
    final Query query = connection.parseQuery(queryText);
    final QueryAxis querySlicerAxis = query.getSlicerAxis();
    final Member slicerMember = ((MemberExpr) querySlicerAxis.getSet()).getMember();
    final RolapHierarchy slicerHierarchy = ((RolapCube) query.getCube()).getTimeHierarchy(null);
    final Execution execution = new Execution(query.getStatement(), 0L);
    final RolapEvaluatorRoot rolapEvaluatorRoot = new RolapEvaluatorRoot(execution);
    final RolapEvaluator rolapEvaluator = new RolapEvaluator(rolapEvaluatorRoot);
    final Member expectedMember = slicerMember;
    rolapEvaluator.setSlicerContext(expectedMember);
    RolapResult.CompoundSlicerRolapMember placeHolderMember = Mockito.mock(RolapResult.CompoundSlicerRolapMember.class);
    Mockito.doReturn(slicerHierarchy).when(placeHolderMember).getHierarchy();
    // tested call
    Member r = SqlConstraintUtils.replaceCompoundSlicerPlaceholder(placeHolderMember, rolapEvaluator);
    // test
    Assert.assertSame(expectedMember, r);
}
Also used : Query(mondrian.olap.Query) TestContext(mondrian.test.TestContext) Connection(mondrian.olap.Connection) Execution(mondrian.server.Execution) MemberExpr(mondrian.mdx.MemberExpr) Member(mondrian.olap.Member) TestMember(mondrian.olap.fun.TestMember) QueryAxis(mondrian.olap.QueryAxis)

Aggregations

MemberExpr (mondrian.mdx.MemberExpr)8 Member (mondrian.olap.Member)7 TestMember (mondrian.olap.fun.TestMember)7 Exp (mondrian.olap.Exp)5 ResolvedFunCall (mondrian.mdx.ResolvedFunCall)4 FunDef (mondrian.olap.FunDef)3 AggregateFunDef (mondrian.olap.fun.AggregateFunDef)3 NullFunDef (mondrian.olap.fun.CrossJoinTest.NullFunDef)3 ParenthesesFunDef (mondrian.olap.fun.ParenthesesFunDef)3 DecimalType (mondrian.olap.type.DecimalType)3 NullType (mondrian.olap.type.NullType)3 TupleType (mondrian.olap.type.TupleType)3 Type (mondrian.olap.type.Type)3 Connection (mondrian.olap.Connection)2 Query (mondrian.olap.Query)2 QueryAxis (mondrian.olap.QueryAxis)2 Execution (mondrian.server.Execution)2 TestContext (mondrian.test.TestContext)2 UnaryTupleList (mondrian.calc.impl.UnaryTupleList)1 SetEvaluator (mondrian.olap.Evaluator.SetEvaluator)1