From 15a7cd95fc1ba3bd948df79d04923f6c41d67784 Mon Sep 17 00:00:00 2001 From: Miguel Oliveira Date: Tue, 2 Oct 2018 17:53:02 +0100 Subject: [PATCH] [MONDRIAN-2342] - Xmla response does not contain properties in tuple section * Whenever an element does not exist, print the affected property in tuple section of xmla response. --- .../xmla/XmlaDimensionPropertiesTest.java | 14 +- .../xmla/XmlaDimensionPropertiesTest.ref.xml | 384 +++++++++++++++++- .../main/java/mondrian/xmla/XmlaHandler.java | 36 +- 3 files changed, 421 insertions(+), 13 deletions(-) diff --git a/mondrian/src/it/java/mondrian/xmla/XmlaDimensionPropertiesTest.java b/mondrian/src/it/java/mondrian/xmla/XmlaDimensionPropertiesTest.java index 02c9dcdc3d..3ff7616d42 100644 --- a/mondrian/src/it/java/mondrian/xmla/XmlaDimensionPropertiesTest.java +++ b/mondrian/src/it/java/mondrian/xmla/XmlaDimensionPropertiesTest.java @@ -4,7 +4,7 @@ // http://www.eclipse.org/legal/epl-v10.html. // You must accept the terms of that agreement to use this software. // -// Copyright (C) 2005-2017 Hitachi Vantara and others +// Copyright (C) 2005-2018 Hitachi Vantara and others // All Rights Reserved. */ package mondrian.xmla; @@ -24,15 +24,19 @@ public class XmlaDimensionPropertiesTest extends XmlaBaseTestCase { public void testOneHierarchyProperties() throws Exception { - executeTest(); + executeTest("HR"); } public void testTwoHierarchiesProperties() throws Exception { - executeTest(); + executeTest("HR"); } - private void executeTest() throws Exception { - TestContext context = getTestContext().withCube("HR"); + public void testMondrian2342() throws Exception { + executeTest("Sales"); + } + + private void executeTest(String cubeName) throws Exception { + TestContext context = getTestContext().withCube(cubeName); String requestType = "EXECUTE"; Properties props = getDefaultRequestProperties(requestType); doTest(requestType, props, context); diff --git a/mondrian/src/it/java/mondrian/xmla/XmlaDimensionPropertiesTest.ref.xml b/mondrian/src/it/java/mondrian/xmla/XmlaDimensionPropertiesTest.ref.xml index 2206b10c83..652c23cc37 100644 --- a/mondrian/src/it/java/mondrian/xmla/XmlaDimensionPropertiesTest.ref.xml +++ b/mondrian/src/it/java/mondrian/xmla/XmlaDimensionPropertiesTest.ref.xml @@ -204,7 +204,6 @@ - @@ -497,7 +496,6 @@ - @@ -567,7 +565,7 @@ SELECT [Pay Type] ON COLUMNS, - [Store].[Store Country].[USA] DIMENSION PROPERTIES [Store].[Store Name].[Store Manager] ON ROWS + [Store].[Store Country].[USA] DIMENSION PROPERTIES [Store].[Store Name].[Store Manager] ON ROWS FROM HR @@ -585,4 +583,384 @@ ]]> + + + + + + + + SELECT NON EMPTY + Hierarchize(DrilldownMember({{DrilldownMember({{DrilldownMember({{DrilldownLevel( + {[Store].[All Stores]})}},{[Store].[USA]})}},{[Store].[USA].[OR]})}},{[Store].[USA].[OR].[Portland]})) + DIMENSION PROPERTIES [Store].[Store Name].[Store Type] ON COLUMNS FROM [Sales] + WHERE [Time].[Year].[1997] + + + + + ${catalog} + ${data.source.info} + ${format} + TupleFormat + + + + + + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Sales + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Store].[All Stores] + All Stores + [Store].[(All)] + 0 + 65539 + + + + + [Store].[USA] + USA + [Store].[Store Country] + 1 + 65539 + + + + + [Store].[USA].[CA] + CA + [Store].[Store State] + 2 + 5 + + + + + [Store].[USA].[OR] + OR + [Store].[Store State] + 2 + 196610 + + + + + [Store].[USA].[OR].[Portland] + Portland + [Store].[Store City] + 3 + 65537 + + + + + [Store].[USA].[OR].[Portland].[Store 11] + Store 11 + [Store].[Store Name] + 4 + 0 + Supermarket + + + + + [Store].[USA].[OR].[Salem] + Salem + [Store].[Store City] + 3 + 1 + + + + + [Store].[USA].[WA] + WA + [Store].[Store State] + 2 + 7 + + + + + + + + + [Time].[1997] + 1997 + [Time].[Year] + 0 + 4 + + + + + + + + 266773 + 266,773 + Standard + + + 266773 + 266,773 + Standard + + + 74748 + 74,748 + Standard + + + 67659 + 67,659 + Standard + + + 26079 + 26,079 + Standard + + + 26079 + 26,079 + Standard + + + 41580 + 41,580 + Standard + + + 124366 + 124,366 + Standard + + + + + + + + ]]> + + + \ No newline at end of file diff --git a/mondrian/src/main/java/mondrian/xmla/XmlaHandler.java b/mondrian/src/main/java/mondrian/xmla/XmlaHandler.java index 1112129e0e..089eed0ef0 100644 --- a/mondrian/src/main/java/mondrian/xmla/XmlaHandler.java +++ b/mondrian/src/main/java/mondrian/xmla/XmlaHandler.java @@ -2022,6 +2022,7 @@ private List axisInfo( "name", axisName); List hierarchies; + List props = new ArrayList<>(getProps(axis.getAxisMetaData())); Iterator it = axis.getPositions().iterator(); if (it.hasNext()) { final org.olap4j.Position position = it.next(); @@ -2032,7 +2033,10 @@ private List axisInfo( } else { hierarchies = axis.getAxisMetaData().getHierarchies(); } - List props = getProps(axis.getAxisMetaData()); + + // remove a property without a valid associated hierarchy + props.removeIf(prop -> !isValidProp(axis.getPositions(), prop)); + writeHierarchyInfo(writer, hierarchies, props); writer.endElement(); // AxisInfo @@ -2040,6 +2044,20 @@ private List axisInfo( return hierarchies; } + private boolean isValidProp(List positions, Property prop) { + if(!(prop instanceof IMondrianOlap4jProperty)){ + return true; + } + + for (Position pos : positions){ + if(pos.getMembers().stream() + .anyMatch(member -> Objects.nonNull(getHierarchyProperty(member, prop)))){ + return true; + } + } + return false; + } + private void writeHierarchyInfo( SaxWriter writer, List hierarchies, @@ -2284,7 +2302,7 @@ private void writeMember( value = member.getDepth(); } else { value = (longProp instanceof IMondrianOlap4jProperty) - ? getCurrentHierarchyProperty(member, longProp) + ? getHierarchyProperty(member, longProp) : member.getPropertyValue(longProp); } if (value != null) { @@ -2294,8 +2312,8 @@ private void writeMember( writer.endElement(); // Member } - private Object getCurrentHierarchyProperty( - Member member, Property longProp) throws OlapException + private Object getHierarchyProperty( + Member member, Property longProp) { IMondrianOlap4jProperty currentProperty = (IMondrianOlap4jProperty) longProp; @@ -2303,7 +2321,15 @@ private Object getCurrentHierarchyProperty( String thatHierarchyName = currentProperty.getLevel() .getHierarchy().getName(); if (thisHierarchyName.equals(thatHierarchyName)) { - return member.getPropertyValue(currentProperty); + try { + return member.getPropertyValue(currentProperty); + } catch (OlapException e) { + throw new XmlaException( + SERVER_FAULT_FC, + HSB_BAD_PROPERTIES_LIST_CODE, + HSB_BAD_PROPERTIES_LIST_FAULT_FS, + e); + } } // if property doesn't belong to current hierarchy return null return null;