Search in sources :

Example 41 with Result

use of mondrian.olap.Result in project mondrian by pentaho.

the class NonEmptyTest method testLevelMembersWithoutNonEmpty.

public void testLevelMembersWithoutNonEmpty() {
    SmartMemberReader smr = getSmartMemberReader("Customers");
    MemberCacheHelper smrch = ((RolapCubeHierarchy.CacheRolapCubeHierarchyMemberReader) smr).rolapCubeCacheHelper;
    clearAndHardenCache(smrch);
    MemberCacheHelper smrich = smr.cacheHelper;
    clearAndHardenCache(smrich);
    SmartMemberReader ssmr = getSharedSmartMemberReader("Customers");
    MemberCacheHelper ssmrch = ssmr.cacheHelper;
    clearAndHardenCache(ssmrch);
    Result r = executeQuery("select \n" + "{[Measures].[Unit Sales]} ON columns,\n" + "{[Customers].[All Customers], [Customers].[Name].Members} ON rows\n" + "from [Sales]\n" + "where ([Store].[All Stores].[USA].[CA].[San Francisco].[Store 14], [Time].[1997].[Q1].[1])");
    Level[] levels = smr.getHierarchy().getLevels();
    Level nameLevel = levels[levels.length - 1];
    // evaluator for [All Customers], [Store 14], [1/1/1997]
    Evaluator context = getEvaluator(r, new int[] { 0, 0 });
    // make sure that [Customers].[Name].Members IS in cache
    TupleConstraint lmc = scf.getLevelMembersConstraint(null);
    List<RolapMember> list = smrch.mapLevelToMembers.get((RolapLevel) nameLevel, lmc);
    if (MondrianProperties.instance().EnableRolapCubeMemberCache.get()) {
        assertNotNull(list);
        assertEquals(10281, list.size());
    }
    // make sure that NON EMPTY [Customers].[Name].Members is NOT in cache
    context.setNonEmpty(true);
    lmc = scf.getLevelMembersConstraint(context);
    assertNull(smrch.mapLevelToMembers.get((RolapLevel) nameLevel, lmc));
    // make sure that the parent/child for the context are cached
    // [Customers].[Canada].[BC].[Burnaby]
    Member member = r.getAxes()[1].getPositions().get(1).get(0);
    Member parent = member.getParentMember();
    parent = ((RolapCubeMember) parent).getRolapMember();
    member = ((RolapCubeMember) member).getRolapMember();
    // lookup all children of [Burnaby] -> yes, found in cache
    MemberChildrenConstraint mcc = scf.getMemberChildrenConstraint(null);
    list = ssmrch.mapMemberToChildren.get((RolapMember) parent, mcc);
    assertNotNull(list);
    assertTrue(list.contains(member));
    // lookup NON EMPTY children of [Burlingame] -> not in cache
    mcc = scf.getMemberChildrenConstraint(context);
    list = ssmrch.mapMemberToChildren.get((RolapMember) parent, mcc);
    assertNull(list);
}
Also used : Evaluator(mondrian.olap.Evaluator) NonEmptyResult(mondrian.rolap.RolapConnection.NonEmptyResult) Result(mondrian.olap.Result) TupleConstraint(mondrian.rolap.sql.TupleConstraint) MemberChildrenConstraint(mondrian.rolap.sql.MemberChildrenConstraint) Level(mondrian.olap.Level) Member(mondrian.olap.Member)

Example 42 with Result

use of mondrian.olap.Result in project mondrian by pentaho.

the class RolapResultTest method testD1.

public void testD1() throws Exception {
    if (!isApplicable()) {
        return;
    }
    String mdx = "select " + " filter({[D1].[a],[D1].[b],[D1].[c]}, " + "    [Measures].[Value] > 0) " + " ON COLUMNS, " + " {[D2].[x],[D2].[y],[D2].[z]} " + " ON ROWS " + "from FT1";
    // getCubeTestContext().assertQueryReturns(mdx, RESULTS);
    Result result = getTestContext().executeQuery(mdx);
    String resultString = TestContext.toString(result);
    // System.out.println(resultString);
    /*
 This is what is produced
Axis #0:
{}
Axis #1:
Axis #2:
{[D2].[x]}
{[D2].[y]}
{[D2].[z]}
*/
    assertEquals(resultString, RESULTS);
}
Also used : Result(mondrian.olap.Result)

Example 43 with Result

use of mondrian.olap.Result in project mondrian by pentaho.

the class RolapConnectionTest method testDataSourceOverrideUserPass.

public void testDataSourceOverrideUserPass() throws SQLException, NamingException {
    // use the datasource property to connect to the database
    Util.PropertyList properties = spy(TestContext.instance().getConnectionProperties().clone());
    final Dialect dialect = TestContext.instance().getDialect();
    if (dialect.getDatabaseProduct() == Dialect.DatabaseProduct.ACCESS) {
        // Access doesn't accept user/password, so this test is pointless.
        return;
    }
    final String jdbcUser = properties.get(RolapConnectionProperties.JdbcUser.name());
    final String jdbcPassword = properties.get(RolapConnectionProperties.JdbcPassword.name());
    if (jdbcUser == null || jdbcPassword == null) {
        // Can only run this test if username and password are explicit.
        return;
    }
    // Define a data source with bogus user and password.
    properties.put(RolapConnectionProperties.JdbcUser.name(), "bogususer");
    properties.put(RolapConnectionProperties.JdbcPassword.name(), "boguspassword");
    properties.put(RolapConnectionProperties.PoolNeeded.name(), "false");
    final StringBuilder buf = new StringBuilder();
    final DataSource dataSource = RolapConnection.createDataSource(null, properties, buf);
    final String desc = buf.toString();
    assertTrue(desc, desc.startsWith("Jdbc="));
    assertTrue(desc, desc.indexOf("JdbcUser=bogususer") >= 0);
    verify(properties, atLeastOnce()).get(RolapConnectionProperties.JdbcPassword.name());
    final String jndiName = "jndiDataSource";
    THREAD_INITIAL_CONTEXT.set(new InitialContext() {

        public Object lookup(String str) {
            return str.equals(jndiName) ? dataSource : null;
        }
    });
    // Create a property list that we will use for the actual mondrian
    // connection. Replace the original JDBC info with the data source we
    // just created.
    final Util.PropertyList properties2 = new Util.PropertyList();
    for (Pair<String, String> entry : properties) {
        properties2.put(entry.getKey(), entry.getValue());
    }
    properties2.remove(RolapConnectionProperties.Jdbc.name());
    properties2.put(RolapConnectionProperties.DataSource.name(), jndiName);
    // With JdbcUser and JdbcPassword credentials in the mondrian connect
    // string, the data source's "user" and "password" properties are
    // overridden and the connection succeeds.
    properties2.put(RolapConnectionProperties.JdbcUser.name(), jdbcUser);
    properties2.put(RolapConnectionProperties.JdbcPassword.name(), jdbcPassword);
    mondrian.olap.Connection connection = null;
    try {
        connection = DriverManager.getConnection(properties2, null);
        Query query = connection.parseQuery("select from [Sales]");
        final Result result = connection.execute(query);
        assertNotNull(result);
    } finally {
        if (connection != null) {
            connection.close();
            connection = null;
        }
    }
    // If we don't specify JdbcUser and JdbcPassword in the mondrian
    // connection properties, mondrian uses the data source's
    // bogus credentials, and the connection fails.
    properties2.remove(RolapConnectionProperties.JdbcUser.name());
    properties2.remove(RolapConnectionProperties.JdbcPassword.name());
    for (String poolNeeded : Arrays.asList("false", "true")) {
        // Important to test with & without pooling. Connection pools
        // typically do not let you change user, so it's important that
        // mondrian handles these right.
        properties2.put(RolapConnectionProperties.PoolNeeded.name(), poolNeeded);
        try {
            connection = DriverManager.getConnection(properties2, null);
            fail("Expected exception");
        } catch (MondrianException e) {
            final String s = TestContext.getStackTrace(e);
            assertTrue(s, s.indexOf("Error while creating SQL connection: " + "DataSource=jndiDataSource") >= 0);
            switch(dialect.getDatabaseProduct()) {
                case DERBY:
                    assertTrue(s, s.indexOf("Caused by: java.sql.SQLException: " + "Schema 'BOGUSUSER' does not exist") >= 0);
                    break;
                case ORACLE:
                    assertTrue(s, s.indexOf("Caused by: java.sql.SQLException: ORA-01017: " + "invalid username/password; logon denied") >= 0);
                    break;
                case MYSQL:
                case MARIADB:
                    assertTrue(s, s.indexOf("Caused by: java.sql.SQLException: Access denied " + "for user 'bogususer'") >= 0);
                    break;
                case POSTGRESQL:
                    assertTrue(s, s.indexOf("Caused by: org.postgresql.util.PSQLException: " + "FATAL: password authentication failed for " + "user \"bogususer\"") >= 0);
                    break;
            }
        } finally {
            if (connection != null) {
                connection.close();
                connection = null;
            }
        }
    }
}
Also used : Query(mondrian.olap.Query) Util(mondrian.olap.Util) InitialContext(javax.naming.InitialContext) DataSource(javax.sql.DataSource) Result(mondrian.olap.Result) Dialect(mondrian.spi.Dialect) MondrianException(mondrian.olap.MondrianException)

Example 44 with Result

use of mondrian.olap.Result in project mondrian by pentaho.

the class DialectTest method testDateLiteralString.

public void testDateLiteralString() {
    // verify correct construction of the date literal string.
    // With Oracle this can get interesting, because depending on the
    // driver version the string may be a DATE or a TIMESTAMP.
    // We need to construct a valid date literal in either case.
    // See http://jira.pentaho.com/browse/MONDRIAN-1819 and
    // http://jira.pentaho.com/browse/MONDRIAN-626
    // 
    // verify jdbc dialect - some jdbc drivers return TIMESTAMP too
    // http://jira.pentaho.com/browse/MONDRIAN-2038
    Dialect jdbcDialect = new JdbcDialectImpl();
    StringBuilder buf = new StringBuilder();
    jdbcDialect.quoteDateLiteral(buf, "2003-12-12");
    assertEquals("DATE '2003-12-12'", buf.toString());
    buf = new StringBuilder();
    jdbcDialect.quoteDateLiteral(buf, "2007-01-15 00:00:00.0");
    assertEquals("DATE '2007-01-15'", buf.toString());
    if (getDialect().getDatabaseProduct() != Dialect.DatabaseProduct.ORACLE) {
        // the following test is specifically for Oracle.
        return;
    }
    final TestContext context = TestContext.instance().withSchema("<?xml version=\"1.0\"?>\n" + "<Schema name=\"FoodMart\">\n" + "  <Dimension  name=\"Time\" type=\"TimeDimension\">\n" + "    <Hierarchy hasAll='true' primaryKey=\"time_id\">\n" + "      <Table name=\"time_by_day\"/>\n" + "      <Level name=\"Day\"  type=\"Date\" uniqueMembers=\"true\"\n" + "          levelType=\"TimeYears\">\n" + "        <KeyExpression>\n" + "          <SQL>\n" + "            cast(\"the_date\" as DATE)\n" + "          </SQL>\n" + "        </KeyExpression>\n" + "      </Level>\n" + "    </Hierarchy>\n" + "  </Dimension>\n" + "  <Cube name=\"DateLiteralTest\" defaultMeasure=\"expression\">\n" + "    <Table name=\"sales_fact_1997\" />\n" + "    <DimensionUsage name=\"Time\" source=\"Time\" foreignKey=\"time_id\"/>\n" + "    <Measure name=\"Unit Sales\" column=\"unit_sales\"  aggregator=\"sum\"\n" + "    formatString=\"Standard\" />\n" + "  </Cube>\n" + "</Schema>\n");
    // if date literal is incorrect the following query will give the error
    // ORA-01861: literal does not match format string
    Result result = context.executeQuery("select Time.[All Times].FirstChild on 0 from DateLiteralTest");
    String firstChild = result.getAxes()[0].getPositions().get(0).get(0).getName().toString();
    // the member name may have timestamp info, for example if using
    // Oracle with ojdbc5+.  Make sure it starts w/ the expected date.
    assertTrue(firstChild.startsWith("1997-01-01"));
}
Also used : GoogleBigQueryDialect(mondrian.spi.impl.GoogleBigQueryDialect) MicrosoftSqlServerDialect(mondrian.spi.impl.MicrosoftSqlServerDialect) MonetDbDialect(mondrian.spi.impl.MonetDbDialect) HiveDialect(mondrian.spi.impl.HiveDialect) InfobrightDialect(mondrian.spi.impl.InfobrightDialect) Dialect(mondrian.spi.Dialect) PostgreSqlDialect(mondrian.spi.impl.PostgreSqlDialect) NetezzaDialect(mondrian.spi.impl.NetezzaDialect) MariaDBDialect(mondrian.spi.impl.MariaDBDialect) OracleDialect(mondrian.spi.impl.OracleDialect) MySqlDialect(mondrian.spi.impl.MySqlDialect) VectorwiseDialect(mondrian.spi.impl.VectorwiseDialect) NuoDbDialect(mondrian.spi.impl.NuoDbDialect) JdbcDialectImpl(mondrian.spi.impl.JdbcDialectImpl) Result(mondrian.olap.Result)

Example 45 with Result

use of mondrian.olap.Result in project mondrian by pentaho.

the class DialectTest method testBigInt.

public void testBigInt() {
    if (getDialect().getDatabaseProduct() != Dialect.DatabaseProduct.VERTICA) {
        // Oracle and MySQL as well.
        return;
    }
    final TestContext context = TestContext.instance().withSchema("<?xml version=\"1.0\"?>\n" + "<Schema name=\"FoodMart\">\n" + "  <Dimension name=\"StoreSqft\">\n" + "    <Hierarchy hasAll=\"true\" primaryKey=\"store_id\">\n" + "      <Table name=\"store\"  />\n" + "      <Level name=\"StoreSqft\"  type=\"Numeric\" uniqueMembers=\"true\">\n" + "         <KeyExpression>" + "          <SQL dialect='mysql'>\n" + "            cast(`store_sqft` as UNSIGNED INTEGER) + " + Integer.MAX_VALUE + "          </SQL>\n" + "          <SQL dialect='vertica'>\n" + "            cast(\"store_sqft\" as BIGINT) + " + Integer.MAX_VALUE + "          </SQL>\n" + "          <SQL dialect='oracle'>\n" + "            CAST(\"store_sqft\" + 2147483647 AS NUMBER(22))  " + "          </SQL>\n" + "         </KeyExpression>" + "      </Level>" + "    </Hierarchy>\n" + "  </Dimension>" + "  <Cube name=\"BigIntTest\" defaultMeasure=\"expression\">\n" + "    <Table name=\"sales_fact_1997\" />\n" + "    <DimensionUsage name=\"StoreSqft\" source=\"StoreSqft\" foreignKey=\"store_id\"/>\n" + "    <Measure name=\"Big Unit Sales\"   aggregator=\"sum\"\n" + "    formatString=\"Standard\" >\n" + "           <MeasureExpression>\n" + "      <SQL dialect=\"vertica\">\n" + "   CAST(\"unit_sales\" + 2147483647 AS NUMBER(22)) \n" + "      </SQL>\n" + "      </MeasureExpression>\n" + "      </Measure>\n" + "  <Measure name=\"Pass Agg enabled\" column=\"store_cost\" aggregator=\"sum\"/>\n" + "  </Cube>\n" + "</Schema>\n");
    Result result = context.executeQuery("select StoreSqft.[All StoreSqfts].children on 0 from BigIntTest");
    RolapMember secondChild = (RolapMember) result.getAxes()[0].getPositions().get(1).get(0);
    assertTrue(secondChild.getKey() instanceof Long);
    assertEquals(2147503966L, ((Long) secondChild.getKey()).longValue());
    context.assertQueryReturns("select StoreSqft.[All StoreSqfts].children on 0, " + "{measures.[Big Unit Sales]} on 1 from BigIntTest", "Axis #0:\n" + "{}\n" + "Axis #1:\n" + "{[StoreSqft].[#null]}\n" + "{[StoreSqft].[2147503966]}\n" + "{[StoreSqft].[2147504862]}\n" + "{[StoreSqft].[2147506125]}\n" + "{[StoreSqft].[2147506759]}\n" + "{[StoreSqft].[2147507240]}\n" + "{[StoreSqft].[2147507245]}\n" + "{[StoreSqft].[2147507335]}\n" + "{[StoreSqft].[2147507406]}\n" + "{[StoreSqft].[2147508244]}\n" + "{[StoreSqft].[2147511341]}\n" + "{[StoreSqft].[2147511853]}\n" + "{[StoreSqft].[2147513915]}\n" + "{[StoreSqft].[2147514231]}\n" + "{[StoreSqft].[2147514444]}\n" + "{[StoreSqft].[2147517505]}\n" + "{[StoreSqft].[2147518099]}\n" + "{[StoreSqft].[2147518438]}\n" + "{[StoreSqft].[2147520156]}\n" + "{[StoreSqft].[2147522029]}\n" + "{[StoreSqft].[2147523343]}\n" + "Axis #2:\n" + "{[Measures].[Big Unit Sales]}\n" + "Row #0: 28,101,971,043,971\n" + "Row #0: 17,746,804,884,887\n" + "Row #0: 17,085,379,920,543\n" + "Row #0: 2,845,415,834,392\n" + "Row #0: \n" + "Row #0: \n" + "Row #0: 17,624,398,316,592\n" + "Row #0: 14,635,101,075,638\n" + "Row #0: \n" + "Row #0: \n" + "Row #0: 28,662,464,278,089\n" + "Row #0: 2,963,527,435,097\n" + "Row #0: 15,884,936,560,450\n" + "Row #0: \n" + "Row #0: \n" + "Row #0: 24,017,457,143,305\n" + "Row #0: \n" + "Row #0: \n" + "Row #0: \n" + "Row #0: \n" + "Row #0: 16,913,581,228,348\n");
}
Also used : RolapMember(mondrian.rolap.RolapMember) Result(mondrian.olap.Result)

Aggregations

Result (mondrian.olap.Result)113 Axis (mondrian.olap.Axis)24 Member (mondrian.olap.Member)10 Test (org.junit.Test)10 Cell (mondrian.olap.Cell)9 Connection (mondrian.olap.Connection)9 Query (mondrian.olap.Query)9 Position (mondrian.olap.Position)8 TestContext (mondrian.test.TestContext)7 ArrayList (java.util.ArrayList)5 MondrianProperties (mondrian.olap.MondrianProperties)5 OlapElement (mondrian.olap.OlapElement)5 RolapCell (mondrian.rolap.RolapCell)5 NonEmptyResult (mondrian.rolap.RolapConnection.NonEmptyResult)5 Execution (mondrian.server.Execution)5 Dialect (mondrian.spi.Dialect)5 OlapConnection (org.olap4j.OlapConnection)5 List (java.util.List)4 ResultBase (mondrian.olap.ResultBase)4 Evaluator (mondrian.olap.Evaluator)3