def test_map_date5(self):
        lower_date = datetime.date(2012, 1, 1)
        upper_date = datetime.date(2012, 12, 31)

        collector = atomic_query_aggregators.RangeCollector(
            'dob', lower_date, upper_date)

        row = {'dob': datetime.date(2013, 1, 1), spar_variables.VARS.ID: 'a'}

        result = collector.map(row)
        self.assertEqual(result, set())
    def test_reduce1(self):
        row1 = {'field1': 3, spar_variables.VARS.ID: 'b'}
        row2 = {'field1': 4, spar_variables.VARS.ID: 'c'}

        ea = atomic_query_aggregators.RangeCollector('field1', 3, 5)

        result1 = ea.map(row1)
        result2 = ea.map(row2)

        agg_result = ea.reduce(result1, result2)

        self.assertSetEqual(agg_result, set(['b', 'c']))
    def test_reduce2(self):
        row1 = {'field1': 3, spar_variables.VARS.ID: 'b'}
        row2 = {'field1': 4, spar_variables.VARS.ID: 'c'}
        row3 = {'field1': 5, spar_variables.VARS.ID: 'd'}
        row4 = {'field1': 6, spar_variables.VARS.ID: 'd'}

        base_count = 10

        ea = atomic_query_aggregators.RangeCollector('field1', 3, 5)

        agg_result1 = ea.map(row1)
        agg_result2 = ea.map(row2)
        agg_result3 = ea.map(row3)

        def add_row_to_result(row, result):
            new_result = ea.map(row)
            if new_result is None:
                return result
            else:
                return ea.reduce(result, new_result)

        for _ in xrange(base_count):
            add_row_to_result(row1, agg_result1)
            add_row_to_result(row1, agg_result2)
            add_row_to_result(row2, agg_result2)
            add_row_to_result(row1, agg_result1)
            add_row_to_result(row2, agg_result2)
            add_row_to_result(row3, agg_result3)
            add_row_to_result(row4, agg_result1)
            add_row_to_result(row4, agg_result2)
            add_row_to_result(row4, agg_result3)

        final_agg_result = ea.reduce(agg_result1, agg_result2)
        final_agg_result = ea.reduce(final_agg_result, agg_result3)

        self.assertSetEqual(final_agg_result, set(['b', 'c', 'd']))
 def test_fields_needed(self):
     field_id = 'field1'
     ea = atomic_query_aggregators.RangeCollector(field_id, 3, 5)
     fn = ea.fields_needed()
     self.assertSetEqual(set(fn), set([field_id]))
 def test_map6(self):
     collector = atomic_query_aggregators.RangeCollector('field1', 3, 5)
     row = {'field1': 4, spar_variables.VARS.ID: None}
     result = collector.map(row)
     self.assertSetEqual(result, set([None]))
 def test_map5(self):
     collector = atomic_query_aggregators.RangeCollector('field1', 3, 5)
     row = {'field1': 6, spar_variables.VARS.ID: 'b'}
     result = collector.map(row)
     self.assertEqual(result, set())