Coverage for python/felis/visitor.py: 85%
34 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-20 03:38 -0700
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-20 03:38 -0700
1# This file is part of felis.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22from __future__ import annotations
24__all__ = ["Visitor"]
26from abc import ABC, abstractmethod
27from collections.abc import Iterable, Mapping
28from typing import Any, Generic, TypeVar
30_Schema = TypeVar("_Schema")
31_SchemaVersion = TypeVar("_SchemaVersion")
32_Table = TypeVar("_Table")
33_Column = TypeVar("_Column")
34_PrimaryKey = TypeVar("_PrimaryKey")
35_Constraint = TypeVar("_Constraint")
36_Index = TypeVar("_Index")
39class Visitor(ABC, Generic[_Schema, _Table, _Column, _PrimaryKey, _Constraint, _Index, _SchemaVersion]):
40 """Abstract interface for visitor classes working on a Felis tree.
42 Clients will only normally use `visit_schema` method, other methods
43 defined in this interface should be called by implementation of
44 `visit_schema` and the methods called from it.
45 """
47 @abstractmethod
48 def visit_schema(self, schema_obj: Mapping[str, Any]) -> _Schema:
49 """Visit Felis schema object.
51 Parameters
52 ----------
53 schema_obj : `Mapping` [ `str`, `Any` ]
54 Felis object (mapping) representing a schema.
56 Returns
57 -------
58 schema : `_Schema`
59 Returns schema representation, type depends on implementation.
60 """
61 raise NotImplementedError()
63 @abstractmethod
64 def visit_schema_version(
65 self, version_obj: str | Mapping[str, Any], schema_obj: Mapping[str, Any]
66 ) -> _SchemaVersion:
67 """Visit schema version object.
69 Parameters
70 ----------
71 version_obj : `str` or `Mapping` [ `str`, `Any` ]
72 String of object describing schema version.
73 schema_obj : `Mapping` [ `str`, `Any` ]
74 Felis object (mapping) representing parent schema.
76 Returns
77 -------
78 schema_version : `_SchemaVersion`
79 Returns version representation, type depends on implementation.
80 """
81 raise NotImplementedError()
83 @abstractmethod
84 def visit_table(self, table_obj: Mapping[str, Any], schema_obj: Mapping[str, Any]) -> _Table:
85 """Visit Felis table object, this method is usually called from
86 `visit_schema`, clients normally do not need to call it directly.
88 Parameters
89 ----------
90 table_obj : `Mapping` [ `str`, `Any` ]
91 Felis object (mapping) representing a table.
92 schema_obj : `Mapping` [ `str`, `Any` ]
93 Felis object (mapping) representing parent schema.
95 Returns
96 -------
97 table : `_Table`
98 Returns table representation, type depends on implementation.
99 """
100 raise NotImplementedError()
102 @abstractmethod
103 def visit_column(self, column_obj: Mapping[str, Any], table_obj: Mapping[str, Any]) -> _Column:
104 """Visit Felis column object, this method is usually called from
105 `visit_table`, clients normally do not need to call it directly.
107 Parameters
108 ----------
109 column_obj : `Mapping` [ `str`, `Any` ]
110 Felis object (mapping) representing a column.
111 table_obj : `Mapping` [ `str`, `Any` ]
112 Felis object (mapping) representing parent table.
114 Returns
115 -------
116 column : `_Column`
117 Returns column representation, type depends on implementation.
118 """
119 raise NotImplementedError()
121 @abstractmethod
122 def visit_primary_key(
123 self, primary_key_obj: str | Iterable[str], table_obj: Mapping[str, Any]
124 ) -> _PrimaryKey:
125 """Visit Felis primary key object, this method is usually called from
126 `visit_table`, clients normally do not need to call it directly.
128 Parameters
129 ----------
130 primary_key_obj : `str` or `Mapping` [ `str`, `Any` ]
131 Felis object (mapping) representing a primary key.
132 table_obj : `Mapping` [ `str`, `Any` ]
133 Felis object (mapping) representing parent table.
135 Returns
136 -------
137 pk : `_PrimaryKey`
138 Returns primary key representation, type depends on implementation.
139 """
140 raise NotImplementedError()
142 @abstractmethod
143 def visit_constraint(
144 self, constraint_obj: Mapping[str, Any], table_obj: Mapping[str, Any]
145 ) -> _Constraint:
146 """Visit Felis constraint object, this method is usually called from
147 `visit_table`, clients normally do not need to call it directly.
149 Parameters
150 ----------
151 constraint_obj : `Mapping` [ `str`, `Any` ]
152 Felis object (mapping) representing a constraint.
153 table_obj : `Mapping` [ `str`, `Any` ]
154 Felis object (mapping) representing parent table.
156 Returns
157 -------
158 constraint : `_Constraint`
159 Returns primary key representation, type depends on implementation.
160 """
161 raise NotImplementedError()
163 @abstractmethod
164 def visit_index(self, index_obj: Mapping[str, Any], table_obj: Mapping[str, Any]) -> _Index:
165 """Visit Felis index object, this method is usually called from
166 `visit_table`, clients normally do not need to call it directly.
168 Parameters
169 ----------
170 index_obj : `Mapping` [ `str`, `Any` ]
171 Felis object (mapping) representing an index.
172 table_obj : `Mapping` [ `str`, `Any` ]
173 Felis object (mapping) representing parent table.
175 Returns
176 -------
177 index : `_Index`
178 Returns index representation, type depends on implementation.
179 """
180 raise NotImplementedError()