summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlzhang2011-10-19 03:19:06 (EDT)
committer xgu2011-10-19 03:19:06 (EDT)
commit3bfb99ef6b12cbed79cffd460ba79e8c8df4594f (patch)
tree949c558c3d58c8af2631d2a0db0b301ee8d67a47
parentcbce981171ca203cb84741f844b719af1e8cbe68 (diff)
downloadorg.eclipse.birt-3bfb99ef6b12cbed79cffd460ba79e8c8df4594f.zip
org.eclipse.birt-3bfb99ef6b12cbed79cffd460ba79e8c8df4594f.tar.gz
org.eclipse.birt-3bfb99ef6b12cbed79cffd460ba79e8c8df4594f.tar.bz2
Checkin: Support the calculation of derived measure which is
defined in cube design in DtE side
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/api/query/ICubeQueryDefinition.java18
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/api/query/IDerivedMeasureDefinition.java24
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/api/query/IMeasureDefinition.java12
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/impl/query/CubeQueryDefinition.java25
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/impl/query/DerivedMeasureDefinition.java44
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/impl/query/MeasureDefinition.java20
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/impl/query/PreparedCubeQueryDefinition.java210
-rw-r--r--data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/impl/DataRequestSessionImpl.java29
8 files changed, 377 insertions, 5 deletions
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/api/query/ICubeQueryDefinition.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/api/query/ICubeQueryDefinition.java
index 0f237d6..dabe836 100644
--- a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/api/query/ICubeQueryDefinition.java
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/api/query/ICubeQueryDefinition.java
@@ -110,6 +110,18 @@ public interface ICubeQueryDefinition extends IBaseCubeQueryDefinition
IBaseExpression expr ) throws DataException;
/**
+ * Create a calculated measure which is dynamically created during the population
+ * of CubeCursor.
+ *
+ * @param measureName
+ * @param expr
+ * @return
+ * @throws DataException
+ */
+ public IDerivedMeasureDefinition createDerivedMeasure( String measureName, int type,
+ IBaseExpression expr ) throws DataException;
+
+ /**
* Return the list of measures defined.
*
* @return
@@ -123,6 +135,12 @@ public interface ICubeQueryDefinition extends IBaseCubeQueryDefinition
public List getComputedMeasures( );
/**
+ * Return the list of calculated measure defined.
+ * @return
+ */
+ public List getDerivedMeasures( );
+
+ /**
* Get the specific EdgeDefn, for each type of Edge there is only one Edge
* instance.
*
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/api/query/IDerivedMeasureDefinition.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/api/query/IDerivedMeasureDefinition.java
new file mode 100644
index 0000000..219af85
--- /dev/null
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/api/query/IDerivedMeasureDefinition.java
@@ -0,0 +1,24 @@
+package org.eclipse.birt.data.engine.olap.api.query;
+
+import org.eclipse.birt.data.engine.api.IBaseExpression;
+import org.eclipse.birt.data.engine.core.DataException;
+
+
+public interface IDerivedMeasureDefinition extends IMeasureDefinition
+{
+ /**
+ * Return the expression of the derived measure.
+ *
+ * @return
+ * @throws DataException
+ */
+ public IBaseExpression getExpression( ) throws DataException;
+
+ /**
+ * Return the type of the derived measure.
+ *
+ * @return
+ * @throws DataException
+ */
+ public int getType() throws DataException;
+}
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/api/query/IMeasureDefinition.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/api/query/IMeasureDefinition.java
index 86ba1f8..73bf4e7 100644
--- a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/api/query/IMeasureDefinition.java
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/api/query/IMeasureDefinition.java
@@ -28,4 +28,16 @@ public interface IMeasureDefinition extends INamedObject
* @param name
*/
public void setAggrFunction( String name );
+
+ /**
+ * Set the data type for this measure.
+ * @param name
+ */
+ public void setDataType( int type );
+
+ /**
+ * get the data type for this measure.
+ * @return
+ */
+ public int getDataType( );
}
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/impl/query/CubeQueryDefinition.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/impl/query/CubeQueryDefinition.java
index 506fe94..0aad3ee 100644
--- a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/impl/query/CubeQueryDefinition.java
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/impl/query/CubeQueryDefinition.java
@@ -27,6 +27,7 @@ import org.eclipse.birt.data.engine.core.DataException;
import org.eclipse.birt.data.engine.olap.api.query.IComputedMeasureDefinition;
import org.eclipse.birt.data.engine.olap.api.query.ICubeOperation;
import org.eclipse.birt.data.engine.olap.api.query.ICubeQueryDefinition;
+import org.eclipse.birt.data.engine.olap.api.query.IDerivedMeasureDefinition;
import org.eclipse.birt.data.engine.olap.api.query.IEdgeDefinition;
import org.eclipse.birt.data.engine.olap.api.query.IMeasureDefinition;
import org.eclipse.birt.data.engine.olap.api.query.NamedObject;
@@ -41,7 +42,7 @@ public class CubeQueryDefinition extends NamedObject
ICubeQueryDefinition
{
private IEdgeDefinition columnEdge, rowEdge, pageEdge;
- private List measureList, bindingList, filterList, sortList, computedMeasureList;
+ private List measureList, bindingList, filterList, sortList, computedMeasureList, derivedMeasureList;
private List<ICubeOperation> cubeOperations;
private String queryResultsID;
private boolean cacheQueryResults;
@@ -61,6 +62,7 @@ public class CubeQueryDefinition extends NamedObject
this.filterList = new ArrayList();
this.sortList = new ArrayList();
this.computedMeasureList = new ArrayList();
+ this.derivedMeasureList = new ArrayList();
this.cubeOperations = new ArrayList<ICubeOperation>();
this.cacheQueryResults = false;
}
@@ -255,6 +257,15 @@ public class CubeQueryDefinition extends NamedObject
{
return this.measureList;
}
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.birt.data.engine.olap.api.query.ICubeQueryDefinition#getMeasures()
+ */
+ public List getDerivedMeasures( )
+ {
+ return this.derivedMeasureList;
+ }
/*
* (non-Javadoc)
@@ -330,6 +341,18 @@ public class CubeQueryDefinition extends NamedObject
/*
* (non-Javadoc)
+ * @see org.eclipse.birt.data.engine.olap.api.query.ICubeQueryDefinition#createCalculatedMeasure(java.lang.String, int, org.eclipse.birt.data.engine.api.IBaseExpression)
+ */
+ public IDerivedMeasureDefinition createDerivedMeasure( String measureName, int type,
+ IBaseExpression expr ) throws DataException
+ {
+ DerivedMeasureDefinition dmd = new DerivedMeasureDefinition( measureName, type, expr );
+ this.derivedMeasureList.add( dmd );
+ return dmd;
+ }
+
+ /*
+ * (non-Javadoc)
* @see org.eclipse.birt.data.engine.olap.api.query.ICubeQueryDefinition#getComputedMeasures()
*/
public List getComputedMeasures( )
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/impl/query/DerivedMeasureDefinition.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/impl/query/DerivedMeasureDefinition.java
new file mode 100644
index 0000000..669c084
--- /dev/null
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/impl/query/DerivedMeasureDefinition.java
@@ -0,0 +1,44 @@
+package org.eclipse.birt.data.engine.olap.impl.query;
+
+import org.eclipse.birt.data.engine.api.IBaseExpression;
+import org.eclipse.birt.data.engine.olap.api.query.IDerivedMeasureDefinition;
+
+
+public class DerivedMeasureDefinition extends MeasureDefinition implements IDerivedMeasureDefinition
+{
+ //
+ private IBaseExpression expr;
+ private int type;
+
+ /**
+ * Constructor.
+ *
+ * @param name
+ * @param type
+ * @param expr
+ */
+ public DerivedMeasureDefinition( String name, int type, IBaseExpression expr )
+ {
+ super( name );
+ this.expr = expr;
+ this.type = type;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.birt.data.engine.olap.api.query.IComputedMeasureDefinition#getExpression()
+ */
+ public IBaseExpression getExpression( )
+ {
+ return this.expr;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.birt.data.engine.olap.api.query.IComputedMeasureDefinition#getType()
+ */
+ public int getType()
+ {
+ return this.type;
+ }
+}
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/impl/query/MeasureDefinition.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/impl/query/MeasureDefinition.java
index 650c8ec..f24c0e6 100644
--- a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/impl/query/MeasureDefinition.java
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/impl/query/MeasureDefinition.java
@@ -21,7 +21,7 @@ import org.eclipse.birt.data.engine.olap.api.query.NamedObject;
public class MeasureDefinition extends NamedObject implements IMeasureDefinition
{
private String aggrFunction;
-
+ private int dataType;
/**
*
* @param name
@@ -48,5 +48,21 @@ public class MeasureDefinition extends NamedObject implements IMeasureDefinition
{
return this.aggrFunction;
}
-
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.birt.data.engine.olap.api.query.IMeasureDefinition#setDataType(java.lang.Integer)
+ */
+ public void setDataType( int type )
+ {
+ this.dataType = type;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.birt.data.engine.olap.api.query.IMeasureDefinition#getDataType()
+ */
+ public int getDataType( )
+ {
+ return this.dataType;
+ }
}
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/impl/query/PreparedCubeQueryDefinition.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/impl/query/PreparedCubeQueryDefinition.java
index bd7598f..a80b6bf 100644
--- a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/impl/query/PreparedCubeQueryDefinition.java
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/impl/query/PreparedCubeQueryDefinition.java
@@ -16,6 +16,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -25,9 +26,12 @@ import org.eclipse.birt.data.engine.api.IBaseExpression;
import org.eclipse.birt.data.engine.api.IBinding;
import org.eclipse.birt.data.engine.api.IFilterDefinition;
import org.eclipse.birt.data.engine.api.ISortDefinition;
+import org.eclipse.birt.data.engine.api.querydefn.Binding;
+import org.eclipse.birt.data.engine.api.querydefn.ScriptExpression;
import org.eclipse.birt.data.engine.core.DataException;
import org.eclipse.birt.data.engine.expression.ExpressionCompilerUtil;
import org.eclipse.birt.data.engine.i18n.ResourceConstants;
+import org.eclipse.birt.data.engine.impl.document.ExprUtil;
import org.eclipse.birt.data.engine.impl.util.DirectedGraph;
import org.eclipse.birt.data.engine.impl.util.DirectedGraphEdge;
import org.eclipse.birt.data.engine.impl.util.GraphNode;
@@ -35,8 +39,10 @@ import org.eclipse.birt.data.engine.impl.util.DirectedGraph.CycleFoundException;
import org.eclipse.birt.data.engine.olap.api.query.IComputedMeasureDefinition;
import org.eclipse.birt.data.engine.olap.api.query.ICubeOperation;
import org.eclipse.birt.data.engine.olap.api.query.ICubeQueryDefinition;
+import org.eclipse.birt.data.engine.olap.api.query.IDerivedMeasureDefinition;
import org.eclipse.birt.data.engine.olap.api.query.IEdgeDefinition;
import org.eclipse.birt.data.engine.olap.api.query.IMeasureDefinition;
+import org.eclipse.birt.data.engine.olap.data.api.DimLevel;
import org.eclipse.birt.data.engine.olap.util.OlapExpressionUtil;
@@ -83,12 +89,204 @@ public class PreparedCubeQueryDefinition implements ICubeQueryDefinition
}
realBindings.add( binding );
}
+
+ List calculatedMeasures = cqd.getDerivedMeasures( );
+ if ( calculatedMeasures != null && calculatedMeasures.size( ) > 0 )
+ createBindingsForCalculatedMeasures( cqd );
+
List<ICubeOperation> convertedCubeOperations = getConvertedCubeOperations( );
List<ICubeOperation> all = new ArrayList<ICubeOperation>( Arrays.asList( cqd.getCubeOperations( )));
all.addAll( convertedCubeOperations );
realCubeOperations = all.toArray( new ICubeOperation[0] );
}
+ private String getRollUpAggregationFunctionName( String function )
+ {
+ if ( function.equalsIgnoreCase( "COUNT" )
+ || function.equalsIgnoreCase( "COUNTDISTINCT" )
+ || function.equalsIgnoreCase( "AVE" ) )
+ {
+ return "SUM";
+ }
+ return function;
+ }
+
+ private IBinding getSameBindingInQuery( IBinding binding, List bindings ) throws DataException
+ {
+ for ( int i = 0; i < bindings.size( ); i++ )
+ {
+ IBinding b = (IBinding) bindings.get( i );
+ if ( b.getDataType( ) != binding.getDataType( ) )
+ {
+ continue;
+ }
+ if ( binding.getAggrFunction( ) != null
+ && ( !( binding.getAggrFunction( ).equals( b.getAggrFunction( ) ) ) ) )
+ {
+ continue;
+ }
+ if ( !ExprUtil.isEqualExpression( b.getExpression( ),
+ binding.getExpression( ) ) )
+ {
+ continue;
+ }
+ if ( !ExprUtil.isEqualExpression( b.getFilter( ),
+ binding.getFilter( ) ) )
+ {
+ continue;
+ }
+ if ( b.getArguments( ).size( ) != binding.getArguments( ).size( ) )
+ {
+ continue;
+ }
+ Iterator itr1 = b.getArguments( ).iterator( );
+ Iterator itr2 = binding.getArguments( ).iterator( );
+ while ( itr1.hasNext( ) )
+ {
+ IBaseExpression expr1 = (IBaseExpression) itr1.next( );
+ IBaseExpression expr2 = (IBaseExpression) itr2.next( );
+ if ( !ExprUtil.isEqualExpression( expr1, expr2 ) )
+ {
+ continue;
+ }
+ }
+ if ( !Arrays.deepEquals( b.getAggregatOns( ).toArray( ),
+ binding.getAggregatOns( ).toArray( ) ) )
+ {
+ continue;
+ }
+ return b;
+ }
+
+ return null;
+ }
+
+ private void createBindingsForCalculatedMeasures(
+ ICubeQueryDefinition cqd ) throws DataException
+ {
+ List<String> levelNames = new ArrayList( );
+ List aggrOns = org.eclipse.birt.data.engine.olap.query.view.CubeQueryDefinitionUtil.populateMeasureAggrOns( cqd );
+ for ( int i = 0; i < aggrOns.size( ); i++ )
+ {
+ DimLevel level = (DimLevel) aggrOns.get( i );
+ levelNames.add( ExpressionUtil.createJSDimensionExpression( level.getDimensionName( ),
+ level.getLevelName( ) ) );
+ }
+
+ List measures = cqd.getMeasures( );
+ Map measureMap = new HashMap( );
+ for ( int i = 0; i < measures.size( ); i++ )
+ {
+ measureMap.put( ( (MeasureDefinition) measures.get( i ) ).getName( ),
+ measures.get( i ) );
+ }
+ List calculatedMeasures = cqd.getDerivedMeasures( );
+ Map derivedMeasureMap = new HashMap( );
+ for ( int i = 0; i < calculatedMeasures.size( ); i++ )
+ {
+ derivedMeasureMap.put( ( (DerivedMeasureDefinition) calculatedMeasures.get( i ) ).getName( ),
+ calculatedMeasures.get( i ) );
+ }
+
+ Map createdBindings = new HashMap();
+ List bindingsInCubeQuery = cqd.getBindings( );
+
+ //step 1: find the actual measures that a calculated measure refers to. And create internal bindings for them.
+ for ( int i = 0; i < calculatedMeasures.size( ); i++ )
+ {
+ DerivedMeasureDefinition measureDefinition = (DerivedMeasureDefinition) calculatedMeasures.get( i );
+ List referencedMeasures = ExpressionCompilerUtil.extractColumnExpression( measureDefinition.getExpression( ),
+ ExpressionUtil.MEASURE_INDICATOR );
+ for ( int j = 0; j < referencedMeasures.size( ); j++ )
+ {
+ String measureName = referencedMeasures.get( j ).toString( );
+ if ( measureMap.containsKey( measureName ) )
+ {
+ if ( !createdBindings.containsKey( measureName ) )
+ {
+ MeasureDefinition md = (MeasureDefinition) measureMap.get( measureName );
+ IBinding newBinding = new Binding( "temp_"
+ + measureName );
+ newBinding.setDataType( md.getDataType( ) );
+ newBinding.setExpression( new ScriptExpression( ExpressionUtil.createJSMeasureExpression( measureName ) ) );
+ newBinding.setAggrFunction( getRollUpAggregationFunctionName( md.getAggrFunction( ) ) );
+ for ( int a = 0; a < levelNames.size( ); a++ )
+ newBinding.addAggregateOn( levelNames.get( a ) );
+
+ IBinding b = getSameBindingInQuery( newBinding,
+ bindingsInCubeQuery );
+ if ( b != null )
+ {
+ createdBindings.put( measureName, b );
+ }
+ else
+ {
+ createdBindings.put( measureName, newBinding );
+ realBindings.add( newBinding );
+ }
+ }
+ }
+ }
+ }
+
+ //step 2: replace all the expression texts in those bindings in cube query if necessary
+ for ( int i = 0; i < bindingsInCubeQuery.size( ); i++ )
+ {
+ IBinding binding = (IBinding) bindingsInCubeQuery.get( i );
+ ScriptExpression expression = (ScriptExpression) binding.getExpression( );
+ List measureName = ExpressionCompilerUtil.extractColumnExpression( expression,
+ ExpressionUtil.MEASURE_INDICATOR );
+ if ( measureName != null && measureName.size( ) > 0
+ && derivedMeasureMap.containsKey( measureName.get( 0 )
+ .toString( ) ) )
+ {
+ expression.setText( "("
+ + ( (ScriptExpression) ( (DerivedMeasureDefinition) derivedMeasureMap.get( measureName.get( 0 )
+ .toString( ) ) ).getExpression( ) ).getText( )
+ + ")" );
+ expression.setText( getReplacedExpressionText( expression.getText( ),
+ measureMap,
+ derivedMeasureMap, createdBindings ) );
+ expression.setText( expression.getText( ).substring( 1,
+ expression.getText( ).length( ) - 1 ) );
+ binding.getAggregatOns( ).clear( );
+ binding.setAggrFunction( null );
+ }
+ }
+ }
+
+ private String getReplacedExpressionText( String text, Map measureMap,
+ Map derivedMeasureMap, Map createdBindings ) throws DataException
+ {
+ List measureNames = ExpressionCompilerUtil.extractColumnExpression( new ScriptExpression( text ),
+ ExpressionUtil.MEASURE_INDICATOR );
+
+ for ( int i = 0; i < measureNames.size( ); i++ )
+ {
+ if ( measureMap.containsKey( measureNames.get( i ).toString( ) ) )
+ {
+ text = text.replace( ExpressionUtil.createJSMeasureExpression( measureNames.get( i )
+ .toString( ) ),
+ ExpressionUtil.createJSDataExpression( ( (IBinding) createdBindings.get( measureNames.get( i )
+ .toString( ) ) ).getBindingName( ) ) );
+ }
+ else if ( derivedMeasureMap.containsKey( measureNames.get( i )
+ .toString( ) ) )
+ {
+ text = text.replace( ExpressionUtil.createJSMeasureExpression( measureNames.get( i )
+ .toString( ) ),
+ "(" + ( (ScriptExpression) ( (DerivedMeasureDefinition) derivedMeasureMap.get( measureNames.get( i )
+ .toString( ) ) ).getExpression( ) ).getText( )
+ + ")" );
+ text = getReplacedExpressionText( text,
+ measureMap,
+ derivedMeasureMap, createdBindings );
+ }
+ }
+
+ return text;
+ }
+
public ICubeQueryDefinition getCubeQueryDefinition( )
{
return this.cqd;
@@ -178,6 +376,13 @@ public class PreparedCubeQueryDefinition implements ICubeQueryDefinition
{
return cqd.createComputedMeasure( measureName, type, expr );
}
+
+ public IDerivedMeasureDefinition createDerivedMeasure(
+ String measureName, int type, IBaseExpression expr )
+ throws DataException
+ {
+ return cqd.createDerivedMeasure( measureName, type, expr );
+ }
public IEdgeDefinition createEdge( int type )
{
@@ -228,6 +433,11 @@ public class PreparedCubeQueryDefinition implements ICubeQueryDefinition
{
return cqd.getMeasures( );
}
+
+ public List getDerivedMeasures( )
+ {
+ return cqd.getDerivedMeasures( );
+ }
public String getQueryResultsID( )
{
diff --git a/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/impl/DataRequestSessionImpl.java b/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/impl/DataRequestSessionImpl.java
index a22bb89..c8273b3 100644
--- a/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/impl/DataRequestSessionImpl.java
+++ b/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/impl/DataRequestSessionImpl.java
@@ -139,7 +139,7 @@ public class DataRequestSessionImpl extends DataRequestSession
private DataEngineImpl dataEngine;
private IModelAdapter modelAdaptor;
private DataSessionContext sessionContext;
- private Map cubeHandleMap;
+ private Map cubeHandleMap, cubeMetaDataHandleMap;
private Map<ReportElementHandle, QueryDefinition> cubeQueryMap = new HashMap<ReportElementHandle, QueryDefinition>();
private Map<ReportElementHandle, List<ColumnMeta>> cubeMetaMap = new HashMap<ReportElementHandle, List<ColumnMeta>>();
@@ -184,6 +184,7 @@ public class DataRequestSessionImpl extends DataRequestSession
sessionContext = context;
cubeHandleMap = new HashMap( );
+ cubeMetaDataHandleMap = new HashMap( );
createdDimensions = new HashMap<String, IDimension>( );
if( sessionContext!= null )
{
@@ -680,6 +681,7 @@ public class DataRequestSessionImpl extends DataRequestSession
public void defineCube( CubeHandle cubeHandle ) throws BirtException
{
CubeHandleUtil.defineCube( dataEngine, cubeHandle, this.sessionContext.getAppContext( ) );
+ this.cubeMetaDataHandleMap.put( cubeHandle.getQualifiedName( ), cubeHandle );
ICubeInterceptor cubeInterceptor = CubeInterceptorFinder.find( cubeHandle );
if ( cubeInterceptor != null )
@@ -802,7 +804,10 @@ public class DataRequestSessionImpl extends DataRequestSession
for ( int j = 0; j < measures.size( ); j++ )
{
MeasureHandle measure = (MeasureHandle) measures.get( j );
- measureNames.add( measure.getName( ) );
+ if( !measure.isCalculated( ) )
+ {
+ measureNames.add( measure.getName( ) );
+ }
}
}
@@ -1621,12 +1626,32 @@ public class DataRequestSessionImpl extends DataRequestSession
Map appContext ) throws BirtException
{
refactorCubeQueryDefinition( query );
+ setMeasureDataTypeForCubeQuery ( query );
QueryAdapter.adaptQuery( query );
dataEngine.getSession( ).getStopSign( ).start( );
setModuleHandleToAppContext( appContext );
return this.dataEngine.prepare( query, appContext );
}
+
+ private void setMeasureDataTypeForCubeQuery( ICubeQueryDefinition query )
+ {
+ List measures = query.getMeasures( );
+
+ if ( this.cubeMetaDataHandleMap != null
+ && this.cubeMetaDataHandleMap.containsKey( query.getName( ) ) )
+ {
+ CubeHandle cubeHandle = (CubeHandle) this.cubeMetaDataHandleMap.get( query.getName( ) );
+
+ for ( int i = 0; i < measures.size( ); i++ )
+ {
+ IMeasureDefinition measureDef = ( IMeasureDefinition ) measures.get( i );
+ MeasureHandle measureHandle = cubeHandle.getMeasure( measureDef.getName( ) );
+ if ( measureHandle != null )
+ measureDef.setDataType( DataAdapterUtil.adaptModelDataType( measureHandle.getDataType( ) ) );
+ }
+ }
+ }
private void refactorCubeQueryDefinition( ICubeQueryDefinition query )
throws DataException, AdapterException