<commit_before>from test.integration.base import DBTIntegrationTest, FakeArgs, use_profile
import json


class TestChangingPartitions(DBTIntegrationTest):

    @property
    def schema(self):
        return "bigquery_test_022"

    @property
    def models(self):
        return "partition-models"

    def run_changes(self, before, after, strict=False):
        # strict needs to be off because these tests use legacy partition_by clauses
        results = self.run_dbt(['run', '--vars', json.dumps(before)], strict=strict)
        self.assertEqual(len(results), 1)

        results = self.run_dbt(['run', '--vars', json.dumps(after)], strict=strict)
        self.assertEqual(len(results), 1)

    @use_profile('bigquery')
    def test_bigquery_add_partition(self):
        before = {"partition_by": None, "cluster_by": None}
        after = {"partition_by": "date(cur_time)", "cluster_by": None}
        self.run_changes(before, after)

    @use_profile('bigquery')
    def test_bigquery_remove_partition(self):
        before = {"partition_by": "date(cur_time)", "cluster_by": None}
        after = {"partition_by": None, "cluster_by": None}
        self.run_changes(before, after)

    @use_profile('bigquery')
    def test_bigquery_change_partitions(self):
        before = {"partition_by": "date(cur_time)", "cluster_by": None}
        after = {"partition_by": "cur_date", "cluster_by": None}
        self.run_changes(before, after)
        self.run_changes(after, before)

    @use_profile('bigquery')
    def test_bigquery_add_clustering(self):
        before = {"partition_by": "date(cur_time)", "cluster_by": None}
        after = {"partition_by": "cur_date", "cluster_by": "id"}
        self.run_changes(before, after)

    @use_profile('bigquery')
    def test_bigquery_remove_clustering(self):
        before = {"partition_by": "date(cur_time)", "cluster_by": "id"}
        after = {"partition_by": "cur_date", "cluster_by": None}
        self.run_changes(before, after)

    @use_profile('bigquery')
    def test_bigquery_change_clustering(self):
        before = {"partition_by": "date(cur_time)", "cluster_by": "id"}
        after = {"partition_by": "cur_date", "cluster_by": "name"}
        self.run_changes(before, after)

    @use_profile('bigquery')
    def test_bigquery_change_clustering_strict(self):
        before = {'partition_by': {'field': 'cur_time', 'data_type': 'timestamp'}, 'cluster_by': 'id'}
        after = {'partition_by': {'field': 'cur_date', 'data_type': 'date'}, 'cluster_by': 'name'}
        self.run_changes(before, after, strict=True)<commit_msg>Add test for bq part int<>date switch<commit_after>from test.integration.base import DBTIntegrationTest, FakeArgs, use_profile
import json


class TestChangingPartitions(DBTIntegrationTest):

    @property
    def schema(self):
        return "bigquery_test_022"

    @property
    def models(self):
        return "partition-models"

    def run_changes(self, before, after, strict=False):
        # strict needs to be off because these tests use legacy partition_by clauses
        results = self.run_dbt(['run', '--vars', json.dumps(before)], strict=strict)
        self.assertEqual(len(results), 1)

        results = self.run_dbt(['run', '--vars', json.dumps(after)], strict=strict)
        self.assertEqual(len(results), 1)

    @use_profile('bigquery')
    def test_bigquery_add_partition(self):
        before = {"partition_by": None, "cluster_by": None}
        after = {"partition_by": "date(cur_time)", "cluster_by": None}
        self.run_changes(before, after)

    @use_profile('bigquery')
    def test_bigquery_remove_partition(self):
        before = {"partition_by": "date(cur_time)", "cluster_by": None}
        after = {"partition_by": None, "cluster_by": None}
        self.run_changes(before, after)

    @use_profile('bigquery')
    def test_bigquery_change_partitions(self):
        before = {"partition_by": "date(cur_time)", "cluster_by": None}
        after = {"partition_by": "cur_date", "cluster_by": None}
        self.run_changes(before, after)
        self.run_changes(after, before)
    
    @use_profile('bigquery')
    def test_bigquery_change_partitions_from_int(self):
        before = {"partition_by": {"field": "id", "data_type": "int64", "range": {"start": 0, "end": 10, "interval": 1}}, "cluster_by": None}
        after = {"partition_by": {"field": "cur_date", "data_type": "date"}, "cluster_by": None}
        self.run_changes(before, after)
        self.run_changes(after, before)

    @use_profile('bigquery')
    def test_bigquery_add_clustering(self):
        before = {"partition_by": "date(cur_time)", "cluster_by": None}
        after = {"partition_by": "cur_date", "cluster_by": "id"}
        self.run_changes(before, after)

    @use_profile('bigquery')
    def test_bigquery_remove_clustering(self):
        before = {"partition_by": "date(cur_time)", "cluster_by": "id"}
        after = {"partition_by": "cur_date", "cluster_by": None}
        self.run_changes(before, after)

    @use_profile('bigquery')
    def test_bigquery_change_clustering(self):
        before = {"partition_by": "date(cur_time)", "cluster_by": "id"}
        after = {"partition_by": "cur_date", "cluster_by": "name"}
        self.run_changes(before, after)

    @use_profile('bigquery')
    def test_bigquery_change_clustering_strict(self):
        before = {'partition_by': {'field': 'cur_time', 'data_type': 'timestamp'}, 'cluster_by': 'id'}
        after = {'partition_by': {'field': 'cur_date', 'data_type': 'date'}, 'cluster_by': 'name'}
        self.run_changes(before, after, strict=True)
{'fraction_non_alphanumeric': 0.15018706574024585, 'fraction_numerical': 0.002850525565651167, 'mean_word_length': 3.9593639575971733, 'pattern_counts': {'":': 60, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4231824', 'n_tokens_mistral': 1807, 'n_tokens_neox': 1752, 'n_words': 365}