{"id":22125894,"url":"https://github.com/moeabbas6/bq_data_loader","last_synced_at":"2025-03-24T08:16:18.708Z","repository":{"id":257252326,"uuid":"857734649","full_name":"moeabbas6/bq_data_loader","owner":"moeabbas6","description":"A Python script for executing and logging batch SQL commands in Google BigQuery. Includes tracking of execution times, unique job and statement IDs, and automated logging to a specified BigQuery table.","archived":false,"fork":false,"pushed_at":"2024-09-15T13:33:20.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-29T13:28:27.154Z","etag":null,"topics":["bigquery","data","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moeabbas6.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-09-15T13:24:55.000Z","updated_at":"2024-10-19T14:25:26.000Z","dependencies_parsed_at":"2024-09-15T15:06:34.970Z","dependency_job_id":null,"html_url":"https://github.com/moeabbas6/bq_data_loader","commit_stats":null,"previous_names":["moeabbas6/bq_data_loader"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moeabbas6%2Fbq_data_loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moeabbas6%2Fbq_data_loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moeabbas6%2Fbq_data_loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moeabbas6%2Fbq_data_loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moeabbas6","download_url":"https://codeload.github.com/moeabbas6/bq_data_loader/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245232888,"owners_count":20581702,"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":["bigquery","data","python"],"created_at":"2024-12-01T16:40:25.157Z","updated_at":"2025-03-24T08:16:18.673Z","avatar_url":"https://github.com/moeabbas6.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# BigQuery Data Loader\n\n`bq_data_loader.py` is a Python script designed to execute a batch of SQL commands on Google BigQuery, track execution times, and log the results into a specified BigQuery table for auditing and monitoring purposes.\n\n## Features\n\n- Execute multiple SQL commands in BigQuery.\n- Log execution details, including elapsed time, for each SQL statement.\n- Track the execution using unique job and statement IDs.\n- Automatically log the results into a specified BigQuery table.\n- Fully configurable for various SQL commands and output destinations.\n\n## Requirements\n\n- Python 3.6+\n- Google Cloud BigQuery client library (`google-cloud-bigquery`)\n- Pandas (`pandas`)\n- PyArrow (`pyarrow`)\n\n## Installation\n\n1. Clone the repository:\n\n   ```bash\n   git clone https://github.com/yourusername/bq_data_loader.git\n   cd bq_data_loader\n   ```\n\n2. Create a virtual environment and activate it:\n\n   ```bash\n   python3 -m venv venv\n   source venv/bin/activate\n   ```\n\n3. Install the required packages:\n\n   ```bash\n   pip install -r requirements.txt\n   ```\n\n   **Note:** Ensure you have the `google-cloud-bigquery`, `pandas`, and `pyarrow` libraries installed.\n\n4. Set up your Google Cloud credentials:\n\n   ```bash\n   export GOOGLE_APPLICATION_CREDENTIALS=\"/path/to/your/service-account-file.json\"\n   ```\n\n5. Make the Script Executable:\n\n   ```bash\n   chmod +x bq_data_loader.py\n   ```\n\n## Usage\n\n1. Customize the script by editing the following sections in `bq_data_loader.py`:\n   - **SQL Statements:** Modify the `sql_statements` list to include your SQL commands.\n   - **BigQuery Table ID:** Set the `bq_table_id` variable to the table where you want to log the results.\n\n   Example:\n\n   ```python\n   sql_statements = [\n       \"YOUR_SQL_COMMAND_1_HERE;\",\n       \"YOUR_SQL_COMMAND_2_HERE;\",\n       \"YOUR_SQL_COMMAND_3_HERE;\"\n   ]\n\n   bq_table_id = \"your_project.your_dataset.your_table\"\n   ```\n\n2. Run the script:\n\n   ```bash\n   ./bq_data_loader.py\n   ```\n\n3. The script will execute each SQL command, log the execution details, and append the results to your specified BigQuery table. The total execution time will be printed in the terminal.\n\n## Example\n\nHere is an example of how you might configure the script:\n\n```python\nsql_statements = [\n    \"CREATE OR REPLACE TABLE `project.dataset.customers` AS (SELECT * FROM `project.dataset.customers_v`);\",\n    \"CREATE OR REPLACE TABLE `project.dataset.orders` AS (SELECT * FROM `project.dataset.orders_v`);\"\n]\n\nbq_table_id = \"project.dataset.execution_logs\"\n```\n\n## Contributing\n\nFeel free to open an issue or submit a pull request if you have any improvements or suggestions!\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoeabbas6%2Fbq_data_loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoeabbas6%2Fbq_data_loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoeabbas6%2Fbq_data_loader/lists"}