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

Mapbox Visualizatuion error cause by "is not JSON serializable" #3604

Closed
amoussoubaruch opened this issue Oct 5, 2017 · 27 comments
Closed

Comments

@amoussoubaruch
Copy link

amoussoubaruch commented Oct 5, 2017

Make sure these boxes are checked before submitting your issue - thank you!

  • [yes ] I have checked the superset logs for python stacktraces and included it here as text if any
  • [yes ] I have reproduced the issue with at least the latest released version of superset
  • [yes ] I have checked the issue tracker for the same issue and I haven't found one similar

Superset version

0.19.1

Expected results

I try to draw mapbox in superset. I have dataset with column Latitude and Longitude and use it in respective field.

Actual results

TypeError: <superset.connectors.druid.models.DruidMetric object at 0xefbea90> is not JSON serializable

Steps to reproduce

togithub

Anyone already have the same problem?
Thanks

@xrmx
Copy link
Contributor

xrmx commented Oct 5, 2017

Please reproduce with latest version and also post the full backtrace proberly quoted in text and not in picture.

@amoussoubaruch
Copy link
Author

amoussoubaruch commented Oct 5, 2017

This is full backtrace i receveid

Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/superset/viz.py", line 249, in get_payload
    df = self.get_df()
  File "/usr/lib/python2.7/site-packages/superset/viz.py", line 79, in get_df
    self.results = self.datasource.query(query_obj)
  File "/usr/lib/python2.7/site-packages/superset/connectors/druid/models.py", line 971, in query
    client=client, query_obj=query_obj, phase=2)
  File "/usr/lib/python2.7/site-packages/superset/connectors/druid/models.py", line 799, in get_query_str
    return self.run_query(client=client, phase=phase, **query_obj)
  File "/usr/lib/python2.7/site-packages/superset/connectors/druid/models.py", line 962, in run_query
    client.groupby(**qry)
  File "/usr/lib/python2.7/site-packages/pydruid/client.py", line 192, in groupby
    return self._post(query)
  File "/usr/lib/python2.7/site-packages/pydruid/client.py", line 391, in _post
    headers, querystr, url = self._prepare_url_headers_and_body(query)
  File "/usr/lib/python2.7/site-packages/pydruid/client.py", line 34, in _prepare_url_headers_and_body
    querystr = json.dumps(query.query_dict).encode('utf-8')
  File "/usr/lib64/python2.7/json/__init__.py", line 243, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib64/python2.7/json/encoder.py", line 207, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib64/python2.7/json/encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib64/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <superset.connectors.druid.models.DruidMetric object at 0xb319650> is not JSON serializable

@xrmx
Copy link
Contributor

xrmx commented Oct 5, 2017

Quote with 3 backticks please. And newlines.

@amoussoubaruch
Copy link
Author

Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/superset/viz.py", line 249, in get_payload df = self.get_df() File "/usr/lib/python2.7/site-packages/superset/viz.py", line 79, in get_df self.results = self.datasource.query(query_obj) File "/usr/lib/python2.7/site-packages/superset/connectors/druid/models.py", line 971, in query client=client, query_obj=query_obj, phase=2) File "/usr/lib/python2.7/site-packages/superset/connectors/druid/models.py", line 799, in get_query_str return self.run_query(client=client, phase=phase, **query_obj) File "/usr/lib/python2.7/site-packages/superset/connectors/druid/models.py", line 962, in run_query client.groupby(**qry) File "/usr/lib/python2.7/site-packages/pydruid/client.py", line 192, in groupby return self._post(query) File "/usr/lib/python2.7/site-packages/pydruid/client.py", line 391, in _post headers, querystr, url = self._prepare_url_headers_and_body(query) File "/usr/lib/python2.7/site-packages/pydruid/client.py", line 34, in _prepare_url_headers_and_body querystr = json.dumps(query.query_dict).encode('utf-8') File "/usr/lib64/python2.7/json/__init__.py", line 243, in dumps return _default_encoder.encode(obj) File "/usr/lib64/python2.7/json/encoder.py", line 207, in encode chunks = self.iterencode(o, _one_shot=True) File "/usr/lib64/python2.7/json/encoder.py", line 270, in iterencode return _iterencode(o, 0) File "/usr/lib64/python2.7/json/encoder.py", line 184, in default raise TypeError(repr(o) + " is not JSON serializable") TypeError: <superset.connectors.druid.models.DruidMetric object at 0xb319650> is not JSON serializable

@amoussoubaruch
Copy link
Author

It's ok??

@xrmx
Copy link
Contributor

xrmx commented Oct 5, 2017

No. Copy it from the server logs, it'll have the proper newlines.

@amoussoubaruch
Copy link
Author

TypeError: <superset.connectors.druid.models.DruidMetric object at 0xb319650> is not JSON serializable
2017-10-05 15:09:24,759:INFO:root:Caching for the next 86400 seconds
2017-10-05 15:17:22,439:INFO:root:[stats_logger] (incr) explore
2017-10-05 15:17:23,749:INFO:root:[stats_logger] (incr) explore_json
2017-10-05 15:17:23,820:INFO:root:[stats_logger] (incr) loaded_from_source
2017-10-05 15:17:23,820:INFO:root:Serving from cache
2017-10-05 15:17:28,259:INFO:root:[stats_logger] (incr) explore_json
2017-10-05 15:17:28,332:INFO:root:[stats_logger] (incr) loaded_from_cache
2017-10-05 15:17:28,348:INFO:root:Caching for the next 86400 seconds
2017-10-05 15:17:40,590:INFO:root:[stats_logger] (incr) explore_json
2017-10-05 15:17:40,659:INFO:root:[stats_logger] (incr) loaded_from_cache
2017-10-05 15:17:40,664:ERROR:root:<superset.connectors.druid.models.DruidMetric object at 0x95a5410> is not JSON serializable
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/superset/viz.py", line 249, in get_payload
    df = self.get_df()
  File "/usr/lib/python2.7/site-packages/superset/viz.py", line 79, in get_df
    self.results = self.datasource.query(query_obj)
  File "/usr/lib/python2.7/site-packages/superset/connectors/druid/models.py", line 971, in query
    client=client, query_obj=query_obj, phase=2)
  File "/usr/lib/python2.7/site-packages/superset/connectors/druid/models.py", line 799, in get_query_str
    return self.run_query(client=client, phase=phase, **query_obj)
  File "/usr/lib/python2.7/site-packages/superset/connectors/druid/models.py", line 962, in run_query
    client.groupby(**qry)
  File "/usr/lib/python2.7/site-packages/pydruid/client.py", line 192, in groupby
    return self._post(query)
  File "/usr/lib/python2.7/site-packages/pydruid/client.py", line 391, in _post
    headers, querystr, url = self._prepare_url_headers_and_body(query)
  File "/usr/lib/python2.7/site-packages/pydruid/client.py", line 34, in _prepare_url_headers_and_body
    querystr = json.dumps(query.query_dict).encode('utf-8')
  File "/usr/lib64/python2.7/json/__init__.py", line 243, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib64/python2.7/json/encoder.py", line 207, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib64/python2.7/json/encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib64/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <superset.connectors.druid.models.DruidMetric object at 0x95a5410> is not JSON serializable
2017-10-05 15:17:40,665:INFO:root:Caching for the next 86400 seconds


@amoussoubaruch
Copy link
Author

This is log directly receivred from server.
I use druid for backend database.

@amoussoubaruch
Copy link
Author

@xrmx

@amoussoubaruch
Copy link
Author

@georgeke

@amoussoubaruch
Copy link
Author

@xrmx

@Fokko
Copy link
Contributor

Fokko commented Nov 27, 2017

I'm experiencing the same issue

@ahsanshah
Copy link

Same here. Would be great if this worked as there are many Geo coded (Lat Long) data set use cases for interactive exploration. As an aside, would something like Leaflet.js be possible with Superset?

@bolkedebruin
Copy link
Contributor

bolkedebruin commented Dec 15, 2017


from superset.connectors.druid.models import DruidMetric
import json
from superset.utils import base_json_conv

m = DruidMetric()
json.dumps(m, default=base_json_conv)

'null'

DruidMetric probably needs a default method from JSONEncoder.

@ghost
Copy link

ghost commented Dec 16, 2017

I also have the same issue. How can we set this default method?

@bolkedebruin
Copy link
Contributor

Digging abit deeper, unfortunately adding a "default()" method will not work. The json module has a bit of a peculiar default way of doing serialization, which does not allow serialization methods being added to classes.

However, here it seems that a DruidMetric is somewhere to being forgotten to be .json_obj() as it is done in run_query for metrics. Somehow one (or more) slips trough.

@bolkedebruin
Copy link
Contributor

bolkedebruin commented Dec 25, 2017

Ok I found the issue. The dimensions of the LimitSpec part of the query are populated with metrics or self.metrics. This is a druidmetric instead of a column name.

I think the logic (run_query) is wrong here and it should use dimensions instead and not metrics. I’m not entirely sure and need some help from @Fokko or @mistercrunch. Then the PR is quite simple.

Offending lines:

  1. https://github.com/apache/incubator-superset/blob/master/superset/connectors/druid/models.py#L1139
  2. https://github.com/apache/incubator-superset/blob/master/superset/connectors/druid/models.py#L1188

bolkedebruin added a commit to bolkedebruin/incubator-superset that referenced this issue Dec 25, 2017
in case a form did not specify a metric (e.g. mapbox). If it is
not available it now defaults to the first dimension instead.

This fixes issue apache#3604
@mistercrunch
Copy link
Member

A few tangents here:

It's been tricky to manage how aggregations work for geospatial, in many cases users do not want to aggregate and just use atomic data. In other cases people want to aggregate data. There's also the fact that with WebGL / Deck.GL we can actually afford to visualize hundreds of thousands of data points, and aggregation as necessary technically. The way the new Deck.GL visualizations work is that they don't aggregate unless you specify a metric.

I'm unclear on how to handle this original mapbox visualization in the light of the recent work we've been doing using Deck.GL. The new scatterplot viz is much better than this one, but it doesn't support the dynamic clustering use case (where clusters are created on the fly as users zoom in /out). We may want to refactor that visualization to be more like the new ones. First thing to do would be to use the spatial control for lat/long which works with proper Druid spatial dims.

@bolkedebruin
Copy link
Contributor

@mistercrunch the fix I made is a bug fix in the spec of run_query. It should not be able to pass a DruidMetric directly to the json passed to Druid. MapBox just exposes it but it could occur in different circumstances as well.

In other words, the pr fixes this issue by fixing a fundamental bug. Ptal

@mistercrunch
Copy link
Member

@bolkedebruin gotcha, let me review the PR. I just needed to gather some thoughts around what we're going to do with the Mapbox viz and used this PR as a vehicle.

@bolkedebruin
Copy link
Contributor

Cheers. No prob

mistercrunch pushed a commit that referenced this issue Jan 12, 2018
in case a form did not specify a metric (e.g. mapbox). If it is
not available it now defaults to the first dimension instead.

This fixes issue #3604
@Fokko
Copy link
Contributor

Fokko commented Jan 24, 2018

@amoussoubaruch This issue can be closed, it has been fixed

@chirpy2291
Copy link

Hi, i am facing the same issue.On running single custom dimension i get the following error:
KeyError: u"None of [[u'outputName', u'extractionFn', u'type', u'outputType', u'dimension']] are in the [index]"

Can you specify which version of druid to use? and what is the fix?

@Fokko
Copy link
Contributor

Fokko commented Feb 1, 2018

I don't think it really has to do with Druid. Which version Superset are you running?

@chirpy2291
Copy link

chirpy2291 commented Feb 4, 2018 via email

@bolkedebruin
Copy link
Contributor

@chirpy2291 the fix is new (not even in a released version afaik) and you are running an old version of superset. So why not use master first and then open a new issue if needed instead of hijacking this closed issue?

@chirpy2291
Copy link

chirpy2291 commented Feb 6, 2018 via email

michellethomas pushed a commit to michellethomas/panoramix that referenced this issue May 24, 2018
in case a form did not specify a metric (e.g. mapbox). If it is
not available it now defaults to the first dimension instead.

This fixes issue apache#3604
wenchma pushed a commit to wenchma/incubator-superset that referenced this issue Nov 16, 2018
in case a form did not specify a metric (e.g. mapbox). If it is
not available it now defaults to the first dimension instead.

This fixes issue apache#3604
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants