Skip to content

Commit

Permalink
Merge pull request #230 from felippecaso/feat/add_s3_support_excel
Browse files Browse the repository at this point in the history
Add s3 support to Excel plugin through env variables
  • Loading branch information
jwills authored Aug 9, 2023
2 parents 8b6f366 + e56f3b3 commit b646c61
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion dbt/adapters/duckdb/plugins/excel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import os
import pathlib
from typing import Any
from typing import Dict

import pandas as pd

Expand All @@ -7,9 +10,22 @@


class Plugin(BasePlugin):
def initialize(self, plugin_config: Dict[str, Any]):
# Pass s3 settings to plugin environment
if "s3_access_key_id" in plugin_config:
os.environ["AWS_ACCESS_KEY_ID"] = plugin_config["s3_access_key_id"]
if "s3_secret_access_key" in plugin_config:
os.environ["AWS_SECRET_ACCESS_KEY"] = plugin_config["s3_secret_access_key"]
if "s3_region" in plugin_config:
os.environ["AWS_DEFAULT_REGION"] = plugin_config["s3_region"]

def load(self, source_config: SourceConfig):
ext_location = source_config["external_location"]
ext_location = ext_location.format(**source_config.as_dict())
source_location = pathlib.Path(ext_location.strip("'"))
if "s3" in ext_location:
# Possible to add some treatment in the future
source_location = ext_location
else:
source_location = pathlib.Path(ext_location.strip("'"))
sheet_name = source_config.get("sheet_name", 0)
return pd.read_excel(source_location, sheet_name=sheet_name)

0 comments on commit b646c61

Please sign in to comment.