Родитель
8fcf0578ed
Коммит
63764c72cc
|
@ -244,9 +244,7 @@ jobs:
|
|||
- *java_deps
|
||||
- run:
|
||||
name: Validate views
|
||||
command: |
|
||||
./bqetl bootstrap
|
||||
./bqetl view validate
|
||||
command: PATH="venv/bin:$PATH" script/validate_views
|
||||
docs:
|
||||
docker: *docker
|
||||
steps:
|
||||
|
|
|
@ -200,8 +200,6 @@ SKIP = {
|
|||
# Query too complex
|
||||
"sql/moz-fx-data-shared-prod/firefox_accounts_derived/event_types_history_v1/query.sql",
|
||||
"sql/moz-fx-data-shared-prod/firefox_accounts_derived/event_types_history_v1/init.sql",
|
||||
# Tests
|
||||
"sql/moz-fx-data-test-project/test/simple_view/view.sql",
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,8 +27,6 @@ SKIP_VALIDATION = {
|
|||
"sql/moz-fx-data-shared-prod/telemetry/clients_daily_scalar_aggregates_v1/view.sql",
|
||||
"sql/moz-fx-data-shared-prod/telemetry/clients_histogram_aggregates_v1/view.sql",
|
||||
"sql/moz-fx-data-shared-prod/telemetry/clients_probe_processes/view.sql",
|
||||
# tests
|
||||
"sql/moz-fx-data-test-project/test/simple_view/view.sql",
|
||||
}
|
||||
|
||||
# skip publishing these views
|
||||
|
@ -40,8 +38,6 @@ SKIP_PUBLISHING = {
|
|||
# Dataset glam-fenix-dev:glam_etl was not found
|
||||
# TODO: this should be removed if views are to be automatically deployed
|
||||
*[str(path) for path in Path("sql/glam-fenix-dev").glob("glam_etl/**/view.sql")],
|
||||
# tests
|
||||
"sql/moz-fx-data-test-project/test/simple_view/view.sql",
|
||||
}
|
||||
|
||||
# suffixes of datasets with non-user-facing views
|
||||
|
@ -62,11 +58,7 @@ class View:
|
|||
dataset: str = attr.ib()
|
||||
project: str = attr.ib()
|
||||
|
||||
@path.validator
|
||||
def validate_path(self, attribute, value):
|
||||
"""Check that the view path is valid."""
|
||||
if not Path(self.path).exists():
|
||||
raise ValueError(f"View file does not exist: {self.path}")
|
||||
# todo: validators
|
||||
|
||||
@property
|
||||
def content(self):
|
||||
|
@ -110,7 +102,7 @@ class View:
|
|||
)
|
||||
dataset_metadata.write(dataset_path / DATASET_METADATA_FILE)
|
||||
else:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.parent.mkdir(parents=True)
|
||||
|
||||
if not base_table:
|
||||
base_table = f"{project}.{dataset}_derived.{name}_v1"
|
||||
|
|
|
@ -4,8 +4,4 @@
|
|||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
./bqetl bootstrap
|
||||
./bqetl view publish "$@"
|
||||
|
||||
wait
|
||||
trap - EXIT
|
||||
exec python3 -m bigquery_etl.view.publish_views "$@"
|
||||
|
|
|
@ -4,8 +4,4 @@
|
|||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
./bqetl bootstrap
|
||||
./bqetl view validate "$@"
|
||||
|
||||
wait
|
||||
trap - EXIT
|
||||
exec ./bqetl view validate "$@"
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
friendly_name: Test
|
||||
description: |-
|
||||
Please provide a dataset description.
|
||||
dataset_base_acl: view
|
||||
user_facing: true
|
||||
labels: {}
|
||||
workgroup_access:
|
||||
- role: roles/bigquery.dataViewer
|
||||
members:
|
||||
- workgroup:mozilla-confidential
|
|
@ -1 +0,0 @@
|
|||
SELECT 1
|
|
@ -14,6 +14,7 @@ class TestPublish:
|
|||
(tmp_path / "view.sql").write_text("SELECT 42 as test")
|
||||
result = runner.invoke(view, ["publish", tmp_path.as_posix(), "--dry-run"])
|
||||
assert result.exit_code == 1
|
||||
assert "does not appear to be a CREATE OR REPLACE VIEW" in result.output
|
||||
|
||||
def test_publish_valid_view(self, runner, tmp_path):
|
||||
# In order to be agnostic with respect to individual projects in GCP,
|
||||
|
@ -27,3 +28,4 @@ class TestPublish:
|
|||
)
|
||||
result = runner.invoke(view, ["publish", tmp_path.as_posix(), "--dry-run"])
|
||||
assert result.exit_code == 1
|
||||
assert "Not found" in result.exc_info[1].message
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
CREATE OR REPLACE VIEW
|
||||
`moz-fx-data-test-project.test.simple_view`
|
||||
AS
|
||||
SELECT
|
||||
1
|
|
@ -1,90 +0,0 @@
|
|||
import pytest
|
||||
|
||||
from click.testing import CliRunner
|
||||
from pathlib import Path
|
||||
|
||||
from bigquery_etl.view import View
|
||||
|
||||
TEST_DIR = Path(__file__).parent.parent
|
||||
|
||||
|
||||
class TestView:
|
||||
@pytest.fixture
|
||||
def runner(self):
|
||||
return CliRunner()
|
||||
|
||||
def test_from_file(self):
|
||||
view_file = (
|
||||
TEST_DIR
|
||||
/ "data"
|
||||
/ "test_sql"
|
||||
/ "moz-fx-data-test-project"
|
||||
/ "test"
|
||||
/ "simple_view"
|
||||
/ "view.sql"
|
||||
)
|
||||
|
||||
view = View.from_file(view_file)
|
||||
assert view.dataset == "test"
|
||||
assert view.project == "moz-fx-data-test-project"
|
||||
assert view.name == "simple_view"
|
||||
assert view.view_identifier == "moz-fx-data-test-project.test.simple_view"
|
||||
assert view.is_user_facing
|
||||
|
||||
def test_view_create(self, runner):
|
||||
with runner.isolated_filesystem():
|
||||
view = View.create("moz-fx-data-test-project", "test", "simple_view", "sql")
|
||||
assert view.path == Path(
|
||||
"sql/moz-fx-data-test-project/test/simple_view/view.sql"
|
||||
)
|
||||
assert "CREATE OR REPLACE VIEW" in view.content
|
||||
assert "`moz-fx-data-test-project.test.simple_view`" in view.content
|
||||
assert Path(
|
||||
"sql/moz-fx-data-test-project/test/dataset_metadata.yaml"
|
||||
).exists()
|
||||
assert Path(
|
||||
"sql/moz-fx-data-test-project/test/simple_view/view.sql"
|
||||
).exists()
|
||||
|
||||
view = View.create(
|
||||
"moz-fx-data-test-project",
|
||||
"test",
|
||||
"simple_view",
|
||||
"sql",
|
||||
base_table="moz-fx-data-test-project.test.some_table",
|
||||
)
|
||||
assert "`moz-fx-data-test-project.test.some_table`" in view.content
|
||||
|
||||
def test_view_invalid_path(self):
|
||||
with pytest.raises(ValueError):
|
||||
View(path="test", name="test", dataset="test", project="test")
|
||||
|
||||
@pytest.mark.java
|
||||
def test_view_valid(self, runner):
|
||||
with runner.isolated_filesystem():
|
||||
view = View.create("moz-fx-data-test-project", "test", "simple_view", "sql")
|
||||
assert view.is_valid()
|
||||
|
||||
@pytest.mark.java
|
||||
def test_view_invalid(self):
|
||||
view = View.create("moz-fx-data-test-project", "test", "simple_view", "sql")
|
||||
assert view.is_valid()
|
||||
|
||||
view.path.write_text("CREATE OR REPLACE VIEW test.simple_view AS SELECT 1")
|
||||
assert view.is_valid() is False
|
||||
|
||||
view.path.write_text("SELECT 1")
|
||||
assert view.is_valid() is False
|
||||
|
||||
view.path.write_text(
|
||||
"CREATE OR REPLACE VIEW `moz-fx-data-test-project.foo.bar` AS SELECT 1"
|
||||
)
|
||||
assert view.is_valid() is False
|
||||
|
||||
@pytest.mark.java
|
||||
def test_view_do_not_publish_invalid(self):
|
||||
view = View.create("moz-fx-data-test-project", "test", "simple_view", "sql")
|
||||
assert view.is_valid()
|
||||
view.path.write_text("SELECT 1")
|
||||
assert view.is_valid() is False
|
||||
assert view.publish() is False
|
Загрузка…
Ссылка в новой задаче