Repository: googleapis/python-bigquery
Pull request #2084 (2024-11-28 08:57:43)

feat: add property for `allowNonIncrementalDefinition` for materialized view
Solves https://github.com/googleapis/python-bigquery/issues/2083

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

- [x] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-bigquery/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [x] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)

## Reference
- https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#MaterializedViewDefinition

chalmerlowe: @yu-iskw 

Thanks for adding this functionality. I added a couple of comments.
Please take a look.

yu-iskw: @chalmerlowe Thank you for the suggestion. I have taken them. 

Patch:
diff --git a/google/cloud/bigquery/table.py b/google/cloud/bigquery/table.py
index dcaf377e..38542023 100644
--- a/google/cloud/bigquery/table.py
+++ b/google/cloud/bigquery/table.py
@@ -390,6 +390,7 @@ class Table(_TableBase):
         "mview_last_refresh_time": ["materializedView", "lastRefreshTime"],
         "mview_query": "materializedView",
         "mview_refresh_interval": "materializedView",
+        "mview_allow_non_incremental_definition": "materializedView",
         "num_bytes": "numBytes",
         "num_rows": "numRows",
         "partition_expiration": "timePartitioning",
@@ -928,6 +929,28 @@ class Table(_TableBase):
             refresh_interval_ms,
         )
 
+    @property
+    def mview_allow_non_incremental_definition(self):
+        """Optional[bool]: This option declares the intention to construct a
+        materialized view that isn't refreshed incrementally.
+        The default value is :data:`False`.
+        """
+        api_field = self._PROPERTY_TO_API_FIELD[
+            "mview_allow_non_incremental_definition"
+        ]
+        return _helpers._get_sub_prop(
+            self._properties, [api_field, "allowNonIncrementalDefinition"]
+        )
+
+    @mview_allow_non_incremental_definition.setter
+    def mview_allow_non_incremental_definition(self, value):
+        api_field = self._PROPERTY_TO_API_FIELD[
+            "mview_allow_non_incremental_definition"
+        ]
+        _helpers._set_sub_prop(
+            self._properties, [api_field, "allowNonIncrementalDefinition"], value
+        )
+
     @property
     def streaming_buffer(self):
         """google.cloud.bigquery.StreamingBuffer: Information about a table's


Test patch:
diff --git a/tests/unit/test_table.py b/tests/unit/test_table.py
index d81ad2dc..ff059347 100644
--- a/tests/unit/test_table.py
+++ b/tests/unit/test_table.py
@@ -1050,6 +1050,16 @@ class TestTable(unittest.TestCase, _SchemaBase):
         table.mview_refresh_interval = None
         self.assertIsNone(table.mview_refresh_interval)
 
+    def test_mview_allow_non_incremental_definition(self):
+        table = self._make_one()
+        self.assertIsNone(table.mview_allow_non_incremental_definition)
+        table.mview_allow_non_incremental_definition = True
+        self.assertTrue(table.mview_allow_non_incremental_definition)
+        table.mview_allow_non_incremental_definition = False
+        self.assertFalse(table.mview_allow_non_incremental_definition)
+        table.mview_allow_non_incremental_definition = None
+        self.assertIsNone(table.mview_allow_non_incremental_definition)
+
     def test_from_string(self):
         cls = self._get_target_class()
         got = cls.from_string("string-project.string_dataset.string_table")