Repository: dbt-labs/dbt-redshift (language: python)

Issue:
[Feature] Reduce warnings with singular restrict_direct_pg_catalog_access message
### Is this your first time submitting a feature request?

- [X] I have read the [expectations for open source contributors](https://docs.getdbt.com/docs/contributing/oss-expectations)
- [X] I have searched the existing issues, and I could not find an existing issue for this feature
- [X] I am requesting a straightforward extension of existing dbt-redshift functionality, rather than a Big Idea better suited to a discussion

### Describe the feature

I have many hundreds of warnings for `restrict_direct_pg_catalog_access` behavior changes and it makes it impossible to see the warnings I care about related to tests and freshness/etc. Can the warning behavior be adjusted to reduce the messages to once per job run, rather than once per model materialization. 

### Describe alternatives you've considered

A single warning at the Top of a dbt run, perhaps when the compile step happens or the internal calls to determine if the tables already exist or not is performed. 

### Who will this benefit?

Administrators of job runs that need to action on Warnings. 

### Are you interested in contributing this feature?

I'm not able to

### Anything else?

_No response_


Discussion / hints:

Fix patch:
diff --git a/.changes/unreleased/Fixes-20240920-184812.yaml b/.changes/unreleased/Fixes-20240920-184812.yaml
new file mode 100644
index 000000000..754e9558a
--- /dev/null
+++ b/.changes/unreleased/Fixes-20240920-184812.yaml
@@ -0,0 +1,6 @@
+kind: Fixes
+body: Restrict behavior change warnings to firing once per run to avoid noisy logs
+time: 2024-09-20T18:48:12.064324-04:00
+custom:
+  Author: mikealfare
+  Issue: "915"


Test patch:
diff --git a/tests/functional/test_columns_in_relation.py b/tests/functional/test_columns_in_relation.py
index 60aeaa2aa..608217a41 100644
--- a/tests/functional/test_columns_in_relation.py
+++ b/tests/functional/test_columns_in_relation.py
@@ -1,5 +1,7 @@
+import os
+
 from dbt.adapters.base import Column
-from dbt.tests.util import run_dbt
+from dbt.tests.util import run_dbt, run_dbt_and_capture
 import pytest
 
 from dbt.adapters.redshift import RedshiftRelation
@@ -57,3 +59,43 @@ def expected_columns(self):
             Column(column="my_num", dtype="numeric", numeric_precision=3, numeric_scale=2),
             Column(column="my_char", dtype="varchar", char_size=1),
         ]
+
+
+ONE_CHECK = """
+select 1 as id
+-- {{ adapter.get_columns_in_relation(this) }}
+"""
+
+
+TWO_CHECK = """
+select 1 as id
+-- {{ adapter.get_columns_in_relation(this) }}
+-- {{ adapter.get_columns_in_relation(this) }}
+"""
+
+
+class TestBehaviorFlagFiresOnce:
+    @pytest.fixture(scope="class")
+    def project_config_update(self):
+        return {"flags": {"restrict_direct_pg_catalog_access": False}}
+
+    @pytest.fixture(scope="class")
+    def models(self):
+        return {"one_check.sql": ONE_CHECK, "two_check.sql": TWO_CHECK}
+
+    def test_warning_fires_once(self, project):
+        msg = "https://docs.getdbt.com/reference/global-configs/behavior-changes#redshift-restrict_direct_pg_catalog_access"
+
+        # trigger the evaluation once, we get one warning
+        _, logs = run_dbt_and_capture(["--debug", "run", "--models", "one_check"])
+        assert logs.count(msg) == 1
+
+        # trigger the evaluation twice, we still get one warning
+        _, logs = run_dbt_and_capture(["--debug", "run", "--models", "one_check"])
+        assert logs.count(msg) == 1
+
+        # trigger the evaluation three times, across two models, we still get one warning
+        _, logs = run_dbt_and_capture(["--debug", "run", "--full-refresh"])
+        assert logs.count(msg) == 1
+
+        # note, we still got a warning in the second call, so it's once per invocation