Skip to content
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

[sql lab] Fix issue around VARBINARY type in Presto #5121

Merged
merged 1 commit into from
Jun 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ python-dateutil==2.6.1
python-geohash==0.8.5
pyyaml==3.12
requests==2.18.4
simplejson==3.13.2
simplejson==3.15.0
six==1.11.0
sqlalchemy==1.2.2
sqlalchemy-utils==0.32.21
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def get_git_sha():
'python-geohash',
'pyyaml>=3.11',
'requests',
'simplejson',
'simplejson>=3.15.0',
'six',
'sqlalchemy',
'sqlalchemy-utils',
Expand Down
6 changes: 5 additions & 1 deletion superset/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ def datetime_f(dttm):


def base_json_conv(obj):

if isinstance(obj, numpy.int64):
return int(obj)
elif isinstance(obj, numpy.bool_):
Expand All @@ -323,6 +322,11 @@ def base_json_conv(obj):
return str(obj)
elif isinstance(obj, timedelta):
return str(obj)
elif isinstance(obj, bytes):
try:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get a unit test here? Also don't we want to raise the error vs. swallow by sending [bytes] or even put some type of logger.error()?

return '{}'.format(obj)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will return different values depending on Python version. For Python 2 (where bytes are strings):

>>> print(repr('{}'.format(b'test')))
'test'

For Python 3:

>>> print(repr('{}'.format(b'test')))
"b'test'"

Why not return a list of integers here instead?

>>> list(b'test')
[116, 101, 115, 116]

What is the use case for VARBINARY?

except Exception:
return '[bytes]'


def json_iso_dttm_ser(obj, pessimistic=False):
Expand Down
6 changes: 5 additions & 1 deletion superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2467,7 +2467,11 @@ def sql_json(self):
rendered_query,
return_results=True)
payload = json.dumps(
data, default=utils.pessimistic_json_iso_dttm_ser, ignore_nan=True)
data,
default=utils.pessimistic_json_iso_dttm_ser,
ignore_nan=True,
encoding=None,
)
except Exception as e:
logging.exception(e)
return json_error_response('{}'.format(e))
Expand Down