Repository: m-lab/bigsanity

Issue:
paris_traceroute uses log_time
paris_traceroute data uses `log_time` rather than `web100_log_entry.log_time` since Paris Traceroute is not web100 based. We need to adjust the query construction to address this.

Discussion:

Patch:
diff --git a/bigsanity/query_construct.py b/bigsanity/query_construct.py
index 58e1b2d..cead3cd 100644
--- a/bigsanity/query_construct.py
+++ b/bigsanity/query_construct.py
@@ -102,6 +102,26 @@ def _project_has_intermediate_snapshots(project):
             project == constants.PROJECT_ID_NPAD)
 
 
+def _project_to_time_field(project):
+    """Returns the appropriate test log time field for the project type.
+
+    Returns the appropriate test log time field for a test given its project
+    type. All web100 M-Lab tests use 'web100_log_entry.log_time', while Paris
+    Traceroute uses 'log_time'.
+
+    Args:
+        project: The numeric ID of the project (e.g. NDT = 0).
+
+    Returns:
+        The string name of the log time field for the given project in the
+        BigQuery dataset schema.
+    """
+    if project == constants.PROJECT_ID_PARIS_TRACEROUTE:
+        return 'log_time'
+    else:
+        return 'web100_log_entry.log_time'
+
+
 class TableEquivalenceQueryGenerator(object):
     """Generates queries to test the equivalence of two M-Lab tables."""
 
@@ -153,17 +173,18 @@ class TableEquivalenceQueryGenerator(object):
         return _construct_test_id_subquery(tables, conditions)
 
     def _format_time_range_condition(self):
+        time_field = _project_to_time_field(self._project)
         start_time = _to_unix_timestamp(self._time_range_start)
         start_time_human = _to_human_readable_date(self._time_range_start)
         end_time = _to_unix_timestamp(self._time_range_end)
         end_time_human = _to_human_readable_date(self._time_range_end)
-        return (
-            '((web100_log_entry.log_time >= {start_time}) AND  -- {start_time_human}'
-            '\n         (web100_log_entry.log_time < {end_time}))  -- {end_time_human}'
-        ).format(start_time=start_time,
-                 start_time_human=start_time_human,
-                 end_time=end_time,
-                 end_time_human=end_time_human)
+        return ('(({time_field} >= {start_time}) AND  -- {start_time_human}'
+                '\n         ({time_field} < {end_time}))  -- {end_time_human}'
+               ).format(time_field=time_field,
+                        start_time=start_time,
+                        start_time_human=start_time_human,
+                        end_time=end_time,
+                        end_time_human=end_time_human)
 
 
 class TableEquivalenceQueryGeneratorFactory(object):


Test patch:
diff --git a/tests/test_query_construct.py b/tests/test_query_construct.py
index 22441d3..a64f523 100644
--- a/tests/test_query_construct.py
+++ b/tests/test_query_construct.py
@@ -284,8 +284,8 @@ class TableEquivalenceQueryGeneratorTest(unittest.TestCase):
                 plx.google:m_lab.2015_01.all
             WHERE
                 project = 3
-                AND ((web100_log_entry.log_time >= 1419724800) AND  -- 2014-12-28
-                     (web100_log_entry.log_time <  1420243200))     -- 2015-01-03
+                AND ((log_time >= 1419724800) AND  -- 2014-12-28
+                     (log_time <  1420243200))     -- 2015-01-03
           ) AS per_month
         FULL OUTER JOIN EACH
           (
@@ -294,8 +294,8 @@ class TableEquivalenceQueryGeneratorTest(unittest.TestCase):
             FROM
                 plx.google:m_lab.paris_traceroute.all
             WHERE
-                ((web100_log_entry.log_time >= 1419724800) AND  -- 2014-12-28
-                 (web100_log_entry.log_time <  1420243200))     -- 2015-01-03
+                ((log_time >= 1419724800) AND  -- 2014-12-28
+                 (log_time <  1420243200))     -- 2015-01-03
           ) AS per_project
         ON
             per_month.test_id=per_project.test_id