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

Ensure proper JSON serialization of numpy.ndarray #8946

Merged
merged 1 commit into from Jan 10, 2020

Conversation

robdiciuccio
Copy link
Member

CATEGORY

Choose one

  • Bug Fix
  • Enhancement (new features, refinement)
  • Refactor
  • Add tests
  • Build / Development Environment
  • Documentation

SUMMARY

When querying a Presto datasource with a column of type ARRAY asynchronously, the following error would be raised:

TypeError: Unserializable object [] of type <class 'numpy.ndarray'>

This fix ensures proper conversion of the numpy.ndarray to a list for JSON serialization.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TEST PLAN

Ensure queries against a Presto table containing nested data type columns work correctly. Repeat for other supported DBs having nested data type columns.

This fix was tested against Presto 0.227 in both async and sync queries.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

REVIEWERS

@graceguo-supercat @craig-rueda @dpgaspar @villebro

Copy link
Member

@craig-rueda craig-rueda left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@codecov-io
Copy link

Codecov Report

Merging #8946 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #8946   +/-   ##
=======================================
  Coverage   58.97%   58.97%           
=======================================
  Files         359      359           
  Lines       11333    11333           
  Branches     2787     2787           
=======================================
  Hits         6684     6684           
  Misses       4471     4471           
  Partials      178      178

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3bedee7...8926e22. Read the comment docs.

@mistercrunch mistercrunch merged commit 7ff18f0 into apache:master Jan 10, 2020
@mistercrunch mistercrunch deleted the rd/json-ndarray branch January 10, 2020 18:24
graceguo-supercat pushed a commit to graceguo-supercat/superset that referenced this pull request Jan 10, 2020
@graceguo-supercat
Copy link

Hi @robdiciuccio Thanks very much for the fix. I run a few queries in different tables. Here is another error message also related to pyarrow:

  File "/usr/local/lib/python3.6/dist-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/usr/local/lib/python3.6/dist-packages/newrelic/hooks/framework_flask.py", line 108, in _nr_wrapper_Flask_handle_exception_
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.6/dist-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.6/dist-packages/newrelic/hooks/framework_flask.py", line 45, in _nr_wrapper_handler_
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/flask_appbuilder/security/decorators.py", line 168, in wraps
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/superset/utils/log.py", line 59, in wrapper
    value = f(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/superset/views/core.py", line 2291, in results
    return self.results_exec(key)
  File "/usr/local/lib/python3.6/dist-packages/superset/views/core.py", line 2331, in results_exec
    payload, query, cast(bool, results_backend_use_msgpack)
  File "/usr/local/lib/python3.6/dist-packages/superset/views/core.py", line 233, in _deserialize_results_payload
    df = result_set.SupersetResultSet.convert_table_to_df(pa_table)
  File "/usr/local/lib/python3.6/dist-packages/superset/result_set.py", line 129, in convert_table_to_df
    return table.to_pandas(integer_object_nulls=True)
  File "pyarrow/array.pxi", line 468, in pyarrow.lib._PandasConvertible.to_pandas
  File "pyarrow/table.pxi", line 1238, in pyarrow.lib.Table._to_pandas
  File "/usr/local/lib/python3.6/dist-packages/pyarrow/pandas_compat.py", line 704, in table_to_blockmanager
    blocks = _table_to_blocks(options, table, categories)
  File "/usr/local/lib/python3.6/dist-packages/pyarrow/pandas_compat.py", line 976, in _table_to_blocks
    result = pa.lib.table_to_blocks(options, block_table, categories)
  File "pyarrow/table.pxi", line 780, in pyarrow.lib.table_to_blocks
  File "pyarrow/error.pxi", line 86, in pyarrow.lib.check_status
pyarrow.lib.ArrowNotImplementedError: Not implemented type for list in DataFrameBlock: struct<author_type: string, locale: string>

@robdiciuccio
Copy link
Member Author

Thanks @graceguo-supercat. Is this in Presto? What are the data types of the columns being queried?

@graceguo-supercat
Copy link

Presto version=0.188.
I feel the problem might be caused by MAP<STRING,BOOLEAN> type or ARRAY<MAP<STRING,STRING>>

@robdiciuccio
Copy link
Member Author

@graceguo-supercat I tested with the following table and data in our Presto (Hive) cluster, and was unable to replicate the error.

CREATE TABLE default.superset_test (
  id bigint,
  name varchar,
  list_ints array(bigint),
  list_maps array(map(varchar, varchar)),
  map1 map(varchar, varchar),
  map2 map(varchar, boolean),
  ds date
);

INSERT INTO default.superset_test VALUES (1, 'San Francisco', ARRAY[1,2,3], ARRAY[MAP(ARRAY['foo'], ARRAY['bar']), MAP(ARRAY['fad'], ARRAY['baz'])], MAP(ARRAY['foo'], ARRAY['bar']), MAP(ARRAY['foo'], ARRAY[True]), date '2019-01-09');

select * from default.superset_test;

Screen Shot 2020-01-13 at 3 29 56 PM

michellethomas pushed a commit to airbnb/superset-fork that referenced this pull request Jan 15, 2020
@graceguo-supercat
Copy link

graceguo-supercat commented Jan 15, 2020

@robdiciuccio Do you test this PR with Hive Struct data type? otherwise it may break extra cases.

cc @john-bodley

john-bodley added a commit to airbnb/superset-fork that referenced this pull request Jan 24, 2020
etr2460 pushed a commit to etr2460/incubator-superset that referenced this pull request Feb 1, 2020
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.36.0 labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/XS 🚢 0.36.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants