-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 163c1dd
Showing
14 changed files
with
697 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 datnguye | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Change setup.py > version | ||
|
||
Install wheel: python -m pip install wheel | ||
Install twine: python -m pip install --user --upgrade twine | ||
-- | ||
Build new dist: python setup.py sdist bdist_wheel | ||
|
||
Upload test: python -m twine upload --repository testpypi dist/* | ||
|
||
Upload live: python -m twine upload --skip-existing dist/* | ||
|
||
-- | ||
python -m pip install -e C:\Sources\self\snowbim\dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# snowbim | ||
This is to do something awesome between snowflake database and Power BI tabular model file (.bim). | ||
|
||
Those are: | ||
* Refresh tables (key: name) | ||
* Refresh table's columns (key: name) | ||
* Refresh table's partitions (key: name) | ||
|
||
Supported Models: | ||
* Compatibility Level: 1550 | ||
* Default Power BI Data Source Version: powerBI_V3 | ||
|
||
We make use of [dbt (data build tool)'s profile](https://docs.getdbt.com/dbt-cli/configure-your-profile) to configure the Snowflake connection. | ||
> Therefore, PLEASE MAKE SURE you've already managed to create 1 dbt profiles.yml file. | ||
Installation: | ||
``` | ||
python -m pip install snowbim --upgrade | ||
# dependencies | ||
python -m pip install snowflake-connector-python[pandas] | ||
# check version | ||
python -m snowbim --version | ||
``` | ||
|
||
|
||
## Usage | ||
``` | ||
python -m snowbim --help | ||
``` | ||
|
||
If you don't use --profile-dir argument, by default, it will look for profiles.yml in the user home folder: | ||
* Windows: %userprofile%/.dbt/profiles.yml | ||
* Linux: ~/.dbt/profiles.yml | ||
|
||
Sample commands: | ||
* To create new model.bim file: | ||
``` | ||
python -m snowbim --bim "/path/to/model.bim" --db "YOUR_SF_DB_NAME" --schema "YOUR_SF_SCHEMA_NAME" | ||
# model.bim will be created after above command | ||
``` | ||
|
||
* To upgrade existing model.bim file: | ||
``` | ||
python -m snowbim --bim "/path/to/model.bim" --db "YOUR_SF_DB_NAME" --schema "YOUR_SF_SCHEMA_NAME" | ||
# model.bim will be overidden after above command | ||
``` | ||
|
||
* To upgrade existing model.bim file but output to a new model_upgrade.bim file: | ||
``` | ||
python -m snowbim --bim "/path/to/model.bim" --out "/path/to/model_upgrade.bim" --db "YOUR_SF_DB_NAME" --schema "YOUR_SF_SCHEMA_NAME" | ||
# model_upgrade.bim will be created after above command | ||
``` | ||
|
||
> NOTE: If schema is up-to-date, .bim file will not be created or modified. | ||
|
||
## Development Enviroment | ||
Virtual enviroment: | ||
``` | ||
python -m venv env | ||
``` | ||
|
||
Activate virtual env: | ||
``` | ||
Windows: .\env\Scripts\activate | ||
Linux: source env/bin/activate | ||
``` | ||
|
||
Install dependencies: | ||
``` | ||
pip install -r requirements.txt | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pyyaml==5.4.1 | ||
snowflake-connector-python==2.4.3 | ||
snowflake-connector-python==2.4.3[pandas] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name='snowbim', | ||
version='1.0.9', | ||
author='datnguye', | ||
author_email='[email protected]', | ||
packages=find_packages(), | ||
url='https://github.com/datnguye/snowbim', | ||
license='MIT', | ||
description='A package to refresh power bi model .bim file', | ||
long_description_content_type="text/markdown", | ||
long_description=open('README.md').read(), | ||
install_requires=[ | ||
'pyyaml==5.4.1', | ||
'snowflake-connector-python==2.4.3', | ||
'snowflake-connector-python[pandas]' | ||
], | ||
python_requires='>=3.7.5', | ||
entry_points = { | ||
'console_scripts': [ | ||
'snowbim = snowbim.__main__:main' | ||
], | ||
} | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import argparse, sys | ||
from snowbim import snowbim | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(prog='snowbim') | ||
parser.add_argument('-v','--version', action='version', version='%(prog)s 1.0.9') | ||
|
||
parser.add_argument('--bim', help='File path to an input .bim file', type=str, default='') | ||
parser.add_argument('--out', help='File path to an out .bim file. Optional', type=str, default='') | ||
parser.add_argument('--profile_dir', help='File path to dbt profiles.yml. Optional, default to .dbt folder within User Home one', type=str, default=None) | ||
parser.add_argument('--profile', help='dbt profile name. Optional, default: Fisrt profile in profiles.yml', type=str, default=None) | ||
parser.add_argument('--target', help='dbt profile target. Optional, default: dev', type=str, default='dev') | ||
parser.add_argument('--db', help='Snowflake database. Optional, default: DEMO_DB', type=str, default='DEMO_DB') | ||
parser.add_argument('--schema', help='Snowflake database\'s schema. Optional, default: PUBLIC', type=str, default='PUBLIC') | ||
|
||
args = parser.parse_args() | ||
snowbim.upgrade_schema( bim_path = args.bim, | ||
out_bim_path = args.out, | ||
profile_dir = args.profile_dir, | ||
profile = args.profile, | ||
target = args.target, | ||
db = args.db, | ||
schema = args.schema) | ||
|
||
if __name__ == '__main__': | ||
main() |
Empty file.
Oops, something went wrong.