agvdndor commented on code in PR #23094: URL: https://github.com/apache/beam/pull/23094#discussion_r1011676424
########## sdks/python/apache_beam/examples/ml-orchestration/kfp/components/ingestion/src/ingest.py: ########## @@ -0,0 +1,74 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Dummy ingestion function that fetches data from one file and simply copies it to another.""" + +import argparse +import time +from pathlib import Path + + +def parse_args(): + """Parse ingestion arguments.""" + parser = argparse.ArgumentParser() + parser.add_argument( + "--ingested-dataset-path", + type=str, + help="Path to save the ingested dataset to.", + required=True) + parser.add_argument( + "--base-artifact-path", + type=str, + help="Base path to store pipeline artifacts.", + required=True) + return parser.parse_args() + + +def dummy_ingest_data(ingested_dataset_path: str, base_artifact_path: str): + """Dummy data ingestion step that returns an uri + to the data it has 'ingested' as jsonlines. + + Args: + data_ingestion_target (str): uri to the data that was scraped and + ingested by the component""" + # timestamp as unique id for the component execution + timestamp = int(time.time()) + + # create directory to store the actual data + target_path = f"{base_artifact_path}/ingestion/ingested_dataset_{timestamp}.jsonl" + # if the target path is a google cloud storage path convert the path to the gcsfuse path + target_path_gcsfuse = target_path.replace("gs://", "/gcs/") + Path(target_path_gcsfuse).parent.mkdir(parents=True, exist_ok=True) + + with open(target_path_gcsfuse, 'w') as f: + f.writelines([ + """{"image_id": 318556, "id": 255, "caption": "An angled view of a beautifully decorated bathroom.", "image_url": "http://farm4.staticflickr.com/3133/3378902101_3c9fa16b84_z.jpg", "image_name": "COCO_train2014_000000318556.jpg", "image_license": "Attribution-NonCommercial-ShareAlike License"}\n""", Review Comment: We definitely could. My thinking here was that this way it's explicit and visible that each json dict spans exactly one line resulting in the jsonlines format. If it is fine for you either way, I propose we leave it like this. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
