From 96895068207ec39e0c110307a0d2f987970752e5 Mon Sep 17 00:00:00 2001
From: diosmosis <benaka@piwik.pro>
Date: Sat, 20 Sep 2014 15:34:52 -0700
Subject: [PATCH] Refs #6078, prepend numeral index to each column in pivotted
 datatable.

---
 core/API/DocumentationGenerator.php           |   2 +
 core/DataTable/Filter/PivotByDimension.php    |  35 ++-
 .../DataTable/Filter/PivotByDimensionTest.php |   6 +-
 .../Integration/PivotByQueryParamTest.php     |   3 +-
 ...taTableMaps__Referrers.getKeywords_day.xml |  36 +--
 ...mnLimiting__Referrers.getKeywords_week.xml |  12 +-
 ...hCsvOutput__Referrers.getKeywords_week.csv | Bin 440 -> 458 bytes
 ...sonOutput__Referrers.getKeywords_week.json |   2 +-
 ...btableIsSelf__Actions.getPageUrls_week.xml | 210 +++++++++---------
 ...dInRequest__Referrers.getKeywords_week.xml |   4 +-
 ...PivotTable__Referrers.getKeywords_week.xml |  36 +--
 ...sNotLoaded__Referrers.getKeywords_week.xml |  72 +++---
 12 files changed, 227 insertions(+), 191 deletions(-)

diff --git a/core/API/DocumentationGenerator.php b/core/API/DocumentationGenerator.php
index 0662ff153e..668f97bb60 100644
--- a/core/API/DocumentationGenerator.php
+++ b/core/API/DocumentationGenerator.php
@@ -193,6 +193,8 @@ class DocumentationGenerator
         $aParameters['pivotBy'] = false;
         $aParameters['pivotByColumn'] = false;
         $aParameters['pivotByColumnLimit'] = false;
+        $aParameters['disable_queued_filters'] = false;
+        $aParameters['disable_generic_filters'] = false;
 
         $moduleName = Proxy::getInstance()->getModuleNameFromClassName($class);
         $aParameters = array_merge(array('module' => 'API', 'method' => $moduleName . '.' . $methodName), $aParameters);
diff --git a/core/DataTable/Filter/PivotByDimension.php b/core/DataTable/Filter/PivotByDimension.php
index ba4f0220f6..fd176f8cf5 100644
--- a/core/DataTable/Filter/PivotByDimension.php
+++ b/core/DataTable/Filter/PivotByDimension.php
@@ -215,7 +215,7 @@ class PivotByDimension extends BaseFilter
         $others = Piwik::translate('General_Others');
         $defaultRow = $this->getPivotTableDefaultRowFromColumnSummary($columnSet, $others);
 
-        Log::debug("PivotByDimension::%s: processed pivoted columns: %s", __FUNCTION__, $defaultRow);
+        Log::debug("PivotByDimension::%s: un-prepended default row: %s", __FUNCTION__, $defaultRow);
 
         // post process pivoted datatable
         foreach ($table->getRows() as $row) {
@@ -238,6 +238,18 @@ class PivotByDimension extends BaseFilter
         $table->clearQueuedFilters(); // TODO: shouldn't clear queued filters, but we can't wait for them to be run
                                       //       since generic filters are run before them. remove after refactoring
                                       //       processed metrics.
+
+        // prepend numerals to columns in a queued filter (this way, disable_queued_filters can be used
+        // to get machine readable data from the API if needed)
+        $prependedColumnNames = $this->getOrderedColumnsWithPrependedNumerals($defaultRow, $others);
+
+        Log::debug("PivotByDimension::%s: prepended column name mapping: %s", __FUNCTION__, $prependedColumnNames);
+
+        $table->queueFilter(function (DataTable $table) use ($prependedColumnNames) {
+            foreach ($table->getRows() as $row) {
+                $row->setColumns(array_combine($prependedColumnNames, $row->getColumns()));
+            }
+        });
     }
 
     /**
@@ -445,6 +457,27 @@ class PivotByDimension extends BaseFilter
         return $columnSet;
     }
 
+    private function getOrderedColumnsWithPrependedNumerals($defaultRow, $othersRowLabel)
+    {
+        $result = array();
+
+        $currentIndex = 1;
+        foreach ($defaultRow as $columnName => $ignore) {
+            if ($columnName == $othersRowLabel
+                || $columnName == 'label'
+            ) {
+                $result[] = $columnName;
+            } else {
+                $modifiedColumnName = $currentIndex . '.&nbsp;' . $columnName;
+                $result[] = $modifiedColumnName;
+
+                ++$currentIndex;
+            }
+        }
+
+        return $result;
+    }
+
     /**
      * Returns true if pivoting by subtable is supported for a report. Will return true if the report
      * has a subtable dimension and if the subtable dimension is different than the report's dimension.
diff --git a/tests/PHPUnit/Core/DataTable/Filter/PivotByDimensionTest.php b/tests/PHPUnit/Core/DataTable/Filter/PivotByDimensionTest.php
index d711d6655c..f1de402f44 100644
--- a/tests/PHPUnit/Core/DataTable/Filter/PivotByDimensionTest.php
+++ b/tests/PHPUnit/Core/DataTable/Filter/PivotByDimensionTest.php
@@ -262,9 +262,9 @@ class PivotByDimensionTest extends PHPUnit_Framework_TestCase
         $pivotFilter->filter($table);
 
         $expectedRows = array(
-            array('label' => 'row 1', 'col 2' => false, 'col 3' => false, 'col 4' => false),
-            array('label' => 'row 2', 'col 2' => 5, 'col 3' => false, 'col 4' => false),
-            array('label' => 'row 3', 'col 2' => 7, 'col 3' => 9, 'col 4' => 32)
+            array('label' => 'row 1', 'col 2' => false, 'col 4' => false, 'General_Others' => 1),
+            array('label' => 'row 2', 'col 2' => 5, 'col 4' => false, 'General_Others' => 3),
+            array('label' => 'row 3', 'col 2' => 7, 'col 4' => 32, 'General_Others' => 9)
         );
         $this->assertTableRowsEquals($expectedRows, $table);
     }
diff --git a/tests/PHPUnit/Integration/PivotByQueryParamTest.php b/tests/PHPUnit/Integration/PivotByQueryParamTest.php
index 2ca32cada2..d798d22bea 100644
--- a/tests/PHPUnit/Integration/PivotByQueryParamTest.php
+++ b/tests/PHPUnit/Integration/PivotByQueryParamTest.php
@@ -38,7 +38,8 @@ class PivotByQueryParamTest extends IntegrationTestCase
             'period' => 'week',
             'pivotBy' => 'Referrers.SearchEngine',
             'pivotByColumn' => 'nb_visits',
-            'pivotByColumnLimit' => -1
+            'pivotByColumnLimit' => -1,
+            'disable_queued_filters' => 1 // test that prepending doesn't happen w/ this
         ));
     }
 
diff --git a/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotByParamPlaysNiceWithDataTableMaps__Referrers.getKeywords_day.xml b/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotByParamPlaysNiceWithDataTableMaps__Referrers.getKeywords_day.xml
index 744fcf397e..d98cace554 100644
--- a/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotByParamPlaysNiceWithDataTableMaps__Referrers.getKeywords_day.xml
+++ b/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotByParamPlaysNiceWithDataTableMaps__Referrers.getKeywords_day.xml
@@ -6,39 +6,39 @@
 		<result date="2010-01-03">
 			<row>
 				<col name="label">this search term</col>
-				<col name="Toronto, Ontario, Canada">0</col>
-				<col name="Yokohama, Kanagawa, Japan">1</col>
-				<col name="Melbourne, Victoria, Australia">2</col>
+				<col name="1. Toronto, Ontario, Canada">0</col>
+				<col name="2. Yokohama, Kanagawa, Japan">1</col>
+				<col name="3. Melbourne, Victoria, Australia">2</col>
 			</row>
 			<row>
 				<col name="label">search term 2</col>
-				<col name="Toronto, Ontario, Canada">0</col>
-				<col name="Yokohama, Kanagawa, Japan">2</col>
-				<col name="Melbourne, Victoria, Australia">0</col>
+				<col name="1. Toronto, Ontario, Canada">0</col>
+				<col name="2. Yokohama, Kanagawa, Japan">2</col>
+				<col name="3. Melbourne, Victoria, Australia">0</col>
 			</row>
 			<row>
 				<col name="label">search term 3</col>
-				<col name="Toronto, Ontario, Canada">2</col>
-				<col name="Yokohama, Kanagawa, Japan">0</col>
-				<col name="Melbourne, Victoria, Australia">0</col>
+				<col name="1. Toronto, Ontario, Canada">2</col>
+				<col name="2. Yokohama, Kanagawa, Japan">0</col>
+				<col name="3. Melbourne, Victoria, Australia">0</col>
 			</row>
 			<row>
 				<col name="label">search term 4</col>
-				<col name="Toronto, Ontario, Canada">2</col>
-				<col name="Yokohama, Kanagawa, Japan">0</col>
-				<col name="Melbourne, Victoria, Australia">0</col>
+				<col name="1. Toronto, Ontario, Canada">2</col>
+				<col name="2. Yokohama, Kanagawa, Japan">0</col>
+				<col name="3. Melbourne, Victoria, Australia">0</col>
 			</row>
 			<row>
 				<col name="label">that search term</col>
-				<col name="Toronto, Ontario, Canada">0</col>
-				<col name="Yokohama, Kanagawa, Japan">0</col>
-				<col name="Melbourne, Victoria, Australia">2</col>
+				<col name="1. Toronto, Ontario, Canada">0</col>
+				<col name="2. Yokohama, Kanagawa, Japan">0</col>
+				<col name="3. Melbourne, Victoria, Australia">2</col>
 			</row>
 			<row>
 				<col name="label">search term 1</col>
-				<col name="Toronto, Ontario, Canada">0</col>
-				<col name="Yokohama, Kanagawa, Japan">1</col>
-				<col name="Melbourne, Victoria, Australia">0</col>
+				<col name="1. Toronto, Ontario, Canada">0</col>
+				<col name="2. Yokohama, Kanagawa, Japan">1</col>
+				<col name="3. Melbourne, Victoria, Australia">0</col>
 			</row>
 		</result>
 		<result date="2010-01-04" />
diff --git a/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotByParamWorksWithColumnLimiting__Referrers.getKeywords_week.xml b/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotByParamWorksWithColumnLimiting__Referrers.getKeywords_week.xml
index 4635e78f76..ac43686db0 100644
--- a/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotByParamWorksWithColumnLimiting__Referrers.getKeywords_week.xml
+++ b/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotByParamWorksWithColumnLimiting__Referrers.getKeywords_week.xml
@@ -2,32 +2,32 @@
 <result>
 	<row>
 		<col name="label">this search term</col>
-		<col name="Toronto, Ontario, Canada">0</col>
+		<col name="1. Toronto, Ontario, Canada">0</col>
 		<col name="Others">3</col>
 	</row>
 	<row>
 		<col name="label">search term 2</col>
-		<col name="Toronto, Ontario, Canada">0</col>
+		<col name="1. Toronto, Ontario, Canada">0</col>
 		<col name="Others">2</col>
 	</row>
 	<row>
 		<col name="label">search term 3</col>
-		<col name="Toronto, Ontario, Canada">2</col>
+		<col name="1. Toronto, Ontario, Canada">2</col>
 		<col name="Others">0</col>
 	</row>
 	<row>
 		<col name="label">search term 4</col>
-		<col name="Toronto, Ontario, Canada">2</col>
+		<col name="1. Toronto, Ontario, Canada">2</col>
 		<col name="Others">0</col>
 	</row>
 	<row>
 		<col name="label">that search term</col>
-		<col name="Toronto, Ontario, Canada">0</col>
+		<col name="1. Toronto, Ontario, Canada">0</col>
 		<col name="Others">2</col>
 	</row>
 	<row>
 		<col name="label">search term 1</col>
-		<col name="Toronto, Ontario, Canada">0</col>
+		<col name="1. Toronto, Ontario, Canada">0</col>
 		<col name="Others">1</col>
 	</row>
 </result>
\ No newline at end of file
diff --git a/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotByParamWorksWithCsvOutput__Referrers.getKeywords_week.csv b/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotByParamWorksWithCsvOutput__Referrers.getKeywords_week.csv
index 0536708ea8d46329d11063f42fe3dfce86e818ef..a465a67a14a20fbfaaf85163f4fbd9493102d342 100644
GIT binary patch
delta 48
ycmdnNe2Q80|GylDM1~}WRE8V|9R?)^Lk2yD1rzzrS&hI9S4&o75MyJlH6s8;2n<62

delta 30
mcmX@byn~tl|GylDM1~}WRE8V|9R{U|qUIBWEH+NCVgvx3d<j<o

diff --git a/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotByParamWorksWithJsonOutput__Referrers.getKeywords_week.json b/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotByParamWorksWithJsonOutput__Referrers.getKeywords_week.json
index 9b82ca037a..736901c89a 100644
--- a/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotByParamWorksWithJsonOutput__Referrers.getKeywords_week.json
+++ b/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotByParamWorksWithJsonOutput__Referrers.getKeywords_week.json
@@ -1 +1 @@
-[{"label":"this search term","Toronto, Ontario, Canada":false,"Yokohama, Kanagawa, Japan":1,"Melbourne, Victoria, Australia":2},{"label":"search term 2","Toronto, Ontario, Canada":false,"Yokohama, Kanagawa, Japan":2,"Melbourne, Victoria, Australia":false},{"label":"search term 3","Toronto, Ontario, Canada":2,"Yokohama, Kanagawa, Japan":false,"Melbourne, Victoria, Australia":false},{"label":"search term 4","Toronto, Ontario, Canada":2,"Yokohama, Kanagawa, Japan":false,"Melbourne, Victoria, Australia":false},{"label":"that search term","Toronto, Ontario, Canada":false,"Yokohama, Kanagawa, Japan":false,"Melbourne, Victoria, Australia":2},{"label":"search term 1","Toronto, Ontario, Canada":false,"Yokohama, Kanagawa, Japan":1,"Melbourne, Victoria, Australia":false}]
\ No newline at end of file
+[{"label":"this search term","1.&nbsp;Toronto, Ontario, Canada":false,"2.&nbsp;Yokohama, Kanagawa, Japan":1,"3.&nbsp;Melbourne, Victoria, Australia":2},{"label":"search term 2","1.&nbsp;Toronto, Ontario, Canada":false,"2.&nbsp;Yokohama, Kanagawa, Japan":2,"3.&nbsp;Melbourne, Victoria, Australia":false},{"label":"search term 3","1.&nbsp;Toronto, Ontario, Canada":2,"2.&nbsp;Yokohama, Kanagawa, Japan":false,"3.&nbsp;Melbourne, Victoria, Australia":false},{"label":"search term 4","1.&nbsp;Toronto, Ontario, Canada":2,"2.&nbsp;Yokohama, Kanagawa, Japan":false,"3.&nbsp;Melbourne, Victoria, Australia":false},{"label":"that search term","1.&nbsp;Toronto, Ontario, Canada":false,"2.&nbsp;Yokohama, Kanagawa, Japan":false,"3.&nbsp;Melbourne, Victoria, Australia":2},{"label":"search term 1","1.&nbsp;Toronto, Ontario, Canada":false,"2.&nbsp;Yokohama, Kanagawa, Japan":1,"3.&nbsp;Melbourne, Victoria, Australia":false}]
\ No newline at end of file
diff --git a/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotByParamWorksWithReportWhoseSubtableIsSelf__Actions.getPageUrls_week.xml b/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotByParamWorksWithReportWhoseSubtableIsSelf__Actions.getPageUrls_week.xml
index 5697f732c4..0b88c2ff59 100644
--- a/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotByParamWorksWithReportWhoseSubtableIsSelf__Actions.getPageUrls_week.xml
+++ b/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotByParamWorksWithReportWhoseSubtableIsSelf__Actions.getPageUrls_week.xml
@@ -2,122 +2,122 @@
 <result>
 	<row>
 		<col name="label">0</col>
-		<col name="/index">1</col>
-		<col name="/14">0</col>
-		<col name="/13">0</col>
-		<col name="/12">0</col>
-		<col name="/11">0</col>
-		<col name="/15">0</col>
-		<col name="/16">0</col>
-		<col name="/19">0</col>
-		<col name="/18">0</col>
-		<col name="/17">0</col>
-		<col name="/10">0</col>
-		<col name="/9">0</col>
-		<col name="/3">1</col>
-		<col name="/2">1</col>
-		<col name="/1">1</col>
-		<col name="/4">0</col>
-		<col name="/5">0</col>
-		<col name="/8">0</col>
-		<col name="/7">0</col>
-		<col name="/6">0</col>
-		<col name="/0">1</col>
+		<col name="1. /index">1</col>
+		<col name="2. /14">0</col>
+		<col name="3. /13">0</col>
+		<col name="4. /12">0</col>
+		<col name="5. /11">0</col>
+		<col name="6. /15">0</col>
+		<col name="7. /16">0</col>
+		<col name="8. /19">0</col>
+		<col name="9. /18">0</col>
+		<col name="10. /17">0</col>
+		<col name="11. /10">0</col>
+		<col name="12. /9">0</col>
+		<col name="13. /3">1</col>
+		<col name="14. /2">1</col>
+		<col name="15. /1">1</col>
+		<col name="16. /4">0</col>
+		<col name="17. /5">0</col>
+		<col name="18. /8">0</col>
+		<col name="19. /7">0</col>
+		<col name="20. /6">0</col>
+		<col name="21. /0">1</col>
 	</row>
 	<row>
 		<col name="label">1</col>
-		<col name="/index">1</col>
-		<col name="/14">0</col>
-		<col name="/13">0</col>
-		<col name="/12">0</col>
-		<col name="/11">0</col>
-		<col name="/15">0</col>
-		<col name="/16">0</col>
-		<col name="/19">0</col>
-		<col name="/18">0</col>
-		<col name="/17">0</col>
-		<col name="/10">0</col>
-		<col name="/9">0</col>
-		<col name="/3">0</col>
-		<col name="/2">0</col>
-		<col name="/1">0</col>
-		<col name="/4">1</col>
-		<col name="/5">1</col>
-		<col name="/8">0</col>
-		<col name="/7">1</col>
-		<col name="/6">1</col>
-		<col name="/0">0</col>
+		<col name="1. /index">1</col>
+		<col name="2. /14">0</col>
+		<col name="3. /13">0</col>
+		<col name="4. /12">0</col>
+		<col name="5. /11">0</col>
+		<col name="6. /15">0</col>
+		<col name="7. /16">0</col>
+		<col name="8. /19">0</col>
+		<col name="9. /18">0</col>
+		<col name="10. /17">0</col>
+		<col name="11. /10">0</col>
+		<col name="12. /9">0</col>
+		<col name="13. /3">0</col>
+		<col name="14. /2">0</col>
+		<col name="15. /1">0</col>
+		<col name="16. /4">1</col>
+		<col name="17. /5">1</col>
+		<col name="18. /8">0</col>
+		<col name="19. /7">1</col>
+		<col name="20. /6">1</col>
+		<col name="21. /0">0</col>
 	</row>
 	<row>
 		<col name="label">2</col>
-		<col name="/index">1</col>
-		<col name="/14">0</col>
-		<col name="/13">0</col>
-		<col name="/12">0</col>
-		<col name="/11">1</col>
-		<col name="/15">0</col>
-		<col name="/16">0</col>
-		<col name="/19">0</col>
-		<col name="/18">0</col>
-		<col name="/17">0</col>
-		<col name="/10">1</col>
-		<col name="/9">1</col>
-		<col name="/3">0</col>
-		<col name="/2">0</col>
-		<col name="/1">0</col>
-		<col name="/4">0</col>
-		<col name="/5">0</col>
-		<col name="/8">1</col>
-		<col name="/7">0</col>
-		<col name="/6">0</col>
-		<col name="/0">0</col>
+		<col name="1. /index">1</col>
+		<col name="2. /14">0</col>
+		<col name="3. /13">0</col>
+		<col name="4. /12">0</col>
+		<col name="5. /11">1</col>
+		<col name="6. /15">0</col>
+		<col name="7. /16">0</col>
+		<col name="8. /19">0</col>
+		<col name="9. /18">0</col>
+		<col name="10. /17">0</col>
+		<col name="11. /10">1</col>
+		<col name="12. /9">1</col>
+		<col name="13. /3">0</col>
+		<col name="14. /2">0</col>
+		<col name="15. /1">0</col>
+		<col name="16. /4">0</col>
+		<col name="17. /5">0</col>
+		<col name="18. /8">1</col>
+		<col name="19. /7">0</col>
+		<col name="20. /6">0</col>
+		<col name="21. /0">0</col>
 	</row>
 	<row>
 		<col name="label">3</col>
-		<col name="/index">1</col>
-		<col name="/14">1</col>
-		<col name="/13">1</col>
-		<col name="/12">1</col>
-		<col name="/11">0</col>
-		<col name="/15">1</col>
-		<col name="/16">0</col>
-		<col name="/19">0</col>
-		<col name="/18">0</col>
-		<col name="/17">0</col>
-		<col name="/10">0</col>
-		<col name="/9">0</col>
-		<col name="/3">0</col>
-		<col name="/2">0</col>
-		<col name="/1">0</col>
-		<col name="/4">0</col>
-		<col name="/5">0</col>
-		<col name="/8">0</col>
-		<col name="/7">0</col>
-		<col name="/6">0</col>
-		<col name="/0">0</col>
+		<col name="1. /index">1</col>
+		<col name="2. /14">1</col>
+		<col name="3. /13">1</col>
+		<col name="4. /12">1</col>
+		<col name="5. /11">0</col>
+		<col name="6. /15">1</col>
+		<col name="7. /16">0</col>
+		<col name="8. /19">0</col>
+		<col name="9. /18">0</col>
+		<col name="10. /17">0</col>
+		<col name="11. /10">0</col>
+		<col name="12. /9">0</col>
+		<col name="13. /3">0</col>
+		<col name="14. /2">0</col>
+		<col name="15. /1">0</col>
+		<col name="16. /4">0</col>
+		<col name="17. /5">0</col>
+		<col name="18. /8">0</col>
+		<col name="19. /7">0</col>
+		<col name="20. /6">0</col>
+		<col name="21. /0">0</col>
 	</row>
 	<row>
 		<col name="label">4</col>
-		<col name="/index">1</col>
-		<col name="/14">0</col>
-		<col name="/13">0</col>
-		<col name="/12">0</col>
-		<col name="/11">0</col>
-		<col name="/15">0</col>
-		<col name="/16">1</col>
-		<col name="/19">1</col>
-		<col name="/18">1</col>
-		<col name="/17">1</col>
-		<col name="/10">0</col>
-		<col name="/9">0</col>
-		<col name="/3">0</col>
-		<col name="/2">0</col>
-		<col name="/1">0</col>
-		<col name="/4">0</col>
-		<col name="/5">0</col>
-		<col name="/8">0</col>
-		<col name="/7">0</col>
-		<col name="/6">0</col>
-		<col name="/0">0</col>
+		<col name="1. /index">1</col>
+		<col name="2. /14">0</col>
+		<col name="3. /13">0</col>
+		<col name="4. /12">0</col>
+		<col name="5. /11">0</col>
+		<col name="6. /15">0</col>
+		<col name="7. /16">1</col>
+		<col name="8. /19">1</col>
+		<col name="9. /18">1</col>
+		<col name="10. /17">1</col>
+		<col name="11. /10">0</col>
+		<col name="12. /9">0</col>
+		<col name="13. /3">0</col>
+		<col name="14. /2">0</col>
+		<col name="15. /1">0</col>
+		<col name="16. /4">0</col>
+		<col name="17. /5">0</col>
+		<col name="18. /8">0</col>
+		<col name="19. /7">0</col>
+		<col name="20. /6">0</col>
+		<col name="21. /0">0</col>
 	</row>
 </result>
\ No newline at end of file
diff --git a/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotBySegmentCreatesCorrectPivotTableWhenSegmentUsedInRequest__Referrers.getKeywords_week.xml b/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotBySegmentCreatesCorrectPivotTableWhenSegmentUsedInRequest__Referrers.getKeywords_week.xml
index f4cc044f57..52686d6610 100644
--- a/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotBySegmentCreatesCorrectPivotTableWhenSegmentUsedInRequest__Referrers.getKeywords_week.xml
+++ b/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotBySegmentCreatesCorrectPivotTableWhenSegmentUsedInRequest__Referrers.getKeywords_week.xml
@@ -2,10 +2,10 @@
 <result>
 	<row>
 		<col name="label">that search term</col>
-		<col name="Melbourne, Victoria, Australia">2</col>
+		<col name="1. Melbourne, Victoria, Australia">2</col>
 	</row>
 	<row>
 		<col name="label">this search term</col>
-		<col name="Melbourne, Victoria, Australia">2</col>
+		<col name="1. Melbourne, Victoria, Australia">2</col>
 	</row>
 </result>
\ No newline at end of file
diff --git a/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotBySegmentCreatesCorrectPivotTable__Referrers.getKeywords_week.xml b/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotBySegmentCreatesCorrectPivotTable__Referrers.getKeywords_week.xml
index c6315c7326..8112e991f5 100644
--- a/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotBySegmentCreatesCorrectPivotTable__Referrers.getKeywords_week.xml
+++ b/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotBySegmentCreatesCorrectPivotTable__Referrers.getKeywords_week.xml
@@ -2,38 +2,38 @@
 <result>
 	<row>
 		<col name="label">this search term</col>
-		<col name="Toronto, Ontario, Canada">0</col>
-		<col name="Yokohama, Kanagawa, Japan">1</col>
-		<col name="Melbourne, Victoria, Australia">2</col>
+		<col name="1. Toronto, Ontario, Canada">0</col>
+		<col name="2. Yokohama, Kanagawa, Japan">1</col>
+		<col name="3. Melbourne, Victoria, Australia">2</col>
 	</row>
 	<row>
 		<col name="label">search term 2</col>
-		<col name="Toronto, Ontario, Canada">0</col>
-		<col name="Yokohama, Kanagawa, Japan">2</col>
-		<col name="Melbourne, Victoria, Australia">0</col>
+		<col name="1. Toronto, Ontario, Canada">0</col>
+		<col name="2. Yokohama, Kanagawa, Japan">2</col>
+		<col name="3. Melbourne, Victoria, Australia">0</col>
 	</row>
 	<row>
 		<col name="label">search term 3</col>
-		<col name="Toronto, Ontario, Canada">2</col>
-		<col name="Yokohama, Kanagawa, Japan">0</col>
-		<col name="Melbourne, Victoria, Australia">0</col>
+		<col name="1. Toronto, Ontario, Canada">2</col>
+		<col name="2. Yokohama, Kanagawa, Japan">0</col>
+		<col name="3. Melbourne, Victoria, Australia">0</col>
 	</row>
 	<row>
 		<col name="label">search term 4</col>
-		<col name="Toronto, Ontario, Canada">2</col>
-		<col name="Yokohama, Kanagawa, Japan">0</col>
-		<col name="Melbourne, Victoria, Australia">0</col>
+		<col name="1. Toronto, Ontario, Canada">2</col>
+		<col name="2. Yokohama, Kanagawa, Japan">0</col>
+		<col name="3. Melbourne, Victoria, Australia">0</col>
 	</row>
 	<row>
 		<col name="label">that search term</col>
-		<col name="Toronto, Ontario, Canada">0</col>
-		<col name="Yokohama, Kanagawa, Japan">0</col>
-		<col name="Melbourne, Victoria, Australia">2</col>
+		<col name="1. Toronto, Ontario, Canada">0</col>
+		<col name="2. Yokohama, Kanagawa, Japan">0</col>
+		<col name="3. Melbourne, Victoria, Australia">2</col>
 	</row>
 	<row>
 		<col name="label">search term 1</col>
-		<col name="Toronto, Ontario, Canada">0</col>
-		<col name="Yokohama, Kanagawa, Japan">1</col>
-		<col name="Melbourne, Victoria, Australia">0</col>
+		<col name="1. Toronto, Ontario, Canada">0</col>
+		<col name="2. Yokohama, Kanagawa, Japan">1</col>
+		<col name="3. Melbourne, Victoria, Australia">0</col>
 	</row>
 </result>
\ No newline at end of file
diff --git a/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotBySubtableDimensionCreatesCorrectPivotTableWhenEntireHirearchyIsNotLoaded__Referrers.getKeywords_week.xml b/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotBySubtableDimensionCreatesCorrectPivotTableWhenEntireHirearchyIsNotLoaded__Referrers.getKeywords_week.xml
index 1adf9d722a..6ab5630422 100644
--- a/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotBySubtableDimensionCreatesCorrectPivotTableWhenEntireHirearchyIsNotLoaded__Referrers.getKeywords_week.xml
+++ b/tests/PHPUnit/Integration/expected/test_PivotByQueryParamTest_testPivotBySubtableDimensionCreatesCorrectPivotTableWhenEntireHirearchyIsNotLoaded__Referrers.getKeywords_week.xml
@@ -2,56 +2,56 @@
 <result>
 	<row>
 		<col name="label">this search term</col>
-		<col name="Google">1</col>
-		<col name="Yahoo!">1</col>
-		<col name="Ask">1</col>
-		<col name="Bing">0</col>
-		<col name="Alexa">0</col>
-		<col name="Babylon">0</col>
+		<col name="1. Google">1</col>
+		<col name="2. Yahoo!">1</col>
+		<col name="3. Ask">1</col>
+		<col name="4. Bing">0</col>
+		<col name="5. Alexa">0</col>
+		<col name="6. Babylon">0</col>
 	</row>
 	<row>
 		<col name="label">search term 2</col>
-		<col name="Google">0</col>
-		<col name="Yahoo!">0</col>
-		<col name="Ask">0</col>
-		<col name="Bing">0</col>
-		<col name="Alexa">1</col>
-		<col name="Babylon">1</col>
+		<col name="1. Google">0</col>
+		<col name="2. Yahoo!">0</col>
+		<col name="3. Ask">0</col>
+		<col name="4. Bing">0</col>
+		<col name="5. Alexa">1</col>
+		<col name="6. Babylon">1</col>
 	</row>
 	<row>
 		<col name="label">search term 3</col>
-		<col name="Google">1</col>
-		<col name="Yahoo!">0</col>
-		<col name="Ask">1</col>
-		<col name="Bing">0</col>
-		<col name="Alexa">0</col>
-		<col name="Babylon">0</col>
+		<col name="1. Google">1</col>
+		<col name="2. Yahoo!">0</col>
+		<col name="3. Ask">1</col>
+		<col name="4. Bing">0</col>
+		<col name="5. Alexa">0</col>
+		<col name="6. Babylon">0</col>
 	</row>
 	<row>
 		<col name="label">search term 4</col>
-		<col name="Google">0</col>
-		<col name="Yahoo!">1</col>
-		<col name="Ask">0</col>
-		<col name="Bing">1</col>
-		<col name="Alexa">0</col>
-		<col name="Babylon">0</col>
+		<col name="1. Google">0</col>
+		<col name="2. Yahoo!">1</col>
+		<col name="3. Ask">0</col>
+		<col name="4. Bing">1</col>
+		<col name="5. Alexa">0</col>
+		<col name="6. Babylon">0</col>
 	</row>
 	<row>
 		<col name="label">that search term</col>
-		<col name="Google">1</col>
-		<col name="Yahoo!">1</col>
-		<col name="Ask">0</col>
-		<col name="Bing">0</col>
-		<col name="Alexa">0</col>
-		<col name="Babylon">0</col>
+		<col name="1. Google">1</col>
+		<col name="2. Yahoo!">1</col>
+		<col name="3. Ask">0</col>
+		<col name="4. Bing">0</col>
+		<col name="5. Alexa">0</col>
+		<col name="6. Babylon">0</col>
 	</row>
 	<row>
 		<col name="label">search term 1</col>
-		<col name="Google">0</col>
-		<col name="Yahoo!">0</col>
-		<col name="Ask">0</col>
-		<col name="Bing">1</col>
-		<col name="Alexa">0</col>
-		<col name="Babylon">0</col>
+		<col name="1. Google">0</col>
+		<col name="2. Yahoo!">0</col>
+		<col name="3. Ask">0</col>
+		<col name="4. Bing">1</col>
+		<col name="5. Alexa">0</col>
+		<col name="6. Babylon">0</col>
 	</row>
 </result>
\ No newline at end of file
-- 
GitLab