Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Add KlioWriteToText missing fields including file_name_suffix,… #200

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def get_long_description(package_dir):
}
META_FILE = read(META_PATH)
INSTALL_REQUIRES = [
"apache-beam[gcp]",
"click",
"glom",
"google-api-python-client",
Expand Down
9 changes: 8 additions & 1 deletion core/src/klio_core/config/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
import json
import logging


import attr
from apache_beam.io.filesystem import CompressionTypes


logger = logging.getLogger("klio")

Expand Down Expand Up @@ -255,6 +256,7 @@ def from_dict(cls, config_dict, *args, **kwargs):

class KlioFileConfig(object):
name = "file"
compression_type = attr.attrib(type=str, default=CompressionTypes.AUTO)


@attr.attrs(frozen=True)
Expand Down Expand Up @@ -286,6 +288,11 @@ def as_dict(self):
@attr.attrs(frozen=True)
class KlioWriteFileConfig(KlioEventOutput, KlioFileConfig):
file_path_prefix = attr.attrib(type=str)
file_name_suffix = attr.attrib(type=str, default="")
append_trailing_newlines = attr.attrib(type=bool, default=True)
num_shards = attr.attrib(type=int, default=0)
shard_name_template = attr.attrib(type=str, default=None)
header = attr.attrib(type=str, default=None)
shireen-bean marked this conversation as resolved.
Show resolved Hide resolved

@classmethod
def from_dict(cls, config_dict, *args, **kwargs):
Expand Down
28 changes: 22 additions & 6 deletions core/tests/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,17 +432,33 @@ def test_klio_read_file_config():
assert config_dict["location"] == klio_read_file_config.file_pattern


def test_klio_write_file_config():
config_dict = {
"type": "GCS",
"location": "gs://sigint-output/test-parent-job-out",
}
@pytest.mark.parametrize(
"config_dict",
(
# The minimum inputs
{"type": "GCS", "location": "gs://sigint-output/test-parent-job-out"},
# Other fields configured
{
"type": "GCS",
"location": "gs://sigint-output/test-parent-job-out",
"file_name_suffix": ".txt",
"num_shards": 3,
"append_trailing_newlines": True,
},
),
)
def test_klio_write_file_config(config_dict):
klio_write_file_config = io.KlioWriteFileConfig.from_dict(
config_dict, io.KlioIOType.DATA, io.KlioIODirection.OUTPUT
)

config_dict.pop("type")
assert "file" == klio_write_file_config.name
assert config_dict["location"] == klio_write_file_config.file_path_prefix
for k, v in config_dict.items():
if k == "location":
assert v == klio_write_file_config.file_path_prefix
else:
assert v == getattr(klio_write_file_config, k)


def test_klio_write_bigquery_config():
Expand Down
10 changes: 9 additions & 1 deletion core/tox.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
[tox]
envlist = py36,py37,py38,docs,manifest,check-formatting,lint
envlist = {py36,py37,py38}-beam{26,27,28},docs,manifest,check-formatting,lint

[testenv]
install_command = python -m pip install {opts} {packages}
extras = tests
deps =
{toxinidir}/../core
beam26: apache-beam[gcp]>=2.26.0,<2.27.0
beam27: apache-beam[gcp]>=2.27.0,<2.28.0
beam28: apache-beam[gcp]>=2.28.0,<2.29.0

commands =
coverage run -m pytest {posargs}
; assert that protos are compiled
Expand Down Expand Up @@ -85,6 +91,8 @@ filterwarnings =
ignore:invalid escape sequence:DeprecationWarning
; 3rd party libraries haven't updated their use of collections.abc (py37+)
ignore:Using or importing the ABCs from:DeprecationWarning
; Apache Beam-related warnings
ignore:Running the Apache Beam SDK on Python 3:UserWarning

; required for mapping envs -> github runtimes
[gh-actions]
Expand Down