-
Notifications
You must be signed in to change notification settings - Fork 31
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
Return TIMESTAMP columns as native Python datetime objects to improve support for Apache Superset #395
Return TIMESTAMP columns as native Python datetime objects to improve support for Apache Superset #395
Changes from all commits
0212487
f9bd08c
66e7b51
3dc5cb7
8dfcf80
b08cb16
efe8bfb
2d1f41f
246d917
94b3d1e
85b7c7f
2cf32e2
fbef448
3b66626
57ec090
9b82ac2
5b4d5ec
e9788ea
eebd670
187ed3f
e3b8d50
32a4826
2c9e3aa
2adf833
9bc5f51
8e53da5
5ddced3
aaaf7ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 2 * * *' | ||
|
||
|
||
jobs: | ||
test: | ||
name: "Python: ${{ matrix.python-version }} | ||
SQLA: ${{ matrix.sqla-version }} | ||
CrateDB: ${{ matrix.crate-version }} | ||
on ${{ matrix.os }}" | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
crate-version: [nightly] | ||
os: [ubuntu-latest] | ||
sqla-version: ['1.1.18', '1.2.19', '1.3.23'] | ||
python-version: [3.5, 3.6, 3.7, 3.8, 3.9] | ||
|
||
steps: | ||
- uses: actions/checkout@master | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python bootstrap.py | ||
|
||
# replace SQLAlchemy version | ||
sed -ir 's/SQLAlchemy.*/SQLAlchemy = ${{ matrix.sqla-version }}/g' versions.cfg | ||
|
||
# replace CrateDB version | ||
if [ ${{ matrix.crate-version }} = "nightly" ]; then | ||
sed -ir 's/releases/releases\/nightly/g' base.cfg | ||
sed -ir 's/crate_server.*/crate_server = latest/g' versions.cfg | ||
else | ||
sed -ir 's/crate-/crate_/g' base.cfg | ||
sed -ir 's/crate_server.*/crate_server = ${{ matrix.crate-version }}/g' versions.cfg | ||
fi | ||
|
||
bin/buildout -n -c base.cfg | ||
|
||
- name: Test | ||
run: | | ||
bin/flake8 | ||
bin/coverage run bin/test -vv1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ | |
"smallint": sqltypes.SmallInteger, | ||
"timestamp": sqltypes.TIMESTAMP, | ||
"timestamp with time zone": sqltypes.TIMESTAMP, | ||
"timestamp without time zone": sqltypes.TIMESTAMP, | ||
"object": Object, | ||
"integer": sqltypes.Integer, | ||
"long": sqltypes.NUMERIC, | ||
|
@@ -64,6 +65,7 @@ | |
TYPES_MAP["smallint_array"] = ARRAY(sqltypes.SmallInteger) | ||
TYPES_MAP["timestamp_array"] = ARRAY(sqltypes.TIMESTAMP) | ||
TYPES_MAP["timestamp with time zone_array"] = ARRAY(sqltypes.TIMESTAMP) | ||
TYPES_MAP["timestamp without time zone_array"] = ARRAY(sqltypes.TIMESTAMP) | ||
TYPES_MAP["long_array"] = ARRAY(sqltypes.NUMERIC) | ||
TYPES_MAP["bigint_array"] = ARRAY(sqltypes.NUMERIC) | ||
TYPES_MAP["double_array"] = ARRAY(sqltypes.DECIMAL) | ||
|
@@ -75,7 +77,6 @@ | |
except Exception: | ||
pass | ||
|
||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
|
@@ -91,6 +92,8 @@ def result_processor(self, dialect, coltype): | |
def process(value): | ||
if not value: | ||
return | ||
if isinstance(value, datetime): | ||
return value.date() | ||
try: | ||
return datetime.utcfromtimestamp(value / 1e3).date() | ||
except TypeError: | ||
|
@@ -130,6 +133,8 @@ def result_processor(self, dialect, coltype): | |
def process(value): | ||
if not value: | ||
return | ||
if isinstance(value, datetime): | ||
return value | ||
try: | ||
return datetime.utcfromtimestamp(value / 1e3) | ||
except TypeError: | ||
|
@@ -261,7 +266,7 @@ def get_pk_constraint(self, engine, table_name, schema=None, **kw): | |
|
||
def result_fun(result): | ||
rows = result.fetchall() | ||
return set(map(lambda el: el[0], rows)) | ||
return list(set(map(lambda el: el[0], rows))) | ||
Comment on lines
-264
to
+269
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While I don't know about the specific background why there has been a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dear @Aymaru, apologies for the late reply. We've split off this amendment into #426. For you, it apparently solved this issue:
With the patch at #426, we are observing a regression. Maybe due to the upgrade to SQLAlchemy 1.4, and maybe other changes in Apache Superset, this is not needed anymore? With kind regards, |
||
else: | ||
query = """SELECT constraint_name | ||
FROM information_schema.table_constraints | ||
|
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.
This currently raises an exception on CI, see [1]. The current code expects
datetime.datetime(2013, 7, 16, 0, 0)
here.[1] https://github.com/crate/crate-python/runs/2114206441?check_suite_focus=true#step:5:388