summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpeng.shi2011-09-27 04:08:52 (EDT)
committer xgu2011-09-27 04:08:52 (EDT)
commitb6a893f00fcab247f00f39cfc2487df934cc60a2 (patch)
tree7e1323e120b3a57a3c4c974f522e302f1f42534b
parent61f18bbc6902596e3bb8b159bcbcf96dd1bc08c7 (diff)
downloadorg.eclipse.birt-b6a893f00fcab247f00f39cfc2487df934cc60a2.zip
org.eclipse.birt-b6a893f00fcab247f00f39cfc2487df934cc60a2.tar.gz
org.eclipse.birt-b6a893f00fcab247f00f39cfc2487df934cc60a2.tar.bz2
add MDX function and unit test for relative time period analysis
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/MonthToDateTest.java163
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TrailingTest.java194
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/WeekToDateTest.java114
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD1.txt42
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD2.txt42
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD3.txt8
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD4.txt8
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD5.txt20
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD6.txt44
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD7.txt2
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing1.txt6
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing2.txt6
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing3.txt6
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing4.txt6
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing5.txt6
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing6.txt6
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing7.txt6
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/WeekToDateTest.testWTD1.txt10
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/WeekToDateTest.testWTD2.txt10
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/WeekToDateTest.testWTD3.txt14
-rw-r--r--data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/WeekToDateTest.testWTD4.txt2
-rw-r--r--data/org.eclipse.birt.data/META-INF/MANIFEST.MF1
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/AbstractMDX.java146
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/IParallelPeriod.java8
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/IPeriodsFunction.java10
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/MonthToDateFunction.java69
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TimeFunctionFactory.java19
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TimeMember.java42
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TrailingFunction.java83
-rw-r--r--data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/WeekToDateFunciton.java55
30 files changed, 1148 insertions, 0 deletions
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/MonthToDateTest.java b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/MonthToDateTest.java
new file mode 100644
index 0000000..15ca2bd
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/MonthToDateTest.java
@@ -0,0 +1,163 @@
+
+package org.eclipse.birt.data.engine.olap.data.impl.aggregation.function;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.eclipse.birt.data.engine.olap.data.impl.aggregation.function.MonthToDateFunction;
+import org.eclipse.birt.data.engine.olap.data.impl.aggregation.function.TimeMember;
+
+import testutil.BaseTestCase;
+
+/**
+ * this class test month to date funciton, you can refer to MonthToDateFunction
+ * for details
+ *
+ * @author peng.shi
+ *
+ */
+public class MonthToDateTest extends BaseTestCase
+{
+
+ public void testMTD1( ) throws IOException
+ {
+ int[] values = new int[]{
+ 2002, 3, 21
+ };
+ String[] types = new String[]{
+ TimeMember.TIME_LEVEL_TYPE_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_MONTH
+ };
+ TimeMember timeMember = new TimeMember( values, types );
+ List<TimeMember> timeMembers = new MonthToDateFunction( ).getResult( timeMember );
+ printMembers( timeMembers );
+ checkOutputFile( );
+ }
+
+ public void testMTD2( ) throws IOException
+ {
+ int[] values = new int[]{
+ 2002, 1, 3, 21
+ };
+ String[] types = new String[]{
+ TimeMember.TIME_LEVEL_TYPE_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_QUARTER,
+ TimeMember.TIME_LEVEL_TYPE_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_MONTH
+ };
+ TimeMember timeMember = new TimeMember( values, types );
+ List<TimeMember> timeMembers = new MonthToDateFunction( ).getResult( timeMember );
+ printMembers( timeMembers );
+ checkOutputFile( );
+ }
+
+ public void testMTD3( ) throws IOException
+ {
+ int[] values = new int[]{
+ 2011, 3, 9, 4
+ };
+ String[] types = new String[]{
+ TimeMember.TIME_LEVEL_TYPE_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_QUARTER,
+ TimeMember.TIME_LEVEL_TYPE_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH
+ };
+ TimeMember timeMember = new TimeMember( values, types );
+ List<TimeMember> timeMembers = new MonthToDateFunction( ).getResult( timeMember );
+ printMembers( timeMembers );
+ checkOutputFile( );
+
+ }
+
+ public void testMTD4( ) throws IOException
+ {
+ int[] values = new int[]{
+ 2002, 1, 2, 4
+ };
+ String[] types = new String[]{
+ TimeMember.TIME_LEVEL_TYPE_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_QUARTER,
+ TimeMember.TIME_LEVEL_TYPE_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH
+ };
+ TimeMember timeMember = new TimeMember( values, types );
+ List<TimeMember> timeMembers = new MonthToDateFunction( ).getResult( timeMember );
+ printMembers( timeMembers );
+ checkOutputFile( );
+
+ }
+
+ public void testMTD5( ) throws IOException
+ {
+ int[] values = new int[]{
+ 2002, 100
+ };
+ String[] types = new String[]{
+ TimeMember.TIME_LEVEL_TYPE_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_YEAR
+ };
+ TimeMember timeMember = new TimeMember( values, types );
+ List<TimeMember> timeMembers = new MonthToDateFunction( ).getResult( timeMember );
+ printMembers( timeMembers );
+ checkOutputFile( );
+ }
+
+ public void testMTD6( ) throws IOException
+ {
+ int[] values = new int[]{
+ 2011, 3, 9, 4, 39, 5, 22, 265
+ };
+ String[] types = new String[]{
+ TimeMember.TIME_LEVEL_TYPE_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_QUARTER,
+ TimeMember.TIME_LEVEL_TYPE_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_WEEK_OF_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_WEEK,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_YEAR
+ };
+ TimeMember timeMember = new TimeMember( values, types );
+ List<TimeMember> timeMembers = new MonthToDateFunction( ).getResult( timeMember );
+ printMembers( timeMembers );
+ checkOutputFile( );
+ }
+
+ public void testMTD7( ) throws IOException
+ {
+ int[] values = new int[]{
+ 2011, 3, 8
+ };
+ String[] types = new String[]{
+ TimeMember.TIME_LEVEL_TYPE_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_QUARTER,
+ TimeMember.TIME_LEVEL_TYPE_MONTH
+ };
+ TimeMember timeMember = new TimeMember( values, types );
+ List<TimeMember> timeMembers = new MonthToDateFunction( ).getResult( timeMember );
+ printMembers( timeMembers );
+ checkOutputFile( );
+ }
+
+ private void printMembers( List<TimeMember> timeMembers )
+ {
+ String[] levelTypes;
+ int[] memberValues;
+ for ( TimeMember timeMember : timeMembers )
+ {
+ levelTypes = timeMember.getLevelType( );
+ memberValues = timeMember.getMemberValue( );
+ for ( int i = 0; i < levelTypes.length; i++ )
+ {
+ testPrint( levelTypes[i] + " " );
+ }
+ testPrintln( "" );
+ for ( int i = 0; i < memberValues.length; i++ )
+ {
+ testPrint( memberValues[i] + " " );
+ }
+ testPrintln( "" );
+ }
+ }
+}
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TrailingTest.java b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TrailingTest.java
new file mode 100644
index 0000000..f97a3aa
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TrailingTest.java
@@ -0,0 +1,194 @@
+
+package org.eclipse.birt.data.engine.olap.data.impl.aggregation.function;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.eclipse.birt.data.engine.olap.data.impl.aggregation.function.TimeFunctionFactory;
+import org.eclipse.birt.data.engine.olap.data.impl.aggregation.function.TimeMember;
+
+import testutil.BaseTestCase;
+
+/**
+ * this class test the trailing function,you can refer to TrailingFunction for
+ * details.
+ *
+ * @author peng.shi
+ *
+ */
+public class TrailingTest extends BaseTestCase
+{
+
+ public void testTrailing1( ) throws IOException
+ {
+ int[] values = new int[]{
+ 2011, 3, 9, 4, 39, 5, 22, 265
+ };
+ String[] types = new String[]{
+ TimeMember.TIME_LEVEL_TYPE_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_QUARTER,
+ TimeMember.TIME_LEVEL_TYPE_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_WEEK_OF_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_WEEK,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_YEAR
+ };
+ TimeMember timeMember = new TimeMember( values, types );
+ List<TimeMember> timeMembers = TimeFunctionFactory.createTrailingFunction( TimeMember.TIME_LEVEL_TYPE_YEAR,
+ 3 )
+ .getResult( timeMember );
+ printMembers( timeMembers );
+ checkOutputFile( );
+ }
+
+ public void testTrailing2( ) throws IOException
+ {
+ int[] values = new int[]{
+ 2011, 3, 9, 4, 39, 5, 22, 265
+ };
+ String[] types = new String[]{
+ TimeMember.TIME_LEVEL_TYPE_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_QUARTER,
+ TimeMember.TIME_LEVEL_TYPE_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_WEEK_OF_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_WEEK,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_YEAR
+ };
+ TimeMember timeMember = new TimeMember( values, types );
+ List<TimeMember> timeMembers = TimeFunctionFactory.createTrailingFunction( TimeMember.TIME_LEVEL_TYPE_QUARTER,
+ 3 )
+ .getResult( timeMember );
+ printMembers( timeMembers );
+ checkOutputFile( );
+ }
+
+ public void testTrailing3( ) throws IOException
+ {
+ int[] values = new int[]{
+ 2011, 3, 9, 4, 39, 5, 22, 265
+ };
+ String[] types = new String[]{
+ TimeMember.TIME_LEVEL_TYPE_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_QUARTER,
+ TimeMember.TIME_LEVEL_TYPE_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_WEEK_OF_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_WEEK,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_YEAR
+ };
+ TimeMember timeMember = new TimeMember( values, types );
+ List<TimeMember> timeMembers = TimeFunctionFactory.createTrailingFunction( TimeMember.TIME_LEVEL_TYPE_MONTH,
+ 3 )
+ .getResult( timeMember );
+ printMembers( timeMembers );
+ checkOutputFile( );
+ }
+
+ public void testTrailing4( ) throws IOException
+ {
+ int[] values = new int[]{
+ 2011, 3, 9, 4, 39, 5, 22, 265
+ };
+ String[] types = new String[]{
+ TimeMember.TIME_LEVEL_TYPE_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_QUARTER,
+ TimeMember.TIME_LEVEL_TYPE_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_WEEK_OF_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_WEEK,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_YEAR
+ };
+ TimeMember timeMember = new TimeMember( values, types );
+ List<TimeMember> timeMembers = TimeFunctionFactory.createTrailingFunction( "week",
+ 3 )
+ .getResult( timeMember );
+ printMembers( timeMembers );
+ checkOutputFile( );
+ }
+
+ public void testTrailing5( ) throws IOException
+ {
+ int[] values = new int[]{
+ 2011, 3, 9, 4, 39, 5, 22, 265
+ };
+ String[] types = new String[]{
+ TimeMember.TIME_LEVEL_TYPE_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_QUARTER,
+ TimeMember.TIME_LEVEL_TYPE_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_WEEK_OF_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_WEEK,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_YEAR
+ };
+ TimeMember timeMember = new TimeMember( values, types );
+ List<TimeMember> timeMembers = TimeFunctionFactory.createTrailingFunction( "day",
+ 3 )
+ .getResult( timeMember );
+ printMembers( timeMembers );
+ checkOutputFile( );
+ }
+
+ public void testTrailing6( ) throws IOException
+ {
+ int[] values = new int[]{
+ 2011, 1
+ };
+ String[] types = new String[]{
+ TimeMember.TIME_LEVEL_TYPE_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_QUARTER
+ };
+ TimeMember timeMember = new TimeMember( values, types );
+ List<TimeMember> timeMembers = TimeFunctionFactory.createTrailingFunction( TimeMember.TIME_LEVEL_TYPE_QUARTER,
+ 3 )
+ .getResult( timeMember );
+ printMembers( timeMembers );
+ checkOutputFile( );
+
+ }
+
+ public void testTrailing7( ) throws IOException
+ {
+ int[] values = new int[]{
+ 2008, 2, 29
+ };
+ String[] types = new String[]{
+ TimeMember.TIME_LEVEL_TYPE_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_MONTH
+ };
+ TimeMember timeMember = new TimeMember( values, types );
+ List<TimeMember> timeMembers = TimeFunctionFactory.createTrailingFunction( TimeMember.TIME_LEVEL_TYPE_YEAR,
+ 3 )
+ .getResult( timeMember );
+ printMembers( timeMembers );
+ checkOutputFile( );
+
+ }
+
+ private void printMembers( List<TimeMember> timeMembers )
+ {
+ String[] levelTypes;
+ int[] memberValues;
+ for ( TimeMember timeMember : timeMembers )
+ {
+ levelTypes = timeMember.getLevelType( );
+ memberValues = timeMember.getMemberValue( );
+ for ( int i = 0; i < levelTypes.length; i++ )
+ {
+ testPrint( levelTypes[i] + " " );
+ }
+ testPrintln( "" );
+ for ( int i = 0; i < memberValues.length; i++ )
+ {
+ testPrint( memberValues[i] + " " );
+ }
+ testPrintln( "" );
+ }
+ }
+}
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/WeekToDateTest.java b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/WeekToDateTest.java
new file mode 100644
index 0000000..015d529
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/WeekToDateTest.java
@@ -0,0 +1,114 @@
+
+package org.eclipse.birt.data.engine.olap.data.impl.aggregation.function;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.eclipse.birt.data.engine.olap.data.impl.aggregation.function.TimeMember;
+import org.eclipse.birt.data.engine.olap.data.impl.aggregation.function.WeekToDateFunciton;
+
+import testutil.BaseTestCase;
+
+/**
+ * this class test week to date function, you can refer to WeekToDateFunction
+ * for details
+ *
+ * @author peng.shi
+ *
+ */
+public class WeekToDateTest extends BaseTestCase
+{
+
+ public void testWTD1( ) throws IOException
+ {
+ int[] values = new int[]{
+ 2011, 3, 9, 4, 39, 5, 22, 265
+ };
+ String[] types = new String[]{
+ TimeMember.TIME_LEVEL_TYPE_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_QUARTER,
+ TimeMember.TIME_LEVEL_TYPE_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_WEEK_OF_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_WEEK,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_YEAR
+ };
+ TimeMember timeMember = new TimeMember( values, types );
+ List<TimeMember> timeMembers = new WeekToDateFunciton( ).getResult( timeMember );
+ printMembers( timeMembers );
+ checkOutputFile( );
+ }
+
+ public void testWTD2( ) throws IOException
+ {
+ int[] values = new int[]{
+ 2011, 20, 5
+ };
+ String[] types = new String[]{
+ TimeMember.TIME_LEVEL_TYPE_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_WEEK_OF_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_WEEK
+ };
+ TimeMember timeMember = new TimeMember( values, types );
+ List<TimeMember> timeMembers = new WeekToDateFunciton( ).getResult( timeMember );
+ printMembers( timeMembers );
+ checkOutputFile( );
+ }
+
+ public void testWTD3( ) throws IOException
+ {
+ int[] values = new int[]{
+ 2002, 1, 2, 1, 7
+ };
+ String[] types = new String[]{
+ TimeMember.TIME_LEVEL_TYPE_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_QUARTER,
+ TimeMember.TIME_LEVEL_TYPE_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_DAY_OF_WEEK
+ };
+ TimeMember timeMember = new TimeMember( values, types );
+ List<TimeMember> timeMembers = new WeekToDateFunciton( ).getResult( timeMember );
+ printMembers( timeMembers );
+ checkOutputFile( );
+ }
+
+ public void testWTD4( ) throws IOException
+ {
+ int[] values = new int[]{
+ 2011, 1, 2, 1
+ };
+ String[] types = new String[]{
+ TimeMember.TIME_LEVEL_TYPE_YEAR,
+ TimeMember.TIME_LEVEL_TYPE_QUARTER,
+ TimeMember.TIME_LEVEL_TYPE_MONTH,
+ TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH
+ };
+ TimeMember timeMember = new TimeMember( values, types );
+ List<TimeMember> timeMembers = new WeekToDateFunciton( ).getResult( timeMember );
+ printMembers( timeMembers );
+ checkOutputFile( );
+ }
+
+ private void printMembers( List<TimeMember> timeMembers )
+ {
+ String[] levelTypes;
+ int[] memberValues;
+ for ( TimeMember timeMember : timeMembers )
+ {
+ levelTypes = timeMember.getLevelType( );
+ memberValues = timeMember.getMemberValue( );
+ for ( int i = 0; i < levelTypes.length; i++ )
+ {
+ testPrint( levelTypes[i] + " " );
+ }
+ testPrintln( "" );
+ for ( int i = 0; i < memberValues.length; i++ )
+ {
+ testPrint( memberValues[i] + " " );
+ }
+ testPrintln( "" );
+ }
+ }
+}
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD1.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD1.txt
new file mode 100644
index 0000000..67fd2cd
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD1.txt
@@ -0,0 +1,42 @@
+year month day-of-month
+2002 3 1
+year month day-of-month
+2002 3 2
+year month day-of-month
+2002 3 3
+year month day-of-month
+2002 3 4
+year month day-of-month
+2002 3 5
+year month day-of-month
+2002 3 6
+year month day-of-month
+2002 3 7
+year month day-of-month
+2002 3 8
+year month day-of-month
+2002 3 9
+year month day-of-month
+2002 3 10
+year month day-of-month
+2002 3 11
+year month day-of-month
+2002 3 12
+year month day-of-month
+2002 3 13
+year month day-of-month
+2002 3 14
+year month day-of-month
+2002 3 15
+year month day-of-month
+2002 3 16
+year month day-of-month
+2002 3 17
+year month day-of-month
+2002 3 18
+year month day-of-month
+2002 3 19
+year month day-of-month
+2002 3 20
+year month day-of-month
+2002 3 21
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD2.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD2.txt
new file mode 100644
index 0000000..1df1573
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD2.txt
@@ -0,0 +1,42 @@
+year quarter month day-of-month
+2002 1 3 1
+year quarter month day-of-month
+2002 1 3 2
+year quarter month day-of-month
+2002 1 3 3
+year quarter month day-of-month
+2002 1 3 4
+year quarter month day-of-month
+2002 1 3 5
+year quarter month day-of-month
+2002 1 3 6
+year quarter month day-of-month
+2002 1 3 7
+year quarter month day-of-month
+2002 1 3 8
+year quarter month day-of-month
+2002 1 3 9
+year quarter month day-of-month
+2002 1 3 10
+year quarter month day-of-month
+2002 1 3 11
+year quarter month day-of-month
+2002 1 3 12
+year quarter month day-of-month
+2002 1 3 13
+year quarter month day-of-month
+2002 1 3 14
+year quarter month day-of-month
+2002 1 3 15
+year quarter month day-of-month
+2002 1 3 16
+year quarter month day-of-month
+2002 1 3 17
+year quarter month day-of-month
+2002 1 3 18
+year quarter month day-of-month
+2002 1 3 19
+year quarter month day-of-month
+2002 1 3 20
+year quarter month day-of-month
+2002 1 3 21
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD3.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD3.txt
new file mode 100644
index 0000000..5114081
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD3.txt
@@ -0,0 +1,8 @@
+year quarter month week-of-month
+2011 3 8 5
+year quarter month week-of-month
+2011 3 9 2
+year quarter month week-of-month
+2011 3 9 3
+year quarter month week-of-month
+2011 3 9 4
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD4.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD4.txt
new file mode 100644
index 0000000..b275dc8
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD4.txt
@@ -0,0 +1,8 @@
+year quarter month week-of-month
+2002 1 1 5
+year quarter month week-of-month
+2002 1 2 2
+year quarter month week-of-month
+2002 1 2 3
+year quarter month week-of-month
+2002 1 2 4
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD5.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD5.txt
new file mode 100644
index 0000000..88d4545
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD5.txt
@@ -0,0 +1,20 @@
+year day-of-year
+2002 91
+year day-of-year
+2002 92
+year day-of-year
+2002 93
+year day-of-year
+2002 94
+year day-of-year
+2002 95
+year day-of-year
+2002 96
+year day-of-year
+2002 97
+year day-of-year
+2002 98
+year day-of-year
+2002 99
+year day-of-year
+2002 100
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD6.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD6.txt
new file mode 100644
index 0000000..86167d6
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD6.txt
@@ -0,0 +1,44 @@
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 1 36 5 1 244
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 1 36 6 2 245
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 1 36 7 3 246
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 2 37 1 4 247
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 2 37 2 5 248
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 2 37 3 6 249
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 2 37 4 7 250
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 2 37 5 8 251
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 2 37 6 9 252
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 2 37 7 10 253
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 3 38 1 11 254
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 3 38 2 12 255
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 3 38 3 13 256
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 3 38 4 14 257
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 3 38 5 15 258
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 3 38 6 16 259
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 3 38 7 17 260
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 4 39 1 18 261
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 4 39 2 19 262
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 4 39 3 20 263
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 4 39 4 21 264
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 4 39 5 22 265
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD7.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD7.txt
new file mode 100644
index 0000000..893a5f5
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/MonthToDateTest.testMTD7.txt
@@ -0,0 +1,2 @@
+year quarter month
+2011 3 8
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing1.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing1.txt
new file mode 100644
index 0000000..7708640
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing1.txt
@@ -0,0 +1,6 @@
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2009 3 9 4 39 3 22 265
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2010 3 9 4 39 4 22 265
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 4 39 5 22 265
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing2.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing2.txt
new file mode 100644
index 0000000..05490d6
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing2.txt
@@ -0,0 +1,6 @@
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 1 3 4 13 3 22 81
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 2 6 4 26 4 22 173
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 4 39 5 22 265
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing3.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing3.txt
new file mode 100644
index 0000000..b91ef95
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing3.txt
@@ -0,0 +1,6 @@
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 7 4 30 6 22 203
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 8 4 35 2 22 234
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 4 39 5 22 265
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing4.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing4.txt
new file mode 100644
index 0000000..0adb23f
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing4.txt
@@ -0,0 +1,6 @@
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 2 37 5 8 251
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 3 38 5 15 258
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 4 39 5 22 265
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing5.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing5.txt
new file mode 100644
index 0000000..35db3e9
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing5.txt
@@ -0,0 +1,6 @@
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 4 39 3 20 263
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 4 39 4 21 264
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 4 39 5 22 265
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing6.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing6.txt
new file mode 100644
index 0000000..995fe4e
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing6.txt
@@ -0,0 +1,6 @@
+year quarter
+2010 3
+year quarter
+2010 4
+year quarter
+2011 1
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing7.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing7.txt
new file mode 100644
index 0000000..5dc4224
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/TrailingTest.testTrailing7.txt
@@ -0,0 +1,6 @@
+year month day-of-month
+2006 2 28
+year month day-of-month
+2007 2 28
+year month day-of-month
+2008 2 29
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/WeekToDateTest.testWTD1.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/WeekToDateTest.testWTD1.txt
new file mode 100644
index 0000000..158836c
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/WeekToDateTest.testWTD1.txt
@@ -0,0 +1,10 @@
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 4 39 1 18 261
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 4 39 2 19 262
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 4 39 3 20 263
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 4 39 4 21 264
+year quarter month week-of-month week-of-year day-of-week day-of-month day-of-year
+2011 3 9 4 39 5 22 265
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/WeekToDateTest.testWTD2.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/WeekToDateTest.testWTD2.txt
new file mode 100644
index 0000000..68c4a83
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/WeekToDateTest.testWTD2.txt
@@ -0,0 +1,10 @@
+year week-of-year day-of-week
+2011 20 1
+year week-of-year day-of-week
+2011 20 2
+year week-of-year day-of-week
+2011 20 3
+year week-of-year day-of-week
+2011 20 4
+year week-of-year day-of-week
+2011 20 5
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/WeekToDateTest.testWTD3.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/WeekToDateTest.testWTD3.txt
new file mode 100644
index 0000000..f261ae4
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/WeekToDateTest.testWTD3.txt
@@ -0,0 +1,14 @@
+year quarter month week-of-month day-of-week
+2002 1 1 5 1
+year quarter month week-of-month day-of-week
+2002 1 1 5 2
+year quarter month week-of-month day-of-week
+2002 1 1 5 3
+year quarter month week-of-month day-of-week
+2002 1 1 5 4
+year quarter month week-of-month day-of-week
+2002 1 1 5 5
+year quarter month week-of-month day-of-week
+2002 1 2 1 6
+year quarter month week-of-month day-of-week
+2002 1 2 1 7
diff --git a/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/WeekToDateTest.testWTD4.txt b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/WeekToDateTest.testWTD4.txt
new file mode 100644
index 0000000..d5558c3
--- /dev/null
+++ b/data/org.eclipse.birt.data.tests/test/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/golden/WeekToDateTest.testWTD4.txt
@@ -0,0 +1,2 @@
+year quarter month week-of-month
+2011 1 2 1
diff --git a/data/org.eclipse.birt.data/META-INF/MANIFEST.MF b/data/org.eclipse.birt.data/META-INF/MANIFEST.MF
index 9b3c8bf..473edc9 100644
--- a/data/org.eclipse.birt.data/META-INF/MANIFEST.MF
+++ b/data/org.eclipse.birt.data/META-INF/MANIFEST.MF
@@ -41,6 +41,7 @@ Export-Package: javax.olap,
org.eclipse.birt.data.engine.olap.data.document;x-friends:="org.eclipse.birt.data.tests",
org.eclipse.birt.data.engine.olap.data.impl;x-friends:="org.eclipse.birt.data.tests",
org.eclipse.birt.data.engine.olap.data.impl.aggregation;x-friends:="org.eclipse.birt.data.tests",
+ org.eclipse.birt.data.engine.olap.data.impl.aggregation.function;x-friends:="org.eclipse.birt.data.tests",
org.eclipse.birt.data.engine.olap.data.impl.aggregation.filter;x-friends:="org.eclipse.birt.data.tests",
org.eclipse.birt.data.engine.olap.data.impl.aggregation.sort;x-friends:="org.eclipse.birt.data.tests",
org.eclipse.birt.data.engine.olap.data.impl.dimension;x-friends:="org.eclipse.birt.data.tests",
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/AbstractMDX.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/AbstractMDX.java
new file mode 100644
index 0000000..953d1a9
--- /dev/null
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/AbstractMDX.java
@@ -0,0 +1,146 @@
+
+package org.eclipse.birt.data.engine.olap.data.impl.aggregation.function;
+
+import java.util.Calendar;
+
+/**
+ * This abstract class used for MDX function. MTD,YTD,trailing,etc,,, will
+ * extends this class, you can add some base method here.
+ *
+ * @author peng.shi
+ *
+ */
+abstract public class AbstractMDX
+{
+
+ protected static final String YEAR = "year";
+ protected static final String QUARTER = "quarter";
+ protected static final String MONTH = "month";
+ protected static final String WEEK = "week";
+ protected static final String DAY = "day";
+
+ /**
+ * translate the TimeMember.values to Calendar return the base
+ * level("year","month","day"...)
+ *
+ * @param cal
+ * @param levelTypes
+ * @param values
+ * @return
+ */
+ protected String translateToCal( Calendar cal, String[] levelTypes,
+ int[] values )
+ {
+ String type = "";
+ for ( int i = 0; i < values.length; i++ )
+ {
+ if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_YEAR ) )
+ {
+ cal.set( Calendar.YEAR, values[i] );
+ type = YEAR;
+ }
+
+ else if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_QUARTER ) )
+ {
+ // no quarter in cal,so set the corresponding month
+ cal.set( Calendar.MONTH, values[i] * 3 - 1 );
+ type = QUARTER;
+ }
+
+ else if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_MONTH ) )
+ {
+ cal.set( Calendar.MONTH, values[i] - 1 );
+ type = MONTH;
+ }
+
+ else if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH ) )
+ {
+ cal.set( Calendar.WEEK_OF_MONTH, values[i] );
+ type = WEEK;
+ }
+
+ else if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_WEEK_OF_YEAR ) )
+ {
+ cal.set( Calendar.WEEK_OF_YEAR, values[i] );
+ type = WEEK;
+ }
+
+ else if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_WEEK ) )
+ {
+ cal.set( Calendar.DAY_OF_WEEK, values[i] );
+ type = DAY;
+ }
+
+ else if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_MONTH ) )
+ {
+ cal.set( Calendar.DAY_OF_MONTH, values[i] );
+ type = DAY;
+ }
+
+ else if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_YEAR ) )
+ {
+ cal.set( Calendar.DAY_OF_YEAR, values[i] );
+ type = DAY;
+ }
+ }
+
+ return type;
+ }
+
+ /**
+ * get the TimeMember.values from Calendar
+ *
+ * @param cal
+ * @param levelTypes
+ * @return
+ */
+ protected int[] getValueFromCal( Calendar cal, String[] levelTypes )
+ {
+ int[] tmp = new int[levelTypes.length];
+
+ for ( int i = 0; i < levelTypes.length; i++ )
+ {
+ if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_YEAR ) )
+ {
+ tmp[i] = cal.get( Calendar.YEAR );
+ }
+
+ else if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_QUARTER ) )
+ {
+ tmp[i] = cal.get( Calendar.MONTH ) / 3 + 1;
+ }
+
+ else if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_MONTH ) )
+ {
+ tmp[i] = cal.get( Calendar.MONTH ) + 1;
+ }
+
+ else if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH ) )
+ {
+ tmp[i] = cal.get( Calendar.WEEK_OF_MONTH );
+ }
+
+ else if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_WEEK_OF_YEAR ) )
+ {
+ tmp[i] = cal.get( Calendar.WEEK_OF_YEAR );
+ }
+
+ else if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_WEEK ) )
+ {
+ tmp[i] = cal.get( Calendar.DAY_OF_WEEK );
+ }
+
+ else if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_MONTH ) )
+ {
+ tmp[i] = cal.get( Calendar.DAY_OF_MONTH );
+ }
+
+ else if ( levelTypes[i].equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_YEAR ) )
+ {
+ tmp[i] = cal.get( Calendar.DAY_OF_YEAR );
+ }
+ }
+
+ return tmp;
+ }
+}
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/IParallelPeriod.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/IParallelPeriod.java
new file mode 100644
index 0000000..d8550f4
--- /dev/null
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/IParallelPeriod.java
@@ -0,0 +1,8 @@
+package org.eclipse.birt.data.engine.olap.data.impl.aggregation.function;
+
+
+public interface IParallelPeriod
+{
+ //return a members of the Time hierarchy
+ TimeMember getResult( TimeMember member );
+}
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/IPeriodsFunction.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/IPeriodsFunction.java
new file mode 100644
index 0000000..cce2aa5
--- /dev/null
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/IPeriodsFunction.java
@@ -0,0 +1,10 @@
+package org.eclipse.birt.data.engine.olap.data.impl.aggregation.function;
+
+import java.util.List;
+
+
+public interface IPeriodsFunction
+{
+ //return a set of members of the Time hierarchy
+ List<TimeMember> getResult( TimeMember member );
+}
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/MonthToDateFunction.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/MonthToDateFunction.java
new file mode 100644
index 0000000..93d6005
--- /dev/null
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/MonthToDateFunction.java
@@ -0,0 +1,69 @@
+
+package org.eclipse.birt.data.engine.olap.data.impl.aggregation.function;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+/**
+ *
+ * Use the MTD function to return a set of members of the Time hierarchy from
+ * the same month, up to and including a particular member. For example, you
+ * might use the function to return the set of days in 2007.8 up to and
+ * including 2007.8.21.
+ *
+ * @author peng.shi
+ *
+ */
+public class MonthToDateFunction extends AbstractMDX
+ implements
+ IPeriodsFunction
+{
+
+ @Override
+ public List<TimeMember> getResult( TimeMember member )
+ {
+ List timeMembers = new ArrayList<TimeMember>( );
+ String[] levelTypes = member.getLevelType( );
+ int[] values = member.getMemberValue( );
+
+ Calendar cal = new GregorianCalendar( );
+
+ String baseType = translateToCal( cal, levelTypes, values );
+ int[] tmp;
+ if ( baseType.equals( MONTH ) )
+ {
+ timeMembers.add( member );
+ }
+ else if ( baseType.equals( WEEK ) )
+ {
+ int weekOfMonth = cal.get( Calendar.WEEK_OF_MONTH );
+ int month = cal.get( Calendar.MONTH );
+ int year = cal.get( Calendar.YEAR );
+ for ( int i = 1; i <= weekOfMonth; i++ )
+ {
+ cal.set( Calendar.YEAR, year );
+ cal.set( Calendar.MONTH, month );
+ cal.set( Calendar.WEEK_OF_MONTH, i );
+ tmp = getValueFromCal( cal, levelTypes );
+ TimeMember timeMember = new TimeMember( tmp, levelTypes );
+ timeMembers.add( timeMember );
+ }
+ }
+ else if ( baseType.equals( DAY ) )
+ {
+ int dayOfMonth = cal.get( Calendar.DAY_OF_MONTH );
+ for ( int i = 1; i <= dayOfMonth; i++ )
+ {
+ cal.set( Calendar.DAY_OF_MONTH, i );
+ tmp = getValueFromCal( cal, levelTypes );
+ TimeMember timeMember = new TimeMember( tmp, levelTypes );
+ timeMembers.add( timeMember );
+ }
+ }
+
+ return timeMembers;
+ }
+
+}
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TimeFunctionFactory.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TimeFunctionFactory.java
new file mode 100644
index 0000000..e759c19
--- /dev/null
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TimeFunctionFactory.java
@@ -0,0 +1,19 @@
+package org.eclipse.birt.data.engine.olap.data.impl.aggregation.function;
+
+public class TimeFunctionFactory
+{
+ public static IPeriodsFunction createPeriodsToDateFunction( String levelTYpe )
+ {
+ return null;
+ }
+
+ public static IPeriodsFunction createTrailingFunction( String levelTYpe, int Offset )
+ {
+ return new TrailingFunction(levelTYpe, Offset);
+ }
+
+ public static IParallelPeriod createParallelPeriodFunction( String levelTYpe, int Offset )
+ {
+ return null;
+ }
+}
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TimeMember.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TimeMember.java
new file mode 100644
index 0000000..3f07164
--- /dev/null
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TimeMember.java
@@ -0,0 +1,42 @@
+package org.eclipse.birt.data.engine.olap.data.impl.aggregation.function;
+
+public class TimeMember
+{
+ public static final String TIME_LEVEL_TYPE_MONTH = "month"; //$NON-NLS-1$
+ public static final String TIME_LEVEL_TYPE_QUARTER = "quarter"; //$NON-NLS-1$
+
+ public static final String TIME_LEVEL_TYPE_DAY_OF_YEAR = "day-of-year"; //$NON-NLS-1$
+ public static final String TIME_LEVEL_TYPE_DAY_OF_MONTH = "day-of-month"; //$NON-NLS-1$
+ public static final String TIME_LEVEL_TYPE_DAY_OF_WEEK = "day-of-week"; //$NON-NLS-1$
+
+
+ public static final String TIME_LEVEL_TYPE_HOUR = "hour"; //$NON-NLS-1$
+ public static final String TIME_LEVEL_TYPE_MINUTE = "minute"; //$NON-NLS-1$
+ public static final String TIME_LEVEL_TYPE_SECOND = "second"; //$NON-NLS-1$
+
+ //not support
+ public static final String TIME_LEVEL_TYPE_WEEK_OF_MONTH = "week-of-month"; //$NON-NLS-1$
+ public static final String TIME_LEVEL_TYPE_WEEK_OF_YEAR = "week-of-year"; //$NON-NLS-1$
+ public static final String TIME_LEVEL_TYPE_YEAR = "year"; //$NON-NLS-1$
+
+ private int[] memberValue;
+ private String[] levelType;
+
+ public TimeMember( int[] memberValue, String[] levelType )
+ {
+ this.memberValue = memberValue;
+ this.levelType = levelType;
+ }
+
+ public int[] getMemberValue()
+ {
+ return memberValue;
+ }
+
+ public String[] getLevelType()
+ {
+ return levelType;
+ }
+
+
+}
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TrailingFunction.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TrailingFunction.java
new file mode 100644
index 0000000..00e73f1
--- /dev/null
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/TrailingFunction.java
@@ -0,0 +1,83 @@
+
+package org.eclipse.birt.data.engine.olap.data.impl.aggregation.function;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+/**
+ * The Trailing N Period function returns a set of consecutive members that
+ * include a specified member and can be located by the member and the Offset
+ * number.Now we support trailing in 5 level, Year, Quarter, Month, Week, Day
+ *
+ * @author peng.shi
+ *
+ */
+public class TrailingFunction extends AbstractMDX implements IPeriodsFunction
+{
+
+ private String levelType = "";
+ private int offset = 0;
+
+ public TrailingFunction( String levelType, int offset )
+ {
+ this.levelType = levelType;
+ this.offset = offset;
+ }
+
+ @Override
+ public List<TimeMember> getResult( TimeMember member )
+ {
+ List<TimeMember> timeMembers = new ArrayList<TimeMember>( );
+
+ String[] levelTypes = member.getLevelType( );
+ int[] values = member.getMemberValue( );
+
+ Calendar cal = new GregorianCalendar( );
+ translateToCal( cal, levelTypes, values );
+
+ timeMembers.add( member );
+ int[] tmp;
+ for ( int i = 0; i < offset - 1; i++ )
+ {
+ if ( levelType.equals( YEAR ) )
+ {
+ cal.add( Calendar.YEAR, -1 );
+ }
+ else if ( levelType.equals( MONTH ) )
+ {
+ cal.add( Calendar.MONTH, -1 );
+ }
+ else if ( levelType.equals( QUARTER ) )
+ {
+ // Calendar not support quarter, so add 3 month
+ cal.add( Calendar.MONTH, -3 );
+ }
+ else if ( levelType.equals( WEEK ) )
+ {
+ cal.add( Calendar.WEEK_OF_YEAR, -1 );
+ }
+ else if ( levelType.equals( DAY ) )
+ {
+ cal.add( Calendar.DATE, -1 );
+ }
+
+ tmp = getValueFromCal( cal, levelTypes );
+
+ TimeMember timeMember = new TimeMember( tmp, levelTypes );
+ timeMembers.add( timeMember );
+ }
+
+ // sort the member by ascending in time dimension
+ List<TimeMember> newTimeMemebers = new ArrayList<TimeMember>( );
+ for ( int i = timeMembers.size( ) - 1; i >= 0; i-- )
+ {
+ newTimeMemebers.add( timeMembers.get( i ) );
+ }
+
+ return newTimeMemebers;
+
+ }
+
+}
diff --git a/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/WeekToDateFunciton.java b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/WeekToDateFunciton.java
new file mode 100644
index 0000000..ff07b81
--- /dev/null
+++ b/data/org.eclipse.birt.data/src/org/eclipse/birt/data/engine/olap/data/impl/aggregation/function/WeekToDateFunciton.java
@@ -0,0 +1,55 @@
+
+package org.eclipse.birt.data.engine.olap.data.impl.aggregation.function;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+/**
+ * Use the WTD function to return a set of members of the Time hierarchy from
+ * the same week, up to and including a particular member.
+ *
+ * @author peng.shi
+ *
+ */
+public class WeekToDateFunciton extends AbstractMDX implements IPeriodsFunction
+{
+
+ private final long dayTimeInMills = 24 * 3600 * 1000;
+
+ @Override
+ public List<TimeMember> getResult( TimeMember member )
+ {
+ List timeMembers = new ArrayList<TimeMember>( );
+ String[] levelTypes = member.getLevelType( );
+ int[] values = member.getMemberValue( );
+
+ Calendar cal = new GregorianCalendar( );
+ String baseType = translateToCal( cal, levelTypes, values );
+
+ if ( baseType.equals( WEEK ) )
+ {
+ timeMembers.add( member );
+ }
+ else if ( baseType.equals( DAY ) )
+ {
+ int weekday = cal.get( Calendar.DAY_OF_WEEK );
+
+ int[] tmp;
+ Calendar newCal = new GregorianCalendar( );
+ for ( int i = 1; i <= weekday; i++ )
+ {
+ newCal.setTimeInMillis( cal.getTimeInMillis( )
+ - ( weekday - i ) * dayTimeInMills );
+ tmp = getValueFromCal( newCal, levelTypes );
+ TimeMember timeMember = new TimeMember( tmp, levelTypes );
+ timeMembers.add( timeMember );
+ }
+
+ }
+
+ return timeMembers;
+ }
+
+}