Skip to content

Commit

Permalink
fix schema.yml config validation for datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Sep 24, 2024
1 parent 0a48bb9 commit 165507a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
3 changes: 2 additions & 1 deletion core/dbt/artifacts/resources/v1/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
from dataclasses import dataclass, field
from datetime import datetime
from typing import Any, Dict, List, Optional, Union

from mashumaro.jsonschema.annotations import Pattern
Expand Down Expand Up @@ -82,7 +83,7 @@ class NodeConfig(NodeAndTestConfig):
incremental_strategy: Optional[str] = None
batch_size: Any = None
lookback: Any = 0
begin: Any = None
begin: Union[datetime, Any] = None
persist_docs: Dict[str, Any] = field(default_factory=dict)
post_hook: List[Hook] = field(
default_factory=list,
Expand Down
51 changes: 43 additions & 8 deletions tests/functional/microbatch/test_microbatch_config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@
select * from {{ ref('input_model') }}
"""

valid_microbatch_model_no_config_sql = """
select * from {{ ref('input_model') }}
"""

valid_microbatch_model_config_yml = """
models:
- name: microbatch
config:
materialized: incremental
incremental_strategy: microbatch
batch_size: day
event_time: event_time
begin: 2020-01-01
"""

missing_event_time_microbatch_model_sql = """
{{ config(materialized='incremental', incremental_strategy='microbatch', batch_size='day') }}
select * from {{ ref('input_model') }}
Expand Down Expand Up @@ -55,7 +70,7 @@
"""


class BaseMicrobatchTest:
class BaseMicrobatchTestParseError:
@pytest.fixture(scope="class")
def models(self):
return {}
Expand All @@ -66,7 +81,17 @@ def test_parsing_error_raised(self, project):
run_dbt(["parse"])


class TestMissingEventTimeMicrobatch(BaseMicrobatchTest):
class BaseMicrobatchTestNoError:
@pytest.fixture(scope="class")
def models(self):
return {}

@mock.patch.dict(os.environ, {"DBT_EXPERIMENTAL_MICROBATCH": "True"})
def test_parsing_error_not_raised(self, project):
run_dbt(["parse"])


class TestMissingEventTimeMicrobatch(BaseMicrobatchTestParseError):
@pytest.fixture(scope="class")
def models(self):
return {
Expand All @@ -75,7 +100,7 @@ def models(self):
}


class TestInvalidEventTimeMicrobatch(BaseMicrobatchTest):
class TestInvalidEventTimeMicrobatch(BaseMicrobatchTestParseError):
@pytest.fixture(scope="class")
def models(self):
return {
Expand All @@ -84,7 +109,7 @@ def models(self):
}


class TestMissingBeginMicrobatch(BaseMicrobatchTest):
class TestMissingBeginMicrobatch(BaseMicrobatchTestParseError):
@pytest.fixture(scope="class")
def models(self):
return {
Expand All @@ -93,7 +118,7 @@ def models(self):
}


class TestInvaliBeginMicrobatch(BaseMicrobatchTest):
class TestInvaliBeginMicrobatch(BaseMicrobatchTestParseError):
@pytest.fixture(scope="class")
def models(self):
return {
Expand All @@ -102,7 +127,7 @@ def models(self):
}


class TestMissingBatchSizeMicrobatch(BaseMicrobatchTest):
class TestMissingBatchSizeMicrobatch(BaseMicrobatchTestParseError):
@pytest.fixture(scope="class")
def models(self):
return {
Expand All @@ -111,7 +136,7 @@ def models(self):
}


class TestInvalidBatchSizeMicrobatch(BaseMicrobatchTest):
class TestInvalidBatchSizeMicrobatch(BaseMicrobatchTestParseError):
@pytest.fixture(scope="class")
def models(self):
return {
Expand All @@ -120,10 +145,20 @@ def models(self):
}


class TestInvalidInputEventTimeMicrobatch(BaseMicrobatchTest):
class TestInvalidInputEventTimeMicrobatch(BaseMicrobatchTestParseError):
@pytest.fixture(scope="class")
def models(self):
return {
"input_model.sql": invalid_event_time_input_model_sql,
"microbatch.sql": valid_microbatch_model_sql,
}


class TestValidBeginMicrobatch(BaseMicrobatchTestNoError):
@pytest.fixture(scope="class")
def models(self):
return {
"input_model.sql": valid_input_model_sql,
"microbatch.sql": valid_microbatch_model_no_config_sql,
"schema.yml": valid_microbatch_model_config_yml,
}

0 comments on commit 165507a

Please sign in to comment.