Skip to content

Commit

Permalink
Fix XMLA driver bug 2527862, "Failed to get Hierarchy list for partic…
Browse files Browse the repository at this point in the history
…ular

dimension".

This required a change to the olap4j API. Consistent with XMLA, dimension name
parameter of OlapDatabaseMetaData.getHierarchies is now dimension unique name,
and no longer a pattern.

In XMLA driver, validate that all parameters to metadata requests have
valid names.


git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@142 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Jan 22, 2009
1 parent 1dd1911 commit ce2aa44
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/org/olap4j/OlapDatabaseMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ ResultSet getOlapFunctions(
* without a cube; <code>null</code> means that the cube name should
* not be used to narrow the search
*
* @param dimensionNamePattern a dimension name pattern; must match the
* @param dimensionUniqueName unique name of a dimension (not a pattern);
* must match the
* dimension name as it is stored in the database; <code>null</code>
* means that the dimension name should not be used to narrow the
* search
Expand All @@ -572,7 +573,7 @@ ResultSet getHierarchies(
String catalog,
String schemaPattern,
String cubeNamePattern,
String dimensionNamePattern,
String dimensionUniqueName,
String hierarchyNamePattern) throws OlapException;

/**
Expand Down
20 changes: 18 additions & 2 deletions src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import org.olap4j.mdx.parser.impl.DefaultMdxParserImpl;
import org.olap4j.metadata.*;
import org.w3c.dom.*;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSSerializer;
import org.xml.sax.SAXException;

import java.io.*;
Expand Down Expand Up @@ -1743,6 +1741,7 @@ enum MetadataRequest {
new MetadataColumn("SCOPE"));

final List<MetadataColumn> columns;
final Map<String, MetadataColumn> columnsByName;

MetadataRequest(MetadataColumn... columns) {
if (name().equals("DBSCHEMA_CATALOGS")) {
Expand All @@ -1762,6 +1761,12 @@ enum MetadataRequest {
this.columns =
Collections.unmodifiableList(
Arrays.asList(columns));
final Map<String, MetadataColumn> map =
new HashMap<String, MetadataColumn>();
for (MetadataColumn column : columns) {
map.put(column.name, column);
}
this.columnsByName = Collections.unmodifiableMap(map);
}

/**
Expand All @@ -1783,6 +1788,17 @@ public boolean requiresDatasourceName() {
public boolean requiresCatalogName() {
return (this != DBSCHEMA_CATALOGS && this != DISCOVER_DATASOURCES);
}

/**
* Returns the column with a given name, or null if there is no such
* column.
*
* @param name Column name
* @return Column, or null if not found
*/
public MetadataColumn getColumn(String name) {
return columnsByName.get(name);
}
}

private static final Pattern LOWERCASE_PATTERN = Pattern.compile(".*[a-z].*");
Expand Down
9 changes: 6 additions & 3 deletions src/org/olap4j/driver/xmla/XmlaOlap4jDatabaseMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ private ResultSet getMetadata(
Map<String, Matcher> predicateList = new ArrayMap<String, Matcher>();
for (int i = 0; i < patternValues.length; i += 2) {
String name = (String) patternValues[i];
assert metadataRequest.getColumn(name) != null
: "Request '" + metadataRequest
+ "' does not support column '" + name + "'";
Object value = patternValues[i + 1];
if (value == null) {
// ignore
Expand Down Expand Up @@ -1014,7 +1017,7 @@ public ResultSet getDimensions(
XmlaOlap4jConnection.MetadataRequest.MDSCHEMA_DIMENSIONS,
"SCHEMA_NAME", wildcard(schemaPattern),
"CUBE_NAME", wildcard(cubeNamePattern),
"DIMSENSION_NAME", wildcard(dimensionNamePattern));
"DIMENSION_NAME", wildcard(dimensionNamePattern));
}

public ResultSet getOlapFunctions(
Expand All @@ -1029,7 +1032,7 @@ public ResultSet getHierarchies(
String catalog,
String schemaPattern,
String cubeNamePattern,
String dimensionNamePattern,
String dimensionUniqueName,
String hierarchyNamePattern)
throws OlapException
{
Expand All @@ -1038,7 +1041,7 @@ public ResultSet getHierarchies(
"CATALOG_NAME", catalog,
"SCHEMA_NAME", wildcard(schemaPattern),
"CUBE_NAME", wildcard(cubeNamePattern),
"DIMENSION_NAME", wildcard(dimensionNamePattern),
"DIMENSION_UNIQUE_NAME", dimensionUniqueName,
"HIERARCHY_NAME", wildcard(hierarchyNamePattern));
}

Expand Down
7 changes: 7 additions & 0 deletions testsrc/org/olap4j/MetadataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,13 @@ public void testDatabaseMetaDataGetHierarchies() throws SQLException {
catalogName, null, "Sales", null, "Store"),
HIERARCHIES_COLUMN_NAMES);
assertEquals(TestContext.fold("CATALOG_NAME=" + catalogName + ", SCHEMA_NAME=FoodMart, CUBE_NAME=Sales, DIMENSION_UNIQUE_NAME=[Store], HIERARCHY_NAME=Store, HIERARCHY_UNIQUE_NAME=[Store], HIERARCHY_GUID=null, HIERARCHY_CAPTION=Store, DIMENSION_TYPE=3, HIERARCHY_CARDINALITY=63, DEFAULT_MEMBER=[Store].[All Stores], ALL_MEMBER=[Store].[All Stores], DESCRIPTION=Sales Cube - Store Hierarchy, STRUCTURE=0, IS_VIRTUAL=false, IS_READWRITE=false, DIMENSION_UNIQUE_SETTINGS=0, DIMENSION_IS_VISIBLE=true, HIERARCHY_ORDINAL=1, DIMENSION_IS_SHARED=true, PARENT_CHILD=false\n"), s);

// With dimension unique name (bug 2527862).
s = checkResultSet(
olapDatabaseMetaData.getHierarchies(
catalogName, null, "Sales", "[Store]", null),
HIERARCHIES_COLUMN_NAMES);
assertEquals(TestContext.fold("CATALOG_NAME=" + catalogName + ", SCHEMA_NAME=FoodMart, CUBE_NAME=Sales, DIMENSION_UNIQUE_NAME=[Store], HIERARCHY_NAME=Store, HIERARCHY_UNIQUE_NAME=[Store], HIERARCHY_GUID=null, HIERARCHY_CAPTION=Store, DIMENSION_TYPE=3, HIERARCHY_CARDINALITY=63, DEFAULT_MEMBER=[Store].[All Stores], ALL_MEMBER=[Store].[All Stores], DESCRIPTION=Sales Cube - Store Hierarchy, STRUCTURE=0, IS_VIRTUAL=false, IS_READWRITE=false, DIMENSION_UNIQUE_SETTINGS=0, DIMENSION_IS_VISIBLE=true, HIERARCHY_ORDINAL=1, DIMENSION_IS_SHARED=true, PARENT_CHILD=false\n"), s);
}

public void testDatabaseMetaDataGetLevels() throws SQLException {
Expand Down

0 comments on commit ce2aa44

Please sign in to comment.