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

ORDER BY in query not being respected in VL with draw order of features #844

Closed
makella opened this issue Aug 15, 2018 · 4 comments
Closed

Comments

@makella
Copy link
Contributor

makella commented Aug 15, 2018

Related to: #20

I'm noticing that when there is an ORDER BY in a query, that the features aren't drawing as expected. Is this expected behavior?

For example, in the screenshot below, each symbol is colored and sized by an attribute avg_waiting_time where the query orders by avg_waiting_time desc what I would expect to see (and what I see in Builder) is the smaller points to draw on top of the larger ones. As you can see where the central large red circles are, that isn't being respected as there are several smaller points still drawing underneath the larger ones:

screen shot 2018-08-15 at 10 31 45 am

Even if I add
order: width(desc)

It still doesn't change the viz:
screen shot 2018-08-15 at 10 33 39 am

Just in case, the full query for the dataset (client project so can't share map in public repo):

SELECT CONNECTION_NAME,
       sum(occupancy) AS occupancy,
       avg(avg_waiting_time) AS avg_waiting_time,
       the_geom,
       the_geom_webmercator,
       row_number() over() AS cartodb_id,
       hour
FROM table
WHERE avg_waiting_time > 0
  AND trip_date >= '2018-07-18'
  AND trip_date < '2018-07-19'
GROUP BY CONNECTION_NAME,
         hour,
         the_geom,
         the_geom_webmercator
ORDER BY avg_waiting_time DESC
@davidmanzanares
Copy link

I think this is expected behavior due to the way Maps API works.

cc: @Algunenano

@Algunenano
Copy link

I think this is expected behavior due to the way Maps API works.

Yes, but that doesn't mean that CartoVL has to work this way.
To put this in context: Mapnik doesn't have any guarantee about where to start rendering because queries don't have any order and it renders them in the order they arrive.

On the other hand, for MVTs:

  • If using the Mapnik renderer: features should be ordered correctly (as the generation is sequential).
  • If using the pg-mvt (aka St_AsMVT) renderer: features won't be ordered if a parallel plan is triggered, but they will be if processed sequentially.

Either way, even if they reach the client unordered, they could be ordered before rendering. It's should be simple (but costly as it requires reading all properties).

@davidmanzanares
Copy link

Ok, I saw one problem, to use CARTO VL ordering function you should use:
order: desc(width())
Instead of
order: width(desc)

An error is not thrown because #675 is not fixed.

If the issue is fixed with this, please, close the issue.

@rochoa
Copy link
Contributor

rochoa commented Aug 27, 2018

This should throw an error now as #675 is already fixed. Re-open if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants