Пример #1
0
    def test_using_datablender_metric_builds_query(self):
        queries = (mock_dataset_blender.query().widget(
            f.ReactTable(mock_dataset_blender.
                         fields["candidate-spend-per-wins"])).dimension(
                             f.day(mock_dataset_blender.fields.timestamp))).sql

        self.assertEqual(len(queries), 1)
        self.assertEqual(
            "SELECT "
            '"sq0"."$timestamp" "$timestamp",'
            '"sq1"."$candidate-spend"/"sq0"."$wins" "$candidate-spend-per-wins" '
            "FROM ("
            "SELECT "
            'TRUNC("timestamp",\'DD\') "$timestamp",'
            'SUM("is_winner") "$wins" '
            'FROM "politics"."politician" '
            'GROUP BY "$timestamp"'
            ') "sq0" '
            "LEFT JOIN ("
            "SELECT "
            'TRUNC("timestamp",\'DD\') "$timestamp",'
            'SUM("candidate_spend") "$candidate-spend" '
            'FROM "politics"."politician_spend" '
            'GROUP BY "$timestamp"'
            ') "sq1" '
            "ON "
            '"sq0"."$timestamp"="sq1"."$timestamp" '
            'ORDER BY "$timestamp" '
            'LIMIT 200000',
            str(queries[0]),
        )
Пример #2
0
    def test_apply_dimension_filter_on_unmapped_dimension_field_filters_in_dataset_nested_query(
        self, ):
        queries = (mock_dataset_blender.query().widget(
            f.ReactTable(
                mock_dataset_blender.fields["candidate-spend-per-wins"])
        ).dimension(f.day(mock_dataset_blender.fields.timestamp)).filter(
            mock_dataset_blender.fields["political_party"] == "d")).sql

        self.assertEqual(len(queries), 1)
        self.assertEqual(
            "SELECT "
            '"sq0"."$timestamp" "$timestamp",'
            '"sq1"."$candidate-spend"/"sq0"."$wins" "$candidate-spend-per-wins" '
            "FROM ("
            "SELECT "
            'TRUNC("timestamp",\'DD\') "$timestamp",'
            'SUM("is_winner") "$wins" '
            'FROM "politics"."politician" '
            "WHERE \"political_party\"='d' "
            'GROUP BY "$timestamp"'
            ') "sq0" '
            "LEFT JOIN ("
            "SELECT "
            'TRUNC("timestamp",\'DD\') "$timestamp",'
            'SUM("candidate_spend") "$candidate-spend" '
            'FROM "politics"."politician_spend" '
            'GROUP BY "$timestamp"'
            ') "sq1" '
            "ON "
            '"sq0"."$timestamp"="sq1"."$timestamp" '
            'ORDER BY "$timestamp" '
            'LIMIT 200000',
            str(queries[0]),
        )
Пример #3
0
    def test_apply_set_filter_for_dimension_that_is_also_being_fetched_in_both_dataset_queries(
            self):
        queries = (mock_dataset_blender.query().widget(
            f.ReactTable(
                mock_dataset_blender.fields["candidate-spend-per-wins"])
        ).dimension(mock_dataset_blender.fields['candidate-id']).filter(
            f.ResultSet(
                mock_dataset_blender.fields['candidate-id'] == 12))).sql

        self.assertEqual(len(queries), 1)
        self.assertEqual(
            "SELECT "
            '"sq0"."$candidate-id" "$candidate-id",'
            '"sq1"."$candidate-spend"/"sq0"."$wins" "$candidate-spend-per-wins" '
            "FROM ("
            "SELECT "
            'CASE WHEN "candidate_id"=12 THEN \'set(candidate_id=12)\' ELSE \'complement(candidate_id=12)\' END "$candidate-id",'
            'SUM("is_winner") "$wins" '
            'FROM "politics"."politician" '
            'GROUP BY "$candidate-id"'
            ') "sq0" '
            "LEFT JOIN ("
            "SELECT "
            'CASE WHEN "candidate_id"=12 THEN \'set(candidate_id=12)\' ELSE \'complement(candidate_id=12)\' END "$candidate-id",'
            'SUM("candidate_spend") "$candidate-spend" '
            'FROM "politics"."politician_spend" '
            'GROUP BY "$candidate-id"'
            ') "sq1" '
            "ON "
            '"sq0"."$candidate-id"="sq1"."$candidate-id" '
            'ORDER BY "$candidate-id" '
            'LIMIT 200000',
            str(queries[0]),
        )
Пример #4
0
    def test_fields_from_multiple_datasets_results_in_blender_query(self):
        queries = (mock_dataset_blender.query().widget(
            f.ReactTable(
                mock_dataset_blender.fields["candidate-spend"],
                mock_dataset_blender.fields["voters"],
            )).dimension(f.day(mock_dataset_blender.fields.timestamp))).sql

        self.assertEqual(len(queries), 1)
        self.assertEqual(
            "SELECT "
            '"sq0"."$timestamp" "$timestamp",'
            '"sq1"."$candidate-spend" "$candidate-spend",'
            '"sq0"."$voters" "$voters" '
            "FROM ("
            "SELECT "
            'TRUNC("politician"."timestamp",\'DD\') "$timestamp",'
            'COUNT("voter"."id") "$voters" '
            'FROM "politics"."politician" '
            'JOIN "politics"."voter" ON "politician"."id"="voter"."politician_id" '
            'GROUP BY "$timestamp"'
            ') "sq0" '
            "LEFT JOIN ("
            "SELECT "
            'TRUNC("timestamp",\'DD\') "$timestamp",'
            'SUM("candidate_spend") "$candidate-spend" '
            'FROM "politics"."politician_spend" '
            'GROUP BY "$timestamp"'
            ') "sq1" '
            "ON "
            '"sq0"."$timestamp"="sq1"."$timestamp" '
            'ORDER BY "$timestamp" '
            'LIMIT 200000',
            str(queries[0]),
        )
Пример #5
0
    def test_using_fields_from_single_dataset_reduced_to_dataset_query(self):
        queries = (mock_dataset_blender.query().widget(
            f.ReactTable(mock_dataset_blender.fields["votes"])).dimension(
                f.day(mock_dataset_blender.fields.timestamp))).sql

        self.assertEqual(len(queries), 1)
        # TODO Optimisation opportunity with desired result:
        # self.assertEqual(
        #     "SELECT "
        #     'TRUNC("timestamp",\'DD\') "$timestamp",'
        #     'SUM("votes") "$votes" '
        #     'FROM "politics"."politician" '
        #     'GROUP BY "$timestamp" '
        #     'ORDER BY "$timestamp"',
        #     str(queries[0]),
        # )
        self.assertEqual(
            'SELECT "sq0"."$timestamp" "$timestamp","sq0"."$votes" "$votes" '
            "FROM ("
            'SELECT TRUNC("timestamp",\'DD\') "$timestamp",SUM("votes") "$votes" '
            'FROM "politics"."politician" '
            'GROUP BY "$timestamp") "sq0" '
            "LEFT JOIN ("
            'SELECT TRUNC("timestamp",\'DD\') "$timestamp" '
            'FROM "politics"."politician_spend" '
            'GROUP BY "$timestamp") "sq1" '
            'ON "sq0"."$timestamp"="sq1"."$timestamp" '
            'ORDER BY "$timestamp" '
            'LIMIT 200000',
            str(queries[0]),
        )
Пример #6
0
    def test_apply_set_filter_for_metric_in_primary_dataset_query(self):
        queries = (mock_dataset_blender.query().widget(
            f.ReactTable(
                mock_dataset_blender.fields["candidate-spend-per-wins"])
        ).dimension(f.day(mock_dataset_blender.fields.timestamp)).filter(
            f.ResultSet(mock_dataset_blender.fields["votes"].gt(10)))).sql

        self.assertEqual(len(queries), 1)
        self.assertEqual(
            "SELECT "
            '"sq0"."$timestamp" "$timestamp",'
            '"sq0"."$set(SUM(votes)>10)" "$set(SUM(votes)>10)",'
            '"sq1"."$candidate-spend"/"sq0"."$wins" "$candidate-spend-per-wins" '
            "FROM ("
            "SELECT "
            'TRUNC("timestamp",\'DD\') "$timestamp",'
            'CASE WHEN SUM("votes")>10 THEN \'set(SUM(votes)>10)\' ELSE \'complement(SUM(votes)>10)\' END "$set(SUM(votes)>10)",'
            'SUM("is_winner") "$wins" '
            'FROM "politics"."politician" '
            'GROUP BY "$timestamp"'
            ') "sq0" '
            "LEFT JOIN ("
            "SELECT "
            'TRUNC("timestamp",\'DD\') "$timestamp",'
            'SUM("candidate_spend") "$candidate-spend" '
            'FROM "politics"."politician_spend" '
            'GROUP BY "$timestamp"'
            ') "sq1" '
            "ON "
            '"sq0"."$timestamp"="sq1"."$timestamp" '
            'ORDER BY "$timestamp" '
            'LIMIT 200000',
            str(queries[0]),
        )
Пример #7
0
    def test_using_datablender_builds_query_with_mapped_and_unmapped_dimensions(
            self):
        queries = (mock_dataset_blender.query().widget(
            f.ReactTable(mock_dataset_blender.
                         fields["candidate-spend-per-wins"])).dimension(
                             f.day(mock_dataset_blender.fields.timestamp),
                             mock_dataset_blender.fields.political_party,
                         )).sql

        self.assertEqual(len(queries), 1)
        self.assertEqual(
            "SELECT "
            '"sq0"."$timestamp" "$timestamp",'
            '"sq0"."$political_party" "$political_party",'
            '"sq1"."$candidate-spend"/"sq0"."$wins" "$candidate-spend-per-wins" '
            "FROM ("
            "SELECT "
            'TRUNC("timestamp",\'DD\') "$timestamp",'
            '"political_party" "$political_party",'
            'SUM("is_winner") "$wins" '
            'FROM "politics"."politician" '
            'GROUP BY "$timestamp","$political_party" ORDER BY "$timestamp","$political_party"'
            ') "sq0" '
            "JOIN ("
            "SELECT "
            'TRUNC("timestamp",\'DD\') "$timestamp",'
            'SUM("candidate_spend") "$candidate-spend" '
            'FROM "politics"."politician_spend" '
            'GROUP BY "$timestamp" ORDER BY "$timestamp"'
            ') "sq1" '
            "ON "
            '"sq0"."$timestamp"="sq1"."$timestamp" '
            'ORDER BY "$timestamp","$political_party"',
            str(queries[0]),
        )
Пример #8
0
    def test_multiple_metrics_with_an_order_by_in_query_applies_order_to_wrapping_query(
        self, ):
        queries = (mock_dataset_blender.query().widget(
            f.ReactTable(
                mock_dataset_blender.fields["votes"],
                mock_dataset_blender.fields["candidate-spend"],
            )).dimension(f.day(mock_dataset_blender.fields.timestamp)).orderby(
                mock_dataset_blender.fields["votes"])).sql

        self.assertEqual(len(queries), 1)

        self.assertEqual(
            "SELECT "
            '"sq0"."$timestamp" "$timestamp",'
            '"sq0"."$votes" "$votes",'
            '"sq1"."$candidate-spend" "$candidate-spend" '
            "FROM ("
            "SELECT "
            'TRUNC("timestamp",\'DD\') "$timestamp",'
            'SUM("votes") "$votes" '
            'FROM "politics"."politician" '
            'GROUP BY "$timestamp" ORDER BY "$timestamp"'
            ') "sq0" '
            "JOIN ("
            "SELECT "
            'TRUNC("timestamp",\'DD\') "$timestamp",'
            'SUM("candidate_spend") "$candidate-spend" '
            'FROM "politics"."politician_spend" '
            'GROUP BY "$timestamp" ORDER BY "$timestamp"'
            ') "sq1" '
            "ON "
            '"sq0"."$timestamp"="sq1"."$timestamp" '
            'ORDER BY "$votes"',
            str(queries[0]),
        )
Пример #9
0
    def test_apply_metric_filter_to_dataset_field_filters_in_nested_dataset_query(
            self):
        queries = (mock_dataset_blender.query().widget(
            f.ReactTable(
                mock_dataset_blender.fields["candidate-spend-per-wins"])
        ).dimension(f.day(mock_dataset_blender.fields.timestamp)).filter(
            mock_dataset_blender.fields["votes"].gt(10))).sql

        self.assertEqual(len(queries), 1)
        self.assertEqual(
            "SELECT "
            '"sq0"."$timestamp" "$timestamp",'
            '"sq1"."$candidate-spend"/"sq0"."$wins" "$candidate-spend-per-wins" '
            "FROM ("
            "SELECT "
            'TRUNC("timestamp",\'DD\') "$timestamp",'
            'SUM("is_winner") "$wins" '
            'FROM "politics"."politician" '
            'GROUP BY "$timestamp" '
            'HAVING SUM("votes")>10 '
            'ORDER BY "$timestamp"'
            ') "sq0" '
            "JOIN ("
            "SELECT "
            'TRUNC("timestamp",\'DD\') "$timestamp",'
            'SUM("candidate_spend") "$candidate-spend" '
            'FROM "politics"."politician_spend" '
            'GROUP BY "$timestamp" ORDER BY "$timestamp"'
            ') "sq1" '
            "ON "
            '"sq0"."$timestamp"="sq1"."$timestamp" '
            'ORDER BY "$timestamp"',
            str(queries[0]),
        )
Пример #10
0
    def test_apply_reference_to_blended_query(self):
        query = (mock_dataset_blender.query().widget(
            f.ReactTable(
                mock_dataset_blender.fields["candidate-spend-per-wins"])
        ).dimension(f.day(mock_dataset_blender.fields.timestamp)).reference(
            f.WeekOverWeek(mock_dataset_blender.fields.timestamp)))

        sql = query.sql

        self.assertEqual(len(sql), 2)
        (base_query, ref_query) = sql
        with self.subTest("base query"):
            self.assertEqual(
                "SELECT "
                '"sq0"."$timestamp" "$timestamp",'
                '"sq1"."$candidate-spend"/"sq0"."$wins" "$candidate-spend-per-wins" '
                "FROM ("
                "SELECT "
                'TRUNC("timestamp",\'DD\') "$timestamp",'
                'SUM("is_winner") "$wins" '
                'FROM "politics"."politician" '
                'GROUP BY "$timestamp" ORDER BY "$timestamp"'
                ') "sq0" '
                "JOIN ("
                "SELECT "
                'TRUNC("timestamp",\'DD\') "$timestamp",'
                'SUM("candidate_spend") "$candidate-spend" '
                'FROM "politics"."politician_spend" '
                'GROUP BY "$timestamp" ORDER BY "$timestamp"'
                ') "sq1" '
                "ON "
                '"sq0"."$timestamp"="sq1"."$timestamp" '
                'ORDER BY "$timestamp"',
                str(base_query),
            )
        with self.subTest("ref query"):
            self.assertEqual(
                "SELECT "
                '"sq0"."$timestamp" "$timestamp",'
                '"sq1"."$candidate-spend_wow"/"sq0"."$wins_wow" "$candidate-spend-per-wins_wow" '
                "FROM ("
                "SELECT "
                "TRUNC(TIMESTAMPADD('week',1,TRUNC(\"timestamp\",'DD')),'DD') \"$timestamp\","
                'SUM("is_winner") "$wins_wow" '
                'FROM "politics"."politician" '
                'GROUP BY "$timestamp" ORDER BY "$timestamp"'
                ') "sq0" '
                "JOIN ("
                "SELECT "
                "TRUNC(TIMESTAMPADD('week',1,TRUNC(\"timestamp\",'DD')),'DD') \"$timestamp\","
                'SUM("candidate_spend") "$candidate-spend_wow" '
                'FROM "politics"."politician_spend" '
                'GROUP BY "$timestamp" ORDER BY "$timestamp"'
                ') "sq1" '
                "ON "
                '"sq0"."$timestamp"="sq1"."$timestamp" '
                'ORDER BY "$timestamp"',
                str(ref_query),
            )
Пример #11
0
 def test_does_not_raise_SlicerException_when_a_dimension_is_not_mapped_for_unnecessary_secondary_datasets(
     self,
 ):
     # noinspection PyStatementEffect
     (
         mock_dataset_blender.query()
         .widget(f.ReactTable(mock_dataset_blender.fields["votes"]))
         .dimension(mock_dataset_blender.fields["district-id"])
     ).sql
Пример #12
0
    def test_using_fields_from_single_dataset_reduced_to_dataset_query(self):
        queries = (mock_dataset_blender.query().widget(
            f.ReactTable(mock_dataset_blender.fields["votes"], )).dimension(
                f.day(mock_dataset_blender.fields.timestamp))).sql

        self.assertEqual(len(queries), 1)
        self.assertEqual(
            "SELECT "
            'TRUNC("timestamp",\'DD\') "$timestamp",'
            'SUM("votes") "$votes" '
            'FROM "politics"."politician" '
            'GROUP BY "$timestamp" '
            'ORDER BY "$timestamp"',
            str(queries[0]),
        )
Пример #13
0
    def test_blend_data_set_on_query_using_joins(self):
        query = (
            mock_dataset_blender.query()
            .widget(f.ReactTable(mock_dataset_blender.fields["candidate-spend-per-wins"]))
            .dimension(
                f.day(mock_dataset_blender.fields.timestamp),
                mock_dataset_blender.fields.state,
            )
        )

        self.assertEqual(
            "SELECT "
            '"sq0"."$timestamp" "$timestamp",'
            '"sq0"."$state" "$state",'
            '"sq1"."$candidate-spend"/"sq0"."$wins" "$candidate-spend-per-wins" '
            "FROM ("
            "SELECT "
            'TRUNC("politician"."timestamp",\'DD\') "$timestamp",'
            '"state"."state_name" "$state",'
            'SUM("politician"."is_winner") "$wins" '
            'FROM "politics"."politician" '
            'FULL OUTER JOIN "locations"."district" '
            'ON "politician"."district_id"="district"."id" '
            'JOIN "locations"."state" '
            'ON "district"."state_id"="state"."id" '
            'GROUP BY "$timestamp","$state"'
            ') "sq0" '
            "LEFT JOIN ("
            "SELECT "
            'TRUNC("timestamp",\'DD\') "$timestamp",'
            '"state_name" "$state",'
            'SUM("candidate_spend") "$candidate-spend" '
            'FROM "politics"."politician_spend" '
            'GROUP BY "$timestamp","$state"'
            ') "sq1" '
            "ON "
            '"sq0"."$timestamp"="sq1"."$timestamp" '
            'AND "sq0"."$state"="sq1"."$state" '
            'ORDER BY "$timestamp","$state" '
            'LIMIT 200000',
            str(query.sql[0]),
        )
Пример #14
0
    def test_blended_query_with_orderby_mapped_dimension(self):
        queries = (
            mock_dataset_blender.query()
            .widget(f.ReactTable(mock_dataset_blender.fields["candidate-spend-per-wins"]))
            .dimension(
                f.day(mock_dataset_blender.fields.timestamp),
                mock_dataset_blender.fields["candidate-id"],
            )
            .orderby(mock_dataset_blender.fields["candidate-id"], Order.desc)
        ).sql

        self.assertEqual(len(queries), 1)
        (query,) = queries
        self.assertEqual(
            "SELECT "
            '"sq0"."$timestamp" "$timestamp",'
            '"sq0"."$candidate-id" "$candidate-id",'
            '"sq1"."$candidate-spend"/"sq0"."$wins" "$candidate-spend-per-wins" '
            "FROM ("
            "SELECT "
            'TRUNC("timestamp",\'DD\') "$timestamp",'
            '"candidate_id" "$candidate-id",'
            'SUM("is_winner") "$wins" '
            'FROM "politics"."politician" '
            'GROUP BY "$timestamp","$candidate-id"'
            ') "sq0" '
            "LEFT JOIN ("
            "SELECT "
            'TRUNC("timestamp",\'DD\') "$timestamp",'
            '"candidate_id" "$candidate-id",'
            'SUM("candidate_spend") "$candidate-spend" '
            'FROM "politics"."politician_spend" '
            'GROUP BY "$timestamp","$candidate-id"'
            ') "sq1" '
            "ON "
            '"sq0"."$timestamp"="sq1"."$timestamp" '
            'AND "sq0"."$candidate-id"="sq1"."$candidate-id" '
            'ORDER BY "$candidate-id" DESC '
            'LIMIT 200000',
            str(query),
        )
Пример #15
0
    def test_apply_totals_to_blended_query(self):
        queries = (mock_dataset_blender.query().widget(
            f.ReactTable(mock_dataset_blender.
                         fields["candidate-spend-per-wins"])).dimension(
                             f.day(mock_dataset_blender.fields.timestamp),
                             Rollup(
                                 mock_dataset_blender.fields["candidate-id"]),
                         )).sql

        self.assertEqual(len(queries), 2)
        (base_query, totals_query) = queries
        with self.subTest("base query"):
            self.assertEqual(
                "SELECT "
                '"sq0"."$timestamp" "$timestamp",'
                '"sq0"."$candidate-id" "$candidate-id",'
                '"sq1"."$candidate-spend"/"sq0"."$wins" "$candidate-spend-per-wins" '
                "FROM ("
                "SELECT "
                'TRUNC("timestamp",\'DD\') "$timestamp",'
                '"candidate_id" "$candidate-id",'
                'SUM("is_winner") "$wins" '
                'FROM "politics"."politician" '
                'GROUP BY "$timestamp","$candidate-id"'
                ') "sq0" '
                "LEFT JOIN ("
                "SELECT "
                'TRUNC("timestamp",\'DD\') "$timestamp",'
                '"candidate_id" "$candidate-id",'
                'SUM("candidate_spend") "$candidate-spend" '
                'FROM "politics"."politician_spend" '
                'GROUP BY "$timestamp","$candidate-id"'
                ') "sq1" '
                "ON "
                '"sq0"."$timestamp"="sq1"."$timestamp" '
                'AND "sq0"."$candidate-id"="sq1"."$candidate-id" '
                'ORDER BY "$timestamp","$candidate-id" '
                'LIMIT 200000',
                str(base_query),
            )
        with self.subTest("totals query"):
            self.assertEqual(
                "SELECT "
                '"sq0"."$timestamp" "$timestamp",'
                '"sq0"."$candidate-id" "$candidate-id",'
                '"sq1"."$candidate-spend"/"sq0"."$wins" "$candidate-spend-per-wins" '
                "FROM ("
                "SELECT "
                'TRUNC("timestamp",\'DD\') "$timestamp",'
                "'_FIREANT_ROLLUP_VALUE_' \"$candidate-id\","
                'SUM("is_winner") "$wins" '
                'FROM "politics"."politician" '
                'GROUP BY "$timestamp","$candidate-id"'
                ') "sq0" '
                "LEFT JOIN ("
                "SELECT "
                'TRUNC("timestamp",\'DD\') "$timestamp",'
                "'_FIREANT_ROLLUP_VALUE_' \"$candidate-id\","
                'SUM("candidate_spend") "$candidate-spend" '
                'FROM "politics"."politician_spend" '
                'GROUP BY "$timestamp","$candidate-id"'
                ') "sq1" '
                "ON "
                '"sq0"."$timestamp"="sq1"."$timestamp" '
                'AND "sq0"."$candidate-id"="sq1"."$candidate-id" '
                'ORDER BY "$timestamp","$candidate-id" '
                'LIMIT 200000',
                str(totals_query),
            )
Пример #16
0
    def test_apply_set_filter_for_dimension_with_reference_in_both_dataset_queries(
            self):
        queries = (mock_dataset_blender.query().widget(
            f.ReactTable(
                mock_dataset_blender.fields["candidate-spend-per-wins"])
        ).dimension(f.day(mock_dataset_blender.fields.timestamp)).reference(
            f.WeekOverWeek(mock_dataset_blender.fields.timestamp)).filter(
                f.ResultSet(
                    mock_dataset_blender.fields['candidate-id'] == 12))).sql

        self.assertEqual(len(queries), 2)

        with self.subTest("base query"):
            self.assertEqual(
                "SELECT "
                '"sq0"."$timestamp" "$timestamp",'
                '"sq0"."$candidate-id" "$candidate-id",'
                '"sq1"."$candidate-spend"/"sq0"."$wins" "$candidate-spend-per-wins" '
                "FROM ("
                "SELECT "
                'TRUNC("timestamp",\'DD\') "$timestamp",'
                'CASE WHEN "candidate_id"=12 THEN \'set(candidate_id=12)\' ELSE \'complement(candidate_id=12)\' END "$candidate-id",'
                'SUM("is_winner") "$wins" '
                'FROM "politics"."politician" '
                'GROUP BY "$timestamp","$candidate-id"'
                ') "sq0" '
                "LEFT JOIN ("
                "SELECT "
                'TRUNC("timestamp",\'DD\') "$timestamp",'
                'CASE WHEN "candidate_id"=12 THEN \'set(candidate_id=12)\' ELSE \'complement(candidate_id=12)\' END "$candidate-id",'
                'SUM("candidate_spend") "$candidate-spend" '
                'FROM "politics"."politician_spend" '
                'GROUP BY "$timestamp","$candidate-id"'
                ') "sq1" '
                "ON "
                '"sq0"."$timestamp"="sq1"."$timestamp" '
                'AND "sq0"."$candidate-id"="sq1"."$candidate-id" '
                'ORDER BY "$timestamp","$candidate-id" '
                'LIMIT 200000',
                str(queries[0]),
            )

        with self.subTest("ref query"):
            self.assertEqual(
                "SELECT "
                '"sq0"."$timestamp" "$timestamp",'
                '"sq0"."$candidate-id" "$candidate-id",'
                '"sq1"."$candidate-spend_wow"/"sq0"."$wins_wow" "$candidate-spend-per-wins_wow" '
                "FROM ("
                "SELECT "
                'TRUNC(TIMESTAMPADD(week,1,TRUNC("timestamp",\'DD\')),\'DD\') "$timestamp",'
                'CASE WHEN "candidate_id"=12 THEN \'set(candidate_id=12)\' '
                'ELSE \'complement(candidate_id=12)\' END "$candidate-id",'
                'SUM("is_winner") "$wins_wow" '
                'FROM "politics"."politician" '
                'GROUP BY "$timestamp","$candidate-id"'
                ') "sq0" '
                "LEFT JOIN ("
                "SELECT "
                'TRUNC(TIMESTAMPADD(week,1,TRUNC("timestamp",\'DD\')),\'DD\') "$timestamp",'
                'CASE WHEN "candidate_id"=12 THEN \'set(candidate_id=12)\' '
                'ELSE \'complement(candidate_id=12)\' END "$candidate-id",'
                'SUM("candidate_spend") "$candidate-spend_wow" '
                'FROM "politics"."politician_spend" '
                'GROUP BY "$timestamp","$candidate-id"'
                ') "sq1" '
                "ON "
                '"sq0"."$timestamp"="sq1"."$timestamp" '
                'AND "sq0"."$candidate-id"="sq1"."$candidate-id" '
                'ORDER BY "$timestamp","$candidate-id" '
                'LIMIT 200000',
                str(queries[1]),
            )