Search in sources :

Example 1 with Property

use of org.olap4j.metadata.Property in project mondrian by pentaho.

the class Olap4jTest method testCellProperties.

public void testCellProperties() throws SQLException {
    final OlapConnection connection = getTestContext().getOlap4jConnection();
    final CellSet cellSet = connection.createStatement().executeOlapQuery("with member [Customers].[USA].[CA WA] as\n" + " Aggregate({[Customers].[USA].[CA], [Customers].[USA].[WA]})\n" + "select [Measures].[Unit Sales] on 0,\n" + " {[Customers].[USA].[CA], [Customers].[USA].[CA WA]} on 1\n" + "from [Sales]\n" + "cell properties ACTION_TYPE, DRILLTHROUGH_COUNT");
    final CellSetMetaData metaData = cellSet.getMetaData();
    final Property actionTypeProperty = metaData.getCellProperties().get("ACTION_TYPE");
    final Property drillthroughCountProperty = metaData.getCellProperties().get("DRILLTHROUGH_COUNT");
    // Cell [0, 0] is drillable
    final Cell cell0 = cellSet.getCell(0);
    final int actionType0 = (Integer) cell0.getPropertyValue(actionTypeProperty);
    // MDACTION_TYPE_DRILLTHROUGH
    assertEquals(0x100, actionType0);
    final int drill0 = (Integer) cell0.getPropertyValue(drillthroughCountProperty);
    assertEquals(24442, drill0);
    // Cell [0, 1] is not drillable
    final Cell cell1 = cellSet.getCell(1);
    final int actionType1 = (Integer) cell1.getPropertyValue(actionTypeProperty);
    assertEquals(0x0, actionType1);
    final int drill1 = (Integer) cell1.getPropertyValue(drillthroughCountProperty);
    assertEquals(-1, drill1);
}
Also used : Property(org.olap4j.metadata.Property) Cell(org.olap4j.Cell)

Example 2 with Property

use of org.olap4j.metadata.Property in project mondrian by pentaho.

the class Olap4jTest method testFormatString.

public void testFormatString() throws SQLException {
    final OlapConnection connection = getTestContext().getOlap4jConnection();
    final CellSet cellSet = connection.createStatement().executeOlapQuery("with member [Measures].[Foo] as 1, FORMAT_STRING = Iif(1 < 2, '##.0%', 'foo')\n" + "select\n" + " [Measures].[Foo] DIMENSION PROPERTIES FORMAT_EXP on 0\n" + "from [Sales]");
    final CellSetAxis axis = cellSet.getAxes().get(0);
    final Member member = axis.getPositions().get(0).getMembers().get(0);
    Property property = findProperty(axis, "FORMAT_EXP");
    assertNotNull(property);
    // Note that the expression is returned, unevaluated. You can tell from
    // the parentheses and quotes that it has been un-parsed.
    assertEquals("IIf((1 < 2), \"##.0%\", \"foo\")", member.getPropertyValue(property));
}
Also used : Member(org.olap4j.metadata.Member) Property(org.olap4j.metadata.Property)

Example 3 with Property

use of org.olap4j.metadata.Property in project mondrian by pentaho.

the class Olap4jTest method testLevelProperties.

/**
 * Tests that a property that is not a standard olap4j property but is a
 * Mondrian-builtin property (viz, "FORMAT_EXP") is included among a level's
 * properties.
 *
 * @throws SQLException on error
 */
public void testLevelProperties() throws SQLException {
    final OlapConnection connection = getTestContext().getOlap4jConnection();
    final CellSet cellSet = connection.createStatement().executeOlapQuery("select [Store].[Store Name].Members on 0\n" + "from [Sales]");
    final CellSetAxis axis = cellSet.getAxes().get(0);
    final Member member = axis.getPositions().get(0).getMembers().get(0);
    final NamedList<Property> properties = member.getLevel().getProperties();
    // UNIQUE_NAME is an olap4j standard property.
    assertNotNull(properties.get("MEMBER_UNIQUE_NAME"));
    // FORMAT_EXP is a Mondrian built-in but not olap4j standard property.
    assertNotNull(properties.get("FORMAT_EXP"));
    // [Store Type] is a property of the level.
    assertNotNull(properties.get("Store Type"));
}
Also used : Member(org.olap4j.metadata.Member) Property(org.olap4j.metadata.Property)

Example 4 with Property

use of org.olap4j.metadata.Property in project mondrian by pentaho.

the class UdfTest method testPropertyFormatterNested.

/**
 * As {@link #testPropertyFormatter()}, but using new-style nested
 * PropertyFormatter element.
 *
 * @throws java.sql.SQLException on error
 */
public void testPropertyFormatterNested() throws SQLException {
    TestContext tc = TestContext.instance().createSubstitutingCube("Sales", "<Dimension name='Promotions2' foreignKey='promotion_id'>\n" + "  <Hierarchy hasAll='true' allMemberName='All Promotions' primaryKey='promotion_id' defaultMember='[All Promotions]'>\n" + "    <Table name='promotion'/>\n" + "    <Level name='Promotion Name' column='promotion_id' uniqueMembers='true'>\n" + "      <Property name='Medium' column='media_type'>\n" + "        <PropertyFormatter className='" + FooBarPropertyFormatter.class.getName() + "'/>\n" + "      </Property>\n" + "    </Level>\n" + "  </Hierarchy>\n" + "</Dimension>");
    final CellSet result = tc.executeOlap4jQuery("select [Promotions2].Children on 0\n" + "from [Sales]");
    final org.olap4j.metadata.Member member = result.getAxes().get(0).getPositions().get(0).getMembers().get(0);
    final Property property = member.getProperties().get("Medium");
    assertEquals("foo0/Medium/No Mediabar", member.getPropertyFormattedValue(property));
}
Also used : Property(org.olap4j.metadata.Property)

Example 5 with Property

use of org.olap4j.metadata.Property in project mondrian by pentaho.

the class UdfTest method testPropertyFormatter.

/**
 * Unit test for a property formatter defined in the old way -- a
 * 'formatter' attribute of a Property element.
 *
 * @throws java.sql.SQLException on error
 */
public void testPropertyFormatter() throws SQLException {
    TestContext tc = TestContext.instance().createSubstitutingCube("Sales", "<Dimension name='Promotions2' foreignKey='promotion_id'>\n" + "  <Hierarchy hasAll='true' allMemberName='All Promotions' primaryKey='promotion_id' defaultMember='[All Promotions]'>\n" + "    <Table name='promotion'/>\n" + "    <Level name='Promotion Name' column='promotion_id' uniqueMembers='true'>\n" + "      <Property name='Medium' column='media_type' formatter='" + FooBarPropertyFormatter.class.getName() + "'/>\n" + "    </Level>\n" + "  </Hierarchy>\n" + "</Dimension>");
    final CellSet result = tc.executeOlap4jQuery("select [Promotions2].Children on 0\n" + "from [Sales]");
    final org.olap4j.metadata.Member member = result.getAxes().get(0).getPositions().get(0).getMembers().get(0);
    final Property property = member.getProperties().get("Medium");
    assertEquals("foo0/Medium/No Mediabar", member.getPropertyFormattedValue(property));
}
Also used : Property(org.olap4j.metadata.Property)

Aggregations

Property (org.olap4j.metadata.Property)6 Member (org.olap4j.metadata.Member)2 Cell (org.olap4j.Cell)1