Skip to content

Commit

Permalink
MONDRIAN: Fix MONDRIAN-1063, "Various issues preventing analyzer from…
Browse files Browse the repository at this point in the history
… moving to

    olap4j". Here are the changes made, relating to the numbered issues listed
    in that case:

    > 5. Add support for annotations

    Added method "Map<String, Object>
    XmlaHandler.XmlaExtra.getAnnotationMap(MetadataElement)".

    I also made the implementations of org.olap4j.metadata.MetadataElement in
    MondrianOlap4jDriver (MondrianOlap4jCube, MondrianOlap4jDimension etc.)
    implement org.olap4j.OlapWrapper. Therefore you can call

 	    ((OlapWrapper) cube).unwrap(mondrian.olap.Annotated.class).get("foo")

    MetadataElement won't implement org.olap4j.OlapWrapper or java.sql.Wrapper
    until olap4j-1.1. That is a change that will break existing drivers.

    > 6. No format string on StandardMemberProperty
    >
    > 15. Need access to mondrian.olap.Property.FORMAT_EXP from within a Cell and
    > Member
    >
    > 7. Level member properties

    Added a new property "FORMAT_EXP", and made sure that it comes through the
    olap4j driver. You should specify 'DIMENSION PROPERTIES FORMAT_EXP' if you
    want it.

    > 10. Does level.getMembers include calculated members

    Fixed the javadoc.

    > 12. How to tell if a cell is drillable?

    Added cell property "ACTION_TYPE". You will have to ask for it in the
    CELL PROPERTIES clause of the query. The result is an integer bitmask. Bit
    MDACTION_TYPE_DRILLTHROUGH (0x100), will be set if you can drill through.

    > 13. Drill-through count.

    Added cell property "DRILLTHROUGH_COUNT". Value will be -1 if not drillable.
    You will have to ask for it in the CELL PROPERTIES clause of the query.
    Use with caution; may be expensive to evaluate.

    > 17. OlapException needs to pass through the underlying
    > ResourceLimitExceededException, QueryTimeoutException and
    > MondrianEvaluationException.

    The underlying exception is there, if you call getCause(). Furthermore,
    getSQLState() in these cases will return "ResourceLimitExceeded",
    "QueryTimeout", "EvaluationException".

[git-p4: depot-paths = "//open/mondrian/": change = 14886]
  • Loading branch information
julianhyde committed Jan 17, 2012
1 parent f96086a commit ed40aed
Show file tree
Hide file tree
Showing 26 changed files with 577 additions and 71 deletions.
10 changes: 7 additions & 3 deletions src/main/mondrian/olap/Formula.java
Expand Up @@ -4,7 +4,7 @@
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2000-2002 Kana Software, Inc.
// Copyright (C) 2001-2011 Julian Hyde and others
// Copyright (C) 2001-2012 Julian Hyde and others
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -124,7 +124,10 @@ void accept(Validator validator) {
if (isMember) {
Exp formatExp = getFormatExp(validator);
if (formatExp != null) {
mdxMember.setProperty(Property.FORMAT_EXP.name, formatExp);
mdxMember.setProperty(
Property.FORMAT_EXP_PARSED.name, formatExp);
mdxMember.setProperty(
Property.FORMAT_EXP.name, Util.unparse(formatExp));
}

final List<MemberProperty> memberPropertyList =
Expand Down Expand Up @@ -606,7 +609,8 @@ private void returnFormula(Member member) {
}

private Exp getFormula(Member member) {
return (Exp) member.getPropertyValue(Property.FORMAT_EXP.name);
return (Exp)
member.getPropertyValue(Property.FORMAT_EXP_PARSED.name);
}
}
}
Expand Down
68 changes: 57 additions & 11 deletions src/main/mondrian/olap/Property.java
Expand Up @@ -4,7 +4,7 @@
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2001-2002 Kana Software, Inc.
// Copyright (C) 2001-2011 Julian Hyde and others
// Copyright (C) 2001-2012 Julian Hyde and others
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
Expand Down Expand Up @@ -84,14 +84,15 @@ public enum Datatype {
public static final Map<String, Property> mapUpperNameToProperties =
new HashMap<String, Property>();

public static final int FORMAT_EXP_ORDINAL = 0;
public static final int FORMAT_EXP_PARSED_ORDINAL = 0;
/**
* Definition of the internal property which
* holds the parsed format string (an object of type {@link Exp}).
*/
public static final Property FORMAT_EXP =
public static final Property FORMAT_EXP_PARSED =
new Property(
"$format_exp", Datatype.TYPE_OTHER, FORMAT_EXP_ORDINAL, true, false,
"$format_exp", Datatype.TYPE_OTHER,
FORMAT_EXP_PARSED_ORDINAL, true, false,
false, null);

public static final int AGGREGATION_TYPE_ORDINAL = 1;
Expand Down Expand Up @@ -662,6 +663,46 @@ public enum Datatype {
false, false, true,
"The translation expressed as an LCID. Only valid for property translations.");

public static final int FORMAT_EXP_ORDINAL = 53;

/**
* Definition of the property which
* holds the format string.
*/
public static final Property FORMAT_EXP =
new Property(
"FORMAT_EXP", Datatype.TYPE_STRING, FORMAT_EXP_ORDINAL, true, true,
false, null);

public static final int ACTION_TYPE_ORDINAL = 54;

/**
* Definition of the property which
* holds the format string.
*/
public static final Property ACTION_TYPE =
new Property(
"ACTION_TYPE", Datatype.TYPE_NUMERIC, ACTION_TYPE_ORDINAL, false,
false, true, null);

public static final int DRILLTHROUGH_COUNT_ORDINAL = 55;

/**
* Definition of the property that
* holds the number of fact rows that contributed to this cell.
* If the cell is not drillable, returns -1.
*
* <p>Note that this property may be expensive to compute for some
* cubes.</p>
*/
public static final Property DRILLTHROUGH_COUNT =
new Property(
"DRILLTHROUGH_COUNT", Datatype.TYPE_NUMERIC,
DRILLTHROUGH_COUNT_ORDINAL, false,
false, true,
"Number of fact rows that contributed to this cell. If the cell is "
+ "not drillable, value is -1.");

/**
* The various property names which define a format string.
*/
Expand Down Expand Up @@ -741,24 +782,23 @@ public boolean isMemberProperty() {
}

/**
* Returns whether this property is a standard member property.
* Returns whether this property is a standard cell property.
*/
public boolean isCellProperty() {
return cell && ordinal <= VALUE_ORDINAL;
return cell && isStandard();
}

/**
* Returns whether this property is standard.
*/
public boolean isStandard() {
return ordinal <= VALUE_ORDINAL;
return ordinal < MAX_ORDINAL;
}


public static final EnumeratedValues<Property> enumeration =
new EnumeratedValues<Property>(
new Property[] {
FORMAT_EXP,
FORMAT_EXP_PARSED,
AGGREGATION_TYPE,
NAME,
CAPTION,
Expand Down Expand Up @@ -803,18 +843,24 @@ public boolean isStandard() {
KEY,
SCENARIO,
DISPLAY_FOLDER,
FORMAT_EXP,
ACTION_TYPE,
DRILLTHROUGH_COUNT,
});

private static final int MAX_ORDINAL = 56;

static {
// Populate synonyms.
synonyms.put("CAPTION", MEMBER_CAPTION);
synonyms.put("FORMAT", FORMAT_STRING);

// Populate map of upper-case property names.
for (String propertyName : enumeration.getNames()) {
final Property property = enumeration.getValue(propertyName, true);
mapUpperNameToProperties.put(
propertyName.toUpperCase(),
enumeration.getValue(propertyName, true));
propertyName.toUpperCase(), property);
assert property.getOrdinal() < MAX_ORDINAL;
}

// Add synonyms.
Expand Down
6 changes: 3 additions & 3 deletions src/main/mondrian/olap/Util.java
Expand Up @@ -4137,22 +4137,22 @@ public interface Usage {
* correctly with {@link RolapUtil#sqlNullValue}.
*/
public static class SqlNullSafeComparator
implements Comparator<Comparable<?>>
implements Comparator<Comparable>
{
public static final SqlNullSafeComparator instance =
new SqlNullSafeComparator();

private SqlNullSafeComparator() {
}

public int compare(Comparable<?> o1, Comparable<?> o2) {
public int compare(Comparable o1, Comparable o2) {
if (o1 == RolapUtil.sqlNullValue) {
return -1;
}
if (o2 == RolapUtil.sqlNullValue) {
return 1;
}
return ((Comparable) o1).compareTo(o2);
return o1.compareTo(o2);
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/main/mondrian/olap4j/MondrianOlap4jCatalog.java
Expand Up @@ -3,13 +3,14 @@
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2007-2011 Julian Hyde
// Copyright (C) 2007-2012 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package mondrian.olap4j;

import mondrian.olap.Access;
import mondrian.olap.OlapElement;
import mondrian.rolap.RolapSchema;

import org.olap4j.OlapDatabaseMetaData;
Expand All @@ -27,7 +28,10 @@
* @version $Id$
* @since May 23, 2007
*/
class MondrianOlap4jCatalog implements Catalog, Named {
class MondrianOlap4jCatalog
extends MondrianOlap4jMetadataElement
implements Catalog, Named
{
final MondrianOlap4jDatabaseMetaData olap4jDatabaseMetaData;
final String name;
final Map<String, RolapSchema> schemaMap;
Expand Down Expand Up @@ -95,6 +99,10 @@ public OlapDatabaseMetaData getMetaData() {
public Database getDatabase() {
return olap4jDatabase;
}

protected OlapElement getOlapElement() {
return null;
}
}

// End MondrianOlap4jCatalog.java
@@ -1,8 +1,9 @@
/*
// $Id$
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2007-2010 Julian Hyde
// Copyright (C) 2007-2012 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -59,6 +60,10 @@ class MondrianOlap4jCellSetAxisMetaData implements CellSetAxisMetaData {
olap4jProperty =
Util.lookup(
Property.StandardMemberProperty.class, names[0]);
if (olap4jProperty == null) {
olap4jProperty =
MondrianOlap4jProperty.MEMBER_EXTENSIONS.get(names[0]);
}
}
if (olap4jProperty == null) {
final UnresolvedFunCall call =
Expand Down
16 changes: 11 additions & 5 deletions src/main/mondrian/olap4j/MondrianOlap4jCellSetMetaData.java
Expand Up @@ -3,19 +3,20 @@
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2007-2010 Julian Hyde
// Copyright (C) 2007-2012 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package mondrian.olap4j;

import mondrian.olap.Query;
import mondrian.olap.QueryAxis;
import mondrian.olap.*;

import org.olap4j.CellSetAxisMetaData;
import org.olap4j.CellSetMetaData;
import org.olap4j.impl.ArrayNamedListImpl;
import org.olap4j.metadata.*;
import org.olap4j.metadata.Cube;
import org.olap4j.metadata.Property;

import java.sql.SQLException;

Expand Down Expand Up @@ -64,8 +65,13 @@ protected String getName(Property property) {
return property.getName();
}
};
for (Property.StandardCellProperty property
: Property.StandardCellProperty.values())
for (Property property : Property.StandardCellProperty.values()) {
if (query.hasCellProperty(property.getName())) {
list.add(property);
}
}
for (Property property
: MondrianOlap4jProperty.CELL_EXTENSIONS.values())
{
if (query.hasCellProperty(property.getName())) {
list.add(property);
Expand Down
26 changes: 24 additions & 2 deletions src/main/mondrian/olap4j/MondrianOlap4jConnection.java
Expand Up @@ -12,6 +12,7 @@
import mondrian.mdx.*;
import mondrian.olap.*;
import mondrian.olap.Member;
import mondrian.olap.fun.MondrianEvaluationException;
import mondrian.rolap.*;
import mondrian.xmla.XmlaHandler;

Expand Down Expand Up @@ -738,7 +739,7 @@ OlapException createException(Cell context, String msg) {
OlapException createException(
Cell context, String msg, Throwable cause)
{
OlapException exception = new OlapException(msg, cause);
OlapException exception = createException(msg, cause);
exception.setContext(context);
return exception;
}
Expand All @@ -753,7 +754,28 @@ OlapException createException(
OlapException createException(
String msg, Throwable cause)
{
return new OlapException(msg, cause);
String sqlState = deduceSqlState(cause);
assert !mondrian.util.Bug.olap4jUpgrade(
"use OlapException(String, String, Throwable) ctor");
final OlapException e = new OlapException(msg, sqlState);
e.initCause(cause);
return e;
}

private String deduceSqlState(Throwable cause) {
if (cause == null) {
return null;
}
if (cause instanceof ResourceLimitExceededException) {
return "ResourceLimitExceeded";
}
if (cause instanceof QueryTimeoutException) {
return "QueryTimeout";
}
if (cause instanceof MondrianEvaluationException) {
return "EvaluationException";
}
return null;
}

/**
Expand Down

0 comments on commit ed40aed

Please sign in to comment.