Beispiel #1
0
    def test_select_all_state_code_and_ids_filter(self):
        expected_query = (
            "SELECT * FROM `project-id.my_dataset.TABLE_WHERE_DATA_IS` "
            "WHERE state_code IN ('US_XX') AND person_id IN (1234)")

        self.assertEqual(
            expected_query,
            select_all_by_person_query(
                self.dataset,
                self.table_id,
                state_code_filter="US_XX",
                person_id_filter_set={1234},
            ),
        )

        expected_query = (
            "SELECT * FROM `project-id.my_dataset.TABLE_WHERE_DATA_IS` "
            "WHERE state_code IN ('US_XX') AND field_name IN (1234, 56)")
        self.assertEqual(
            expected_query,
            select_all_query(
                self.dataset,
                self.table_id,
                state_code_filter="US_XX",
                unifying_id_field="field_name",
                unifying_id_field_filter_set={1234, 56},
            ),
        )
Beispiel #2
0
    def _get_entities_table_sql_query(self):
        if not self._entity_has_unifying_id_field():
            raise ValueError(f"Shouldn't be querying table for entity {self._entity_class} that doesn't have field "
                             f"{self._unifying_id_field} - these values will never get grouped with results, so it's "
                             f"a waste to query for them.")

        unifying_id_field_filter_set = \
            self._unifying_id_field_filter_set if self._entity_has_unifying_id_field() else None
        state_code_filter = self._state_code if self._entity_has_state_code_field() else None
        entity_query = select_all_query(self._dataset,
                                        self._entity_table_name,
                                        state_code_filter,
                                        self._unifying_id_field,
                                        unifying_id_field_filter_set)

        return entity_query
Beispiel #3
0
    def test_select_all_with_state_code_filter_only(self):
        expected_query = 'SELECT * FROM `project-id.my_dataset.TABLE_WHERE_DATA_IS` WHERE state_code IN (\'US_XX\')'

        self.assertEqual(
            expected_query,
            select_all_by_person_query(self.dataset,
                                       self.table_id,
                                       state_code_filter='US_XX',
                                       person_id_filter_set=None))

        self.assertEqual(
            expected_query,
            select_all_query(self.dataset,
                             self.table_id,
                             state_code_filter='US_XX',
                             unifying_id_field='field_name',
                             unifying_id_field_filter_set=None))
Beispiel #4
0
    def test_simple_select_all_no_filters(self):
        expected_query = 'SELECT * FROM `project-id.my_dataset.TABLE_WHERE_DATA_IS`'

        self.assertEqual(
            expected_query,
            select_all_by_person_query(self.dataset,
                                       self.table_id,
                                       state_code_filter=None,
                                       person_id_filter_set=None))

        self.assertEqual(
            expected_query,
            select_all_query(self.dataset,
                             self.table_id,
                             state_code_filter=None,
                             unifying_id_field='field_name',
                             unifying_id_field_filter_set=None))
Beispiel #5
0
    def test_select_all_with_ids_filter_only(self):
        expected_query = 'SELECT * FROM `project-id.my_dataset.TABLE_WHERE_DATA_IS` WHERE person_id IN (1234)'

        self.assertEqual(
            expected_query,
            select_all_by_person_query(self.dataset,
                                       self.table_id,
                                       state_code_filter=None,
                                       person_id_filter_set={1234}))

        expected_query = 'SELECT * FROM `project-id.my_dataset.TABLE_WHERE_DATA_IS` WHERE field_name IN (1234)'
        self.assertEqual(
            expected_query,
            select_all_query(self.dataset,
                             self.table_id,
                             state_code_filter=None,
                             unifying_id_field='field_name',
                             unifying_id_field_filter_set={1234}))
Beispiel #6
0
    def test_select_all_state_code_and_ids_filter(self):
        expected_query = \
            'SELECT * FROM `project-id.my_dataset.TABLE_WHERE_DATA_IS` ' \
            'WHERE person_id IN (1234) AND state_code IN (\'US_XX\')'

        self.assertEqual(
            expected_query,
            select_all_by_person_query(self.dataset,
                                       self.table_id,
                                       state_code_filter='US_XX',
                                       person_id_filter_set={1234}))

        expected_query = \
            'SELECT * FROM `project-id.my_dataset.TABLE_WHERE_DATA_IS` ' \
            'WHERE field_name IN (1234, 56) AND state_code IN (\'US_XX\')'
        self.assertEqual(
            expected_query,
            select_all_query(self.dataset,
                             self.table_id,
                             state_code_filter='US_XX',
                             unifying_id_field='field_name',
                             unifying_id_field_filter_set={1234, 56}))
Beispiel #7
0
    def test_select_all_with_state_code_filter_only(self):
        expected_query = "SELECT * FROM `project-id.my_dataset.TABLE_WHERE_DATA_IS` WHERE state_code IN ('US_XX')"

        self.assertEqual(
            expected_query,
            select_all_by_person_query(
                self.dataset,
                self.table_id,
                state_code_filter="US_XX",
                person_id_filter_set=None,
            ),
        )

        self.assertEqual(
            expected_query,
            select_all_query(
                self.dataset,
                self.table_id,
                state_code_filter="US_XX",
                unifying_id_field="field_name",
                unifying_id_field_filter_set=None,
            ),
        )