summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlzhang2012-03-19 22:37:32 (EDT)
committer mwu2012-03-19 22:37:32 (EDT)
commit298d1f122f0193f4ff5822c4b66b85e040ea360f (patch)
tree993aa020bf84399257f7d669dcbceb69915d59d2
parenteda8da6775fbb91e52331402625fe026cc37b96c (diff)
downloadorg.eclipse.birt-298d1f122f0193f4ff5822c4b66b85e040ea360f.zip
org.eclipse.birt-298d1f122f0193f4ff5822c4b66b85e040ea360f.tar.gz
org.eclipse.birt-298d1f122f0193f4ff5822c4b66b85e040ea360f.tar.bz2
Exception occur when filter use "value from level" and not recalculate
totals[48084], result of filter use "value from level" is not correct [48086]
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/api/CubeQueryExecutorHelper.java138
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/AggregationResultRowComparator.java2
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/query/view/QueryExecutor.java34
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/util/filter/JSFacttableFilterEvalHelper.java5
4 files changed, 178 insertions, 1 deletions
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/api/CubeQueryExecutorHelper.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/api/CubeQueryExecutorHelper.java
index 85b043c..dcc0cec 100644
--- a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/api/CubeQueryExecutorHelper.java
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/api/CubeQueryExecutorHelper.java
@@ -28,22 +28,27 @@ import org.eclipse.birt.core.archive.FileArchiveWriter;
import org.eclipse.birt.core.archive.IDocArchiveReader;
import org.eclipse.birt.core.archive.IDocArchiveWriter;
import org.eclipse.birt.core.exception.BirtException;
+import org.eclipse.birt.data.engine.api.IBaseExpression;
import org.eclipse.birt.data.engine.api.IShutdownListener;
import org.eclipse.birt.data.engine.cache.Constants;
import org.eclipse.birt.data.engine.core.DataException;
+import org.eclipse.birt.data.engine.i18n.DataResourceHandle;
import org.eclipse.birt.data.engine.i18n.ResourceConstants;
import org.eclipse.birt.data.engine.impl.DataEngineSession;
import org.eclipse.birt.data.engine.impl.StopSign;
import org.eclipse.birt.data.engine.impl.document.stream.VersionManager;
+import org.eclipse.birt.data.engine.olap.api.query.CubeFilterDefinition;
import org.eclipse.birt.data.engine.olap.data.api.cube.ICube;
import org.eclipse.birt.data.engine.olap.data.api.cube.IDimension;
import org.eclipse.birt.data.engine.olap.data.document.IDocumentManager;
import org.eclipse.birt.data.engine.olap.data.impl.AggregationDefinition;
+import org.eclipse.birt.data.engine.olap.data.impl.AggregationFunctionDefinition;
import org.eclipse.birt.data.engine.olap.data.impl.AggregationResultSetSaveUtil;
import org.eclipse.birt.data.engine.olap.data.impl.Cube;
import org.eclipse.birt.data.engine.olap.data.impl.SecuredCube;
import org.eclipse.birt.data.engine.olap.data.impl.aggregation.AggregationExecutor;
import org.eclipse.birt.data.engine.olap.data.impl.aggregation.AggregationResultRow;
+import org.eclipse.birt.data.engine.olap.data.impl.aggregation.AggregationResultRowComparator;
import org.eclipse.birt.data.engine.olap.data.impl.aggregation.AggregationResultSet;
import org.eclipse.birt.data.engine.olap.data.impl.aggregation.CubeDimensionReader;
import org.eclipse.birt.data.engine.olap.data.impl.aggregation.DataSetFromOriginalCube;
@@ -64,10 +69,14 @@ import org.eclipse.birt.data.engine.olap.data.impl.facttable.FactTableRowIterato
import org.eclipse.birt.data.engine.olap.data.util.BufferedStructureArray;
import org.eclipse.birt.data.engine.olap.data.util.DiskSortedStack;
import org.eclipse.birt.data.engine.olap.data.util.IDiskArray;
+import org.eclipse.birt.data.engine.olap.impl.query.CubeQueryExecutor;
+import org.eclipse.birt.data.engine.olap.util.OlapExpressionCompiler;
+import org.eclipse.birt.data.engine.olap.util.filter.BaseDimensionFilterEvalHelper;
import org.eclipse.birt.data.engine.olap.util.filter.IAggrMeasureFilterEvalHelper;
import org.eclipse.birt.data.engine.olap.util.filter.ICubePosFilter;
import org.eclipse.birt.data.engine.olap.util.filter.IJSFacttableFilterEvalHelper;
import org.eclipse.birt.data.engine.olap.util.filter.IJSFilterHelper;
+import org.eclipse.birt.data.engine.olap.util.filter.JSFacttableFilterEvalHelper;
import org.eclipse.birt.data.engine.olap.util.sort.IJSSortHelper;
/**
@@ -100,6 +109,7 @@ public class CubeQueryExecutorHelper implements ICubeQueryExcutorHelper
public long memoryCacheSize = 0;
private IBindingValueFetcher fetcher;
+ private CubeQueryExecutor cubeQueryExecutor;
/**
*
* @param cube
@@ -470,6 +480,8 @@ public class CubeQueryExecutorHelper implements ICubeQueryExcutorHelper
IAggregationResultSet[] resultSet = onePassExecute( aggregations,
stopSign );
+ resultSet = processDimensionFiltersInAggrBindingFilter( resultSet );
+
applyAggrFilters( aggregations, resultSet, stopSign );
applyAggrSort( resultSet );
@@ -477,6 +489,132 @@ public class CubeQueryExecutorHelper implements ICubeQueryExcutorHelper
return resultSet;
}
+
+ public void setCubeQueryExecutor(CubeQueryExecutor executor)
+ {
+ this.cubeQueryExecutor = executor;
+ }
+
+ private IAggregationResultSet[] processDimensionFiltersInAggrBindingFilter(IAggregationResultSet[] rs) throws IOException, BirtException
+ {
+ for( int i = 0; i< rs.length ; i++ )
+ {
+ AggregationFunctionDefinition[] functions = rs[i].getAggregationDefinition().getAggregationFunctions();
+
+ if(functions != null)
+ {
+ IAggregationResultSet[] subAggrRs = new IAggregationResultSet[functions.length];
+ boolean applyMerge = false;
+ for (int j = 0; j < functions.length; j++)
+ {
+ if (functions[j].getFilterEvalHelper() != null && functions[j].getFilterEvalHelper() instanceof JSFacttableFilterEvalHelper)
+ {
+
+ IBaseExpression expr = ((JSFacttableFilterEvalHelper) functions[j]
+ .getFilterEvalHelper()).getFilterExpression();
+ Set dimLevelSet = OlapExpressionCompiler
+ .getReferencedDimLevel(expr, cubeQueryExecutor
+ .getCubeQueryDefinition().getBindings());
+ if (dimLevelSet.size() > 0)
+ {
+ applyMerge = true;
+ CubeQueryExecutorHelper executorHelper = new CubeQueryExecutorHelper(
+ this.cube, cubeQueryExecutor.getComputedMeasureHelper(),fetcher);
+
+ executorHelper.setBreakHierarchy(cubeQueryExecutor.getCubeQueryDefinition().getFilterOption() == 0);
+ CubeFilterDefinition cubeFilter = new CubeFilterDefinition(
+ expr);
+ executorHelper.addJSFilter(BaseDimensionFilterEvalHelper.createFilterHelper(
+ cubeQueryExecutor.getOuterResults(),
+ cubeQueryExecutor.getScope(), cubeQueryExecutor
+ .getCubeQueryDefinition(),
+ cubeFilter, cubeQueryExecutor.getContext()
+ .getScriptContext()));
+
+ AggregationDefinition[] aggregations = new AggregationDefinition[1];
+ AggregationFunctionDefinition[] func = new AggregationFunctionDefinition[1];
+ func[0] = new AggregationFunctionDefinition("temp_"
+ + functions[j].getName(),
+ functions[j].getMeasureName(),
+ functions[j].getFunctionName());
+ aggregations[0] = new AggregationDefinition(rs[i]
+ .getAggregationDefinition().getLevels(),
+ rs[i].getAggregationDefinition()
+ .getSortTypes(), func);
+
+ IAggregationResultSet[] result = executorHelper
+ .execute(aggregations, cubeQueryExecutor
+ .getSession().getStopSign());
+ subAggrRs[j] = result[0];
+ }
+ }
+ }
+
+ if(applyMerge)
+ {
+ mergeAggrResultsSetsResult(rs[i],subAggrRs);
+ }
+ }
+ }
+ return rs;
+ }
+
+ private int[] getKeyLevelIndexs( DimLevel[] keyLevels, IAggregationResultSet rs ) throws DataException
+ {
+ int[] keyLevelIndexes = new int[keyLevels.length];
+ DimLevel[] allLevels = rs.getAllLevels( );
+ for ( int i = 0; i < keyLevels.length; i++ )
+ {
+ keyLevelIndexes[i] = -1;
+ for ( int j = 0; j < allLevels.length; j++ )
+ {
+ if ( keyLevels[i].equals( allLevels[j] ) )
+ keyLevelIndexes[i] = j;
+ }
+ if( keyLevelIndexes[i] == -1 )
+ {
+ throw new DataException( DataResourceHandle.getInstance( )
+ .getMessage( ResourceConstants.NONEXISTENT_LEVEL )
+ + keyLevels[i].getLevelName( ) );
+ }
+ }
+ return keyLevelIndexes;
+ }
+
+
+ private void mergeAggrResultsSetsResult(IAggregationResultSet source, IAggregationResultSet[] result) throws IOException, DataException
+ {
+ IDiskArray sourceRows = ((AggregationResultSet)source).getAggregationResultRows();
+ AggregationResultRowComparator comparator = new AggregationResultRowComparator(getKeyLevelIndexs(source.getAggregationDefinition().getLevels(),source),source.getSortType());
+ for( int i = 0 ; i< source.length(); i++)
+ {
+ IAggregationResultRow row = (IAggregationResultRow)sourceRows.get(i);
+
+
+ for( int j = 0; j< result.length; j++)
+ {
+ IAggregationResultSet rs = result[j];
+ if(rs == null)
+ continue;
+ IDiskArray subRows = ((AggregationResultSet)rs).getAggregationResultRows();
+ boolean find = false;
+ for( int k = 0 ; k<subRows.size();k++)
+ {
+ IAggregationResultRow subRow = (IAggregationResultRow)subRows.get(k);
+ if(comparator.compare(row, subRow) == 0)
+ {
+ find = true;
+ row.getAggregationValues()[j] = subRow.getAggregationValues()[0];
+ break;
+ }
+ }
+ if(!find)
+ row.getAggregationValues()[j] = null;
+ }
+
+ }
+ }
+
/**
*
* @param aggregations
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/AggregationResultRowComparator.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/AggregationResultRowComparator.java
index 148972e..b634cd1 100644
--- a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/AggregationResultRowComparator.java
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/AggregationResultRowComparator.java
@@ -26,7 +26,7 @@ public class AggregationResultRowComparator implements Comparator<IAggregationRe
private int[] keyLevelIndexs;
private int[] sortTypes;
- AggregationResultRowComparator( int[] keyLevelIndexs, int[] sortTypes )
+ public AggregationResultRowComparator( int[] keyLevelIndexs, int[] sortTypes )
{
this.keyLevelIndexs = keyLevelIndexs;
this.sortTypes = sortTypes;
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/query/view/QueryExecutor.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/query/view/QueryExecutor.java
index 94d363d..d708d4d 100644
--- a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/query/view/QueryExecutor.java
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/query/view/QueryExecutor.java
@@ -140,6 +140,7 @@ public class QueryExecutor
cube );
cubeQueryExecutorHelper = new CubeQueryExecutorHelper( cube,
executor.getComputedMeasureHelper( ), fetcher );
+ cubeQueryExecutorHelper.setCubeQueryExecutor( executor );
cubeQueryExecutorHelper.setMemoryCacheSize( CacheUtil.computeMemoryBufferSize( view.getAppContext( ) ) );
cubeQueryExecutorHelper.setMaxDataObjectRows( CacheUtil.getMaxRows( view.getAppContext( ) ) );
@@ -355,10 +356,41 @@ public class QueryExecutor
rs[affectedAggrResultSetIndex.get( j ).intValue( )] );
}
}
+
+ if( edgeResultSet.size( ) > 1 )
+ {
+ combineEdgeResultSetsInfo( edgeResultSet );
+ }
}
return rs;
}
+
+ private void combineEdgeResultSetsInfo( List<IAggregationResultSet> edgeResultSet )
+ {
+ int index = -1;
+ for( int i = 0; i < edgeResultSet.size( ); i++ )
+ {
+ IAggregationResultSet rs = edgeResultSet.get( i );
+ if( rs.length() == 0 )
+ index = i;
+ }
+ if( index >= 0 )
+ {
+ for( int i = 0; i < edgeResultSet.size( ); i++ )
+ {
+ if ( i != index )
+ {
+ IAggregationResultSet rs = edgeResultSet.get( i );
+ IDiskArray newRsRows = new BufferedStructureArray( AggregationResultRow.getCreator( ), rs.length( ) );
+ if ( rs instanceof AggregationResultSet )
+ ( (AggregationResultSet) rs ).setAggregationResultRows( newRsRows );
+ else if (rs instanceof CachedAggregationResultSet)
+ ( (CachedAggregationResultSet) rs ).setAggregationResultRows( newRsRows );
+ }
+ }
+ }
+ }
private List<IAggregationResultSet> populateAndFilterEdgeResultSet(IAggregationResultSet[] rs,
Map<DimLevel, IJSFacttableFilterEvalHelper> edgeDrillFilterMap)
@@ -486,6 +518,8 @@ public class QueryExecutor
joinLevelKeys = joinRS.getLevelKeys( );
int pos = getPos(joinLevelKeys, detailLevelKeys);
+ if( pos < 0 )
+ return;
for (int index = 0; index < detailRS.length( ); index++)
{
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/util/filter/JSFacttableFilterEvalHelper.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/util/filter/JSFacttableFilterEvalHelper.java
index 31d7d67..2fbf787 100644
--- a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/util/filter/JSFacttableFilterEvalHelper.java
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/util/filter/JSFacttableFilterEvalHelper.java
@@ -54,6 +54,11 @@ public class JSFacttableFilterEvalHelper implements IJSFacttableFilterEvalHelper
initialize( parentScope, cubeFilter, cx, outerResults, query );
}
+ public IBaseExpression getFilterExpression()
+ {
+ return this.expr;
+ }
+
/**
*
* @param parentScope