Пример #1
0
 def transform(self, node: IntermediateSnapshotNode) -> ParsedSnapshotNode:
     try:
         parsed_node = ParsedSnapshotNode.from_dict(node.to_dict())
         self.set_snapshot_attributes(parsed_node)
         return parsed_node
     except ValidationError as exc:
         raise CompilationException(validator_error_message(exc), node)
Пример #2
0
    def test_check_ok(self):
        node_dict = {
            'name': 'foo',
            'root_path': '/root/',
            'resource_type': str(NodeType.Snapshot),
            'path': '/root/x/path.sql',
            'original_file_path': '/root/path.sql',
            'package_name': 'test',
            'raw_sql': 'select * from wherever',
            'unique_id': 'model.test.foo',
            'fqn': ['test', 'models', 'foo'],
            'refs': [],
            'sources': [],
            'depends_on': {
                'macros': [],
                'nodes': []
            },
            'database': 'test_db',
            'description': '',
            'schema': 'test_schema',
            'alias': 'bar',
            'tags': [],
            'config': {
                'column_types': {},
                'enabled': True,
                'materialized': 'snapshot',
                'persist_docs': {},
                'post-hook': [],
                'pre-hook': [],
                'quoting': {},
                'tags': [],
                'vars': {},
                'target_database': 'some_snapshot_db',
                'target_schema': 'some_snapshot_schema',
                'unique_key': 'id',
                'strategy': 'check',
                'check_cols': 'all',
            },
            'docs': {
                'show': True
            },
            'columns': {},
            'meta': {},
        }

        node = self.ContractType(
            package_name='test',
            root_path='/root/',
            path='/root/x/path.sql',
            original_file_path='/root/path.sql',
            raw_sql='select * from wherever',
            name='foo',
            resource_type=NodeType.Snapshot,
            unique_id='model.test.foo',
            fqn=['test', 'models', 'foo'],
            refs=[],
            sources=[],
            depends_on=DependsOn(),
            description='',
            database='test_db',
            schema='test_schema',
            alias='bar',
            tags=[],
            config=CheckSnapshotConfig(
                strategy=SnapshotStrategy.Check,
                unique_key='id',
                check_cols=All.All,
                target_database='some_snapshot_db',
                target_schema='some_snapshot_schema',
            ),
        )
        cfg = EmptySnapshotConfig()
        cfg._extra.update({
            'unique_key': 'id',
            'strategy': 'check',
            'check_cols': 'all',
            'target_database': 'some_snapshot_db',
            'target_schema': 'some_snapshot_schema',
        })

        inter = IntermediateSnapshotNode(
            package_name='test',
            root_path='/root/',
            path='/root/x/path.sql',
            original_file_path='/root/path.sql',
            raw_sql='select * from wherever',
            name='foo',
            resource_type=NodeType.Snapshot,
            unique_id='model.test.foo',
            fqn=['test', 'models', 'foo'],
            refs=[],
            sources=[],
            depends_on=DependsOn(),
            description='',
            database='test_db',
            schema='test_schema',
            alias='bar',
            tags=[],
            config=cfg,
        )
        self.assert_symmetric(node, node_dict)
        self.assert_symmetric(inter, node_dict, cls=IntermediateSnapshotNode)
        self.assertEqual(self.ContractType.from_dict(inter.to_dict()), node)
        self.assertTrue(node.is_refable)
        self.assertFalse(node.is_ephemeral)
Пример #3
0
    def test_timestamp_ok(self):
        node_dict = self._ts_ok()

        node = self.ContractType(
            package_name='test',
            root_path='/root/',
            path='/root/x/path.sql',
            original_file_path='/root/path.sql',
            raw_sql='select * from wherever',
            name='foo',
            resource_type=NodeType.Snapshot,
            unique_id='model.test.foo',
            fqn=['test', 'models', 'foo'],
            refs=[],
            sources=[],
            depends_on=DependsOn(),
            description='',
            database='test_db',
            schema='test_schema',
            alias='bar',
            tags=[],
            config=TimestampSnapshotConfig(
                strategy=SnapshotStrategy.Timestamp,
                unique_key='id',
                updated_at='last_update',
                target_database='some_snapshot_db',
                target_schema='some_snapshot_schema',
            ),
        )

        cfg = EmptySnapshotConfig()
        cfg._extra.update({
            'strategy': 'timestamp',
            'unique_key': 'id',
            'updated_at': 'last_update',
            'target_database': 'some_snapshot_db',
            'target_schema': 'some_snapshot_schema',
        })

        inter = IntermediateSnapshotNode(
            package_name='test',
            root_path='/root/',
            path='/root/x/path.sql',
            original_file_path='/root/path.sql',
            raw_sql='select * from wherever',
            name='foo',
            resource_type=NodeType.Snapshot,
            unique_id='model.test.foo',
            fqn=['test', 'models', 'foo'],
            refs=[],
            sources=[],
            depends_on=DependsOn(),
            description='',
            database='test_db',
            schema='test_schema',
            alias='bar',
            tags=[],
            config=cfg,
        )
        self.assert_symmetric(node, node_dict)
        self.assert_symmetric(inter, node_dict, cls=IntermediateSnapshotNode)
        self.assertEqual(self.ContractType.from_dict(inter.to_dict()), node)
        self.assertTrue(node.is_refable)
        self.assertFalse(node.is_ephemeral)
        pickle.loads(pickle.dumps(node))