-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add section on how to setup testing workspace #12
base: main
Are you sure you want to change the base?
Conversation
ccd0823
to
bba15a4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! 👍
NB: I've added a few comments. As always please take them as suggestions when applicable, and skip those which are silly. Just on the __name__ == "__main__"
(see below), I do have very strong opinions ;].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the previous patch, the pyproject.toml
has been removed, while I thought it would have been a good idea to keep it, in order to bundle all dependencies. I only argued against using Poetry, not for removing the pyproject.toml
file ;].
In this spirit, I am proposing to reintroduce it, or alternatively a basic requirements.txt
, which includes all the needed dependencies. Considering the code in sight, the list of requirements seem to be those:
polars
requests
sqlalchemy-cratedb
tdvt @ git+https://github.com/tableau/connector-plugin-sdk/#subdirectory=tdvt
Now that the environment is set up, we need to also set up the tableau test files and data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that the environment is set up, we need to also set up the tableau test files and data. | |
Now that the environment is set up, we need to also set up the Tableau test files and data. |
can follow the official tdvt docs or continue reading and do step by step. | ||
|
||
Note: There is also a [50 minute video by the tableau team ](https://www.youtube.com/watch?v=rAgnnByJIJA) . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: There is also a [50 minute video by the tableau team ](https://www.youtube.com/watch?v=rAgnnByJIJA) . | |
Note: There is also a [50 minute video by the tableau team](https://www.youtube.com/watch?v=rAgnnByJIJA). | |
## Set up CrateDB. | ||
|
||
The quickest way to setup CrateDB is with docker https://cratedb.com/docs/guide/install/container/index.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The quickest way to setup CrateDB is with docker https://cratedb.com/docs/guide/install/container/index.html | |
The quickest way to set up CrateDB is by [using Docker](https://cratedb.com/docs/guide/install/container/). |
|
||
1. Go to `./tests/config/tdvt/tdvt_override.ini` and put the path of your installation's `tabquerytool.exe`, for example | ||
for my in windows it is: `C:\Program Files\Tableau\Tableau 2024.3\bin\tabquerytool.exe` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for my in windows it is: `C:\Program Files\Tableau\Tableau 2024.3\bin\tabquerytool.exe` | |
on a Windows machine it is: `C:\Program Files\Tableau\Tableau 2024.3\bin\tabquerytool.exe` |
1. Go to `./tests/config/tdvt/tdvt_override.ini` and put the path of your installation's `tabquerytool.exe`, for example | ||
for my in windows it is: `C:\Program Files\Tableau\Tableau 2024.3\bin\tabquerytool.exe` | ||
2. [Download](https://github.com/tableau/connector-plugin-sdk/tree/master/tests/datasets/TestV1) and Load the table `calcs` and `staples` to your CrateDB instance. You can use the script in `./data/setup_data.py`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2. [Download](https://github.com/tableau/connector-plugin-sdk/tree/master/tests/datasets/TestV1) and Load the table `calcs` and `staples` to your CrateDB instance. You can use the script in `./data/setup_data.py`, | |
2. [Download datasets](https://github.com/tableau/connector-plugin-sdk/tree/master/tests/datasets/TestV1) and load the table `calcs` and `staples` into your CrateDB instance. You can use the script in `./data/setup_data.py`, |
import pathlib | ||
import logging | ||
|
||
import polars | ||
import requests | ||
|
||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) | ||
|
||
CRATE_DB = 'HOST:PORT' # Examples: localhost:4200, 192.168.88.21:4200 | ||
CRATEDB_HTTP = f'http://{CRATE_DB}/_sql' | ||
CRATEDB_SQLALCHEMY = f'crate://{CRATE_DB}' | ||
DATA_URL = pathlib.Path(__file__).parent.parent / 'data' | ||
|
||
FILES_URL = [ | ||
{'name': 'Calcs', | ||
'url': 'https://raw.githubusercontent.com/tableau/connector-plugin-sdk/' | ||
'refs/heads/master/tests/datasets/TestV1/Calcs_headers.csv'}, | ||
{'name': 'Staples', | ||
'url': 'https://raw.githubusercontent.com/tableau/connector-plugin-sdk/' | ||
'refs/heads/master/tests/datasets/TestV1/Staples_utf8_headers.csv'} | ||
] | ||
|
||
# Create tables. | ||
for file in DATA_URL.iterdir(): | ||
if file.suffix == '.sql': | ||
statement = file.read_text() | ||
response = requests.post(CRATEDB_HTTP, | ||
json={'stmt': statement}) | ||
logging.info(f'Tried creating {file.name}, response from CrateDB: {response.text}') | ||
|
||
# Download data and load it to CrateDB. | ||
for file in FILES_URL: | ||
result = requests.get(file.get('url')) | ||
logging.info(f'Downloading {file.get('url')}') | ||
|
||
df = polars.read_csv(result.content, use_pyarrow=True) | ||
|
||
# There is a bug where an empty space is added to 'Market Segment' column name. | ||
# Easiest solution is just to try to rename it if it exists. | ||
try: | ||
df.get_column('Market Segment ') | ||
df = df.rename({'Market Segment ': 'Market Segment'}) | ||
except polars.exceptions.ColumnNotFoundError: | ||
pass | ||
|
||
logging.info(f'Loading to CrateDB {file.get('name')!r}') | ||
df.write_database(file.get('name'), | ||
connection=CRATEDB_SQLALCHEMY, | ||
if_table_exists='append') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please never put Python code into a file like this, unless a framework demands you to do so. Instead, always use the canonical Python incantation idiom:
if __name__ == "__main__":
main()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amotl mentions it all
Summary of the changes / Why this is an improvement
Checklist