{"id":27443896,"url":"https://github.com/josephmachado/cost_effective_data_pipelines","last_synced_at":"2025-04-15T02:58:07.242Z","repository":{"id":241806837,"uuid":"807320809","full_name":"josephmachado/cost_effective_data_pipelines","owner":"josephmachado","description":"Cost Efficient Data Pipelines with DuckDB","archived":false,"fork":false,"pushed_at":"2024-07-31T20:36:40.000Z","size":16138,"stargazers_count":51,"open_issues_count":0,"forks_count":74,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T02:58:00.304Z","etag":null,"topics":["duckdb","python","sql"],"latest_commit_sha":null,"homepage":"https://www.startdataengineering.com/post/cost-effective-pipelines/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/josephmachado.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-28T21:59:33.000Z","updated_at":"2025-03-26T05:15:35.000Z","dependencies_parsed_at":"2024-06-14T15:16:23.027Z","dependency_job_id":"ad261552-2fd5-4345-b547-18441c2b4d20","html_url":"https://github.com/josephmachado/cost_effective_data_pipelines","commit_stats":null,"previous_names":["josephmachado/cost_effective_data_pipelines"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephmachado%2Fcost_effective_data_pipelines","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephmachado%2Fcost_effective_data_pipelines/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephmachado%2Fcost_effective_data_pipelines/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephmachado%2Fcost_effective_data_pipelines/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/josephmachado","download_url":"https://codeload.github.com/josephmachado/cost_effective_data_pipelines/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248997095,"owners_count":21195797,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["duckdb","python","sql"],"created_at":"2025-04-15T02:58:06.658Z","updated_at":"2025-04-15T02:58:07.235Z","avatar_url":"https://github.com/josephmachado.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"* [Cost Effective Data Pipelines](#cost-effective-data-pipelines)\n    * [Setup](#setup)\n        * [Run on CodeSpaces](#run-on-codespaces)\n        * [Run code on your machine](#run-code-on-your-machine)\n    * [Generate data](#generate-data)\n    * [Data processing](#data-processing)\n\n# Cost Effective Data Pipelines\n\nCode for blog at: [Building cost effective data pipelines with Python \u0026 DuckDB](https://www.startdataengineering.com/post/cost-effective-pipelines/) \n\n## Setup\n\n### Run on CodeSpaces\n\nYou can run the code in the repo with Codespaces. \n\n1. Fork this repo.\n2. Click on code button and select the codespaces tab.\n3. Click on the `Create codespace on main` button.\n\n![Create codespace](./assets/cs.png)\n\nWhen codespaces open, wait for it to complete installing the required libraries from [./requirements.txt](./requirements.txt).\n\n![Create codespace](./assets/cs2.png)\n\nYou can open a Python REPL and run the scripts in the [generate data section](#generate-data).\n\n### Run code on your machine\n\nAlternatively you can run this code on your machine. You'll need the following:\n\n1. [Python 3.8 or above](https://www.python.org/downloads/)\n2. [sqlite3](https://www.sqlite.org/index.html)\n3. Sufficient disk memory (depending on if you want to run with 1 or 10 or 100GB)\n\n\nClone the repo and create a virtual env and install the libraries needed:\n\n```bash\ngit clone https://github.com/josephmachado/cost_effective_data_pipelines.git\ncd cost_effective_data_pipelines\n\npython3 -m venv myenv\n# windows\n# myenv\\Scripts\\activate\n# Linux\nsource myenv/bin/activate\npip install -r requirements.txt\n# After you are done, deactivate with the command `deactivate`\n```\n\n## Generate data\n\nFor the example in this repo we use the TPC-H data set and Coincap API.\nLet's generate the TPCH data, by running the following commands in your terminal:\n\n```bash\n# NOTE: This is to clean up any data (if present) \nrm tpch-dbgen/*.tbl\n# Generate data set of 1 GB size\ncd tpch-dbgen\nmake\n./dbgen -s 1 # Change this number to generate a data of desired size\ncd ..\n\n# NOTE: Load the generated data into a tpch sqlite3 db\nsqlite3 tpch.db \u003c ./upstream_db/tpch_DDL_DML.sql \u003e /dev/null 2\u003e\u00261\n```\n\nLet's open a sqlite3 shell and run a quick count check to ensure that the tables were loaded properly.\n\n```sql\nsqlite3 tpch.db\n.read ./upstream_db/count_test.sql\n/* \nYour output will be (if you generated a 1GB dataset)\n150000\n6001215\n25\n1500000\n200000\n800000\n5\n10000\n*/\n.exit  -- exit sqlite3\n```\n\n## Data processing\n\nYou can run the ETL scripts using the `make up` command. \n```bash\nmake up\n```\n\nAlternatively you can run the scripts individually as shown below.\n\n```bash\ntime python ./src/data_processor/exchange_data.py 2024-05-29\ntime python ./src/data_processor/dim_parts_supplier.py 2024-05-29\ntime python ./src/data_processor/one_big_table.py 2024-05-29\ntime python ./src/data_processor/wide_month_supplier_metrics.py 2024-05-29\n# This last script will fail on base CodeSpace VM, see here for powerful Codespace VMS:`\n# https://docs.github.com/en/codespaces/customizing-your-codespace/changing-the-machine-type-for-your-codespace?tool=webui\n```\n\nRunning the ETL on a 8 core, 32 GB RAM, 1TB HDD 2017 Thinkpad with performs as shown below. The script [wide_month_supplier_metrics.py](./src/data_processor/wide_month_supplier_metrics.py) ran in 7m and 20s, this included reading in about 10GB of data, ineffectively processing it and writing it out.\n\nResource utilization:\n\n![htop](./assets/htop.png)\n\n**NOTE:** The code in this repo can be optimized following principles stated in [this performance guide](https://duckdb.org/docs/guides/performance/overview.html).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosephmachado%2Fcost_effective_data_pipelines","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjosephmachado%2Fcost_effective_data_pipelines","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosephmachado%2Fcost_effective_data_pipelines/lists"}