Skip to content

Commit

Permalink
[core] Remove multi-naming schema
Browse files Browse the repository at this point in the history
  • Loading branch information
shireen-bean committed Mar 30, 2021
1 parent dcb64c3 commit 69941d3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 52 deletions.
11 changes: 3 additions & 8 deletions core/src/klio_core/config/_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.
#

import collections
import string

import glom
Expand Down Expand Up @@ -46,7 +45,7 @@ def _transform_io_list(io_subsection_list):
"""Transform lists of dicts into a nested dict of dicts, where the keys
for the top-level dict come from the `name` field in the nested dict.
If `name` is not present, a name is auto-generated based on the index
of the I/O and it's type.
of the I/O.
example:
Expand Down Expand Up @@ -77,16 +76,12 @@ def _transform_io_list(io_subsection_list):
}
"""

type_counters = collections.defaultdict(int)
io_dict = {}
for conf in io_subsection_list:
for count, conf in enumerate(io_subsection_list):
if "name" in conf:
name = conf["name"]
else:
type_name = conf.get("type", "unknown")
type_id = type_counters[type_name]
type_counters[type_name] += 1
name = "{}{}".format(type_name, type_id)
name = count

io_dict[name] = conf

Expand Down
96 changes: 52 additions & 44 deletions core/tests/config/test_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,53 +226,61 @@ def test_apply_templates(
@pytest.mark.parametrize(
"config,expected",
(
# No overrides given - no changes in returned dict
(
{
"job_config": {
"events": {
"inputs": [
{"type": "bq", "key": "value"},
{"type": "bq", "key": "value2"},
{"type": "gcs", "gcskey": "gcsvalue"},
],
"outputs": [
{"type": "bq", "key": "value", "name": "mybq"},
{"type": "bq", "key": "value2"},
],
},
"data": {
"inputs": [],
"outputs": [
{"type": "bq", "key": "value", "name": "mybq"},
{"type": "bq", "key": "value2"},
],
},
}
# No overrides given - no changes in returned dict
(
{
"job_config": {
"events": {
"inputs": [
{"type": "bq", "key": "value"},
{"type": "bq", "key": "value2"},
{"type": "gcs", "gcskey": "gcsvalue"},
],
"outputs": [
{"type": "bq", "key": "value", "name": "mybq"},
{"type": "bq", "key": "value2"},
],
},
{
"job_config": {
"events": {
"inputs": {
"bq0": {"type": "bq", "key": "value"},
"bq1": {"type": "bq", "key": "value2"},
"gcs0": {"type": "gcs", "gcskey": "gcsvalue"},
},
"outputs": {
"mybq": {"type": "bq", "key": "value", "name": "mybq"},
"bq0": {"type": "bq", "key": "value2"},
},
"data": {
"inputs": [],
"outputs": [
{"type": "bq", "key": "value", "name": "mybq"},
{"type": "bq", "key": "value2"},
],
},
}
},
{
"job_config": {
"events": {
"inputs": {
0: {"type": "bq", "key": "value"},
1: {"type": "bq", "key": "value2"},
2: {"type": "gcs", "gcskey": "gcsvalue"},
},
"outputs": {
"mybq": {
"type": "bq",
"key": "value",
"name": "mybq",
},
"data": {
"inputs": {},
"outputs": {
"mybq": {"type": "bq", "key": "value", "name": "mybq"},
"bq0": {"type": "bq", "key": "value2"},
},
1: {"type": "bq", "key": "value2"},
},
},
"data": {
"inputs": {},
"outputs": {
"mybq": {
"type": "bq",
"key": "value",
"name": "mybq",
},
}
}
),
1: {"type": "bq", "key": "value2"},
},
},
}
},
),
),
)
def test_transform_io(kcp, config, expected):
Expand Down

0 comments on commit 69941d3

Please sign in to comment.