python-table-processor 0.2.29__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_table_processor-0.2.29.dist-info/LICENSE +21 -0
- python_table_processor-0.2.29.dist-info/METADATA +28 -0
- python_table_processor-0.2.29.dist-info/RECORD +21 -0
- python_table_processor-0.2.29.dist-info/WHEEL +4 -0
- python_table_processor-0.2.29.dist-info/entry_points.txt +4 -0
- table_processor/__init__.py +2 -0
- table_processor/cli.py +66 -0
- table_processor/commands/convert_tables.py +80 -0
- table_processor/core/actions.py +601 -0
- table_processor/core/config.py +365 -0
- table_processor/core/constants.py +5 -0
- table_processor/core/convert.py +402 -0
- table_processor/core/functions/assign_id.py +75 -0
- table_processor/core/functions/flatten_row.py +24 -0
- table_processor/core/functions/get_nested_field_value.py +22 -0
- table_processor/core/functions/nest_row.py +25 -0
- table_processor/core/functions/search_column_value.py +26 -0
- table_processor/core/functions/set_flat_field_value.py +23 -0
- table_processor/core/functions/set_nested_field_value.py +24 -0
- table_processor/core/functions/set_row_value.py +33 -0
- table_processor/core/types.py +118 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
'''
|
|
2
|
+
This module contains the dataclasses that are used to define the configuration
|
|
3
|
+
for the table_converter package.
|
|
4
|
+
'''
|
|
5
|
+
|
|
6
|
+
import dataclasses
|
|
7
|
+
|
|
8
|
+
from collections import (
|
|
9
|
+
OrderedDict,
|
|
10
|
+
defaultdict,
|
|
11
|
+
)
|
|
12
|
+
from dataclasses import dataclass
|
|
13
|
+
from typing import (
|
|
14
|
+
Any,
|
|
15
|
+
Literal,
|
|
16
|
+
Mapping,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
@dataclasses.dataclass
|
|
20
|
+
class Row:
|
|
21
|
+
flat: OrderedDict
|
|
22
|
+
nested: OrderedDict
|
|
23
|
+
|
|
24
|
+
@dataclasses.dataclass
|
|
25
|
+
class AssignConfig:
|
|
26
|
+
target: str
|
|
27
|
+
source: str
|
|
28
|
+
assign_default: bool = False
|
|
29
|
+
default_value: Any = None
|
|
30
|
+
required: bool = False
|
|
31
|
+
|
|
32
|
+
@dataclasses.dataclass
|
|
33
|
+
class AssignConstantConfig:
|
|
34
|
+
target: str
|
|
35
|
+
value: Any
|
|
36
|
+
|
|
37
|
+
@dataclasses.dataclass
|
|
38
|
+
class AssignFormatConfig:
|
|
39
|
+
target: str
|
|
40
|
+
format: str
|
|
41
|
+
|
|
42
|
+
@dataclasses.dataclass
|
|
43
|
+
class AssignIdConfig:
|
|
44
|
+
target: str
|
|
45
|
+
primary: list[str]
|
|
46
|
+
context: list[str] | None = None
|
|
47
|
+
|
|
48
|
+
@dataclasses.dataclass
|
|
49
|
+
class FilterConfig:
|
|
50
|
+
field: str
|
|
51
|
+
operator: Literal[
|
|
52
|
+
'==', '!=', '>', '>=', '<', '<=', '=~', 'not-in',
|
|
53
|
+
'empty', 'not-empty',
|
|
54
|
+
]
|
|
55
|
+
value: str | list[str]
|
|
56
|
+
|
|
57
|
+
@dataclasses.dataclass
|
|
58
|
+
class JoinConfig:
|
|
59
|
+
target: str
|
|
60
|
+
source: str
|
|
61
|
+
delimiter: str | None = None
|
|
62
|
+
|
|
63
|
+
@dataclasses.dataclass
|
|
64
|
+
class OmitConfig:
|
|
65
|
+
field: str
|
|
66
|
+
|
|
67
|
+
@dataclasses.dataclass
|
|
68
|
+
class ParseConfig:
|
|
69
|
+
target: str
|
|
70
|
+
source: str
|
|
71
|
+
as_type: Literal['json', 'literal']
|
|
72
|
+
required: bool = False
|
|
73
|
+
|
|
74
|
+
@dataclasses.dataclass
|
|
75
|
+
class PickConfig:
|
|
76
|
+
target: str
|
|
77
|
+
source: str
|
|
78
|
+
|
|
79
|
+
@dataclasses.dataclass
|
|
80
|
+
class SplitConfig:
|
|
81
|
+
target: str
|
|
82
|
+
source: str
|
|
83
|
+
delimiter: str | None = None
|
|
84
|
+
|
|
85
|
+
ActionConfig = \
|
|
86
|
+
AssignIdConfig | \
|
|
87
|
+
AssignConstantConfig | \
|
|
88
|
+
AssignFormatConfig | \
|
|
89
|
+
FilterConfig | \
|
|
90
|
+
SplitConfig
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
type ContextColumnTuple = tuple[str]
|
|
94
|
+
type ContextValueTuple = tuple
|
|
95
|
+
type PrimaryColumnTuple = tuple[str]
|
|
96
|
+
type PrimaryValueTuple = tuple
|
|
97
|
+
|
|
98
|
+
@dataclasses.dataclass
|
|
99
|
+
class IdMap:
|
|
100
|
+
max_id: int = 0
|
|
101
|
+
dict_value_to_id: Mapping[PrimaryValueTuple, int] = \
|
|
102
|
+
dataclasses.field(default_factory=defaultdict)
|
|
103
|
+
dict_id_to_value: Mapping[int, PrimaryValueTuple] = \
|
|
104
|
+
dataclasses.field(default_factory=defaultdict)
|
|
105
|
+
|
|
106
|
+
type IdContextMap = Mapping[
|
|
107
|
+
(
|
|
108
|
+
ContextColumnTuple,
|
|
109
|
+
ContextValueTuple,
|
|
110
|
+
PrimaryColumnTuple,
|
|
111
|
+
),
|
|
112
|
+
IdMap
|
|
113
|
+
]
|
|
114
|
+
|
|
115
|
+
@dataclasses.dataclass
|
|
116
|
+
class GlobalStatus:
|
|
117
|
+
id_context_map: IdContextMap = \
|
|
118
|
+
dataclasses.field(default_factory=lambda: defaultdict(IdMap))
|