Search in sources :

Example 21 with Axis

use of mondrian.olap.Axis in project pentaho-kettle by pentaho.

the class MondrianHelper method outputFlattenedRecurse.

private static void outputFlattenedRecurse(Result result, List<List<Object>> rows, List<Object> rowValues, int[] coords, int axisOrdinal) {
    final Axis[] axes = result.getAxes();
    if (axisOrdinal == axes.length) {
        final Cell cell = result.getCell(coords);
        // Output the raw (unformatted) value of the cell.
        // NOTE: We could output other properties of the cell here, such as its
        // formatted value, too.
        rowValues.add(cell.getValue());
        // Add a copy of the completed row to the list of rows.
        rows.add(new ArrayList<>(rowValues));
    } else {
        final Axis axis = axes[axisOrdinal];
        int k = -1;
        int saveLength = rowValues.size();
        for (Position position : axis.getPositions()) {
            coords[axisOrdinal] = ++k;
            for (Member member : position) {
                rowValues.add(member.getUniqueName());
            }
            outputFlattenedRecurse(result, rows, rowValues, coords, axisOrdinal + 1);
            while (rowValues.size() > saveLength) {
                rowValues.remove(rowValues.size() - 1);
            }
        }
    }
}
Also used : Position(mondrian.olap.Position) Cell(mondrian.olap.Cell) Member(mondrian.olap.Member) Axis(mondrian.olap.Axis)

Example 22 with Axis

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

the class MultipleColsInTupleAggTest method testNativeFilterWithoutMeasuresAndLevelWithProps.

public void testNativeFilterWithoutMeasuresAndLevelWithProps() throws Exception {
    if (!isApplicable()) {
        return;
    }
    // similar to the previous test, but verifies a case where
    // a level property is the extra column that requires joining
    // agg star back to the dim table.  This test also uses the bottom
    // level of the dim
    final String query = "select " + "Filter([Product].[Product Name].members, " + "Product.CurrentMember.Caption MATCHES (\"(?i).*Two.*\") )" + " on columns " + "from [Fact] ";
    getTestContext().assertQueryReturns(query, "Axis #0:\n" + "{}\n" + "Axis #1:\n" + "{[Product].[Cat One].[Prod Cat One].[Two]}\n" + "Row #0: 6\n");
    // check generated sql only for native evaluation
    if (MondrianProperties.instance().EnableNativeFilter.get()) {
        assertQuerySql(query, new SqlPattern[] { new SqlPattern(Dialect.DatabaseProduct.MYSQL, "select\n" + "    `cat`.`cat` as `c0`,\n" + "    `cat`.`cap` as `c1`,\n" + "    `cat`.`ord` as `c2`,\n" + "    `cat`.`name3` as `c3`,\n" + "    `product_cat`.`name2` as `c4`,\n" + "    `product_cat`.`cap` as `c5`,\n" + "    `product_cat`.`ord` as `c6`,\n" + "    `test_lp_xx2_fact`.`prodname` as `c7`,\n" + "    `product_csv`.`color` as `c8`\n" + "from\n" + "    `product_csv` as `product_csv`,\n" + "    `product_cat` as `product_cat`,\n" + "    `cat` as `cat`,\n" + "    `test_lp_xx2_fact` as `test_lp_xx2_fact`\n" + "where\n" + "    `product_cat`.`cat` = `cat`.`cat`\n" + "and\n" + "    `product_csv`.`prod_cat` = `product_cat`.`prod_cat`\n" + "and\n" + "    `product_csv`.`name1` = `test_lp_xx2_fact`.`prodname`\n" + "group by\n" + "    `cat`.`cat`,\n" + "    `cat`.`cap`,\n" + "    `cat`.`ord`,\n" + "    `cat`.`name3`,\n" + "    `product_cat`.`name2`,\n" + "    `product_cat`.`cap`,\n" + "    `product_cat`.`ord`,\n" + "    `test_lp_xx2_fact`.`prodname`,\n" + "    `product_csv`.`color`\n" + "having\n" + "    c7 IS NOT NULL AND UPPER(c7) REGEXP '.*TWO.*'\n" + "order by\n" + (TestContext.instance().getDialect().requiresOrderByAlias() ? "    ISNULL(`c2`) ASC, `c2` ASC,\n" + "    ISNULL(`c6`) ASC, `c6` ASC,\n" + "    ISNULL(`c7`) ASC, `c7` ASC" : "    ISNULL(`cat`.`ord`) ASC, `cat`.`ord` ASC,\n" + "    ISNULL(`product_cat`.`ord`) ASC, `product_cat`.`ord` ASC,\n" + "    ISNULL(`test_lp_xx2_fact`.`prodname`) ASC, " + "`test_lp_xx2_fact`.`prodname` ASC"), null) });
    }
    Axis axis = getTestContext().withCube("Fact").executeAxis("Filter([Product].[Product Name].members, " + "Product.CurrentMember.Caption MATCHES (\"(?i).*Two.*\") )");
    assertEquals("Member property value was not loaded correctly.", "Black", ((RolapAxis) axis).getTupleList().get(0).get(0).getPropertyValue("Product Color"));
}
Also used : RolapAxis(mondrian.rolap.RolapAxis) SqlPattern(mondrian.test.SqlPattern) RolapAxis(mondrian.rolap.RolapAxis) Axis(mondrian.olap.Axis)

Example 23 with Axis

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

the class BasicQueryTest method testAllMemberCaption.

public void testAllMemberCaption() {
    TestContext testContext = TestContext.instance().createSubstitutingCube("Sales", "<Dimension name=\"Gender3\" foreignKey=\"customer_id\">\n" + "  <Hierarchy hasAll=\"true\" allMemberName=\"All Gender\"\n" + " allMemberCaption=\"Frauen und Maenner\" primaryKey=\"customer_id\">\n" + "  <Table name=\"customer\"/>\n" + "    <Level name=\"Gender\" column=\"gender\" uniqueMembers=\"true\"/>\n" + "  </Hierarchy>\n" + "</Dimension>");
    String mdx = "select {[Gender3].[All Gender]} on columns from Sales";
    Result result = testContext.executeQuery(mdx);
    Axis axis0 = result.getAxes()[0];
    Position pos0 = axis0.getPositions().get(0);
    Member allGender = pos0.get(0);
    String caption = allGender.getCaption();
    Assert.assertEquals(caption, "Frauen und Maenner");
}
Also used : Position(mondrian.olap.Position) Axis(mondrian.olap.Axis)

Example 24 with Axis

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

the class BasicQueryTest method testAllLevelName.

public void testAllLevelName() {
    TestContext testContext = TestContext.instance().createSubstitutingCube("Sales", "<Dimension name=\"Gender4\" foreignKey=\"customer_id\">\n" + "  <Hierarchy hasAll=\"true\" allMemberName=\"All Gender\"\n" + " allLevelName=\"GenderLevel\" primaryKey=\"customer_id\">\n" + "  <Table name=\"customer\"/>\n" + "    <Level name=\"Gender\" column=\"gender\" uniqueMembers=\"true\"/>\n" + "  </Hierarchy>\n" + "</Dimension>");
    String mdx = "select {[Gender4].[All Gender]} on columns from Sales";
    Result result = testContext.executeQuery(mdx);
    Axis axis0 = result.getAxes()[0];
    Position pos0 = axis0.getPositions().get(0);
    Member allGender = pos0.get(0);
    String caption = allGender.getLevel().getName();
    Assert.assertEquals(caption, "GenderLevel");
}
Also used : Position(mondrian.olap.Position) Axis(mondrian.olap.Axis)

Example 25 with Axis

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

the class BasicQueryTest method testNonEmptyCrossJoin.

/**
 * Tests a query with a CrossJoin so large that we run out of memory unless
 * we can push down evaluation to SQL.
 */
public void testNonEmptyCrossJoin() {
    if (!props.EnableNativeCrossJoin.get()) {
        // memory.
        return;
    }
    TestContext.instance().flushSchemaCache();
    Result result = executeQuery("select {[Measures].[Store Sales]} on columns,\n" + "  NON EMPTY Crossjoin(\n" + "    [Customers].[Name].Members,\n" + "    [Product].[Product Name].Members\n" + " ) ON rows\n" + "from [Sales]\n" + "where (\n" + "  [Store].[All Stores].[USA].[CA].[San Francisco].[Store 14],\n" + "  [Time].[1997].[Q1].[1]\n" + ")\n");
    // ok if no OutOfMemoryError occurs
    Axis a = result.getAxes()[1];
    assertEquals(67, a.getPositions().size());
}
Also used : Axis(mondrian.olap.Axis)

Aggregations

Axis (mondrian.olap.Axis)38 Result (mondrian.olap.Result)9 Position (mondrian.olap.Position)8 List (java.util.List)7 Member (mondrian.olap.Member)7 Test (org.junit.Test)7 Cell (mondrian.olap.Cell)6 ArrayList (java.util.ArrayList)5 TupleList (mondrian.calc.TupleList)4 UnaryTupleList (mondrian.calc.impl.UnaryTupleList)4 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)2 Hierarchy (mondrian.olap.Hierarchy)2 RolapAxis (mondrian.rolap.RolapAxis)2 DBCacheEntry (org.pentaho.di.core.DBCacheEntry)2 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)2 RowMeta (org.pentaho.di.core.row.RowMeta)2 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)2 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)2 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)2