CartoDB / Windshaft-cartodb

Windshaft tailored for CARTO
BSD 3-Clause "New" or "Revised" License
72 stars 59 forks source link

Error parsing columns in numeric histograms #1160

Closed manmorjim closed 4 years ago

manmorjim commented 4 years ago

Context

When I add a time-series widget based on a date column Windshaft returns an error:

{
  "errors": [
    "schema \"__ctx_query\" does not exist"
  ],
  "errors_with_context": [
    {
      "type": "unknown",
      "message": "schema \"__ctx_query\" does not exist"
    }
  ]
}

After debugging Windhaft, it seems it tries to run a query which has the following:

WITH  
 __cdb_basics AS ( 
    ...
FROM 
( 
    SELECT * FROM (SELECT * FROM (SELECT * FROM multi_location) _cdb_bbox_filter 
WHERE ST_Intersects(the_geom_webmercator, ST_Transform(ST_MakeEnvelope(-124.08690690994264,12.740371611587053,-47.09471940994263,50.77352319541077, 4326), 3857))) __ctx_query, __cdb_basics  
              WHERE __ctx_query.date_part( 'epoch ', kickoff) >= 1577836800 
                AND __ctx_query.date_part( 'epoch ', kickoff) <= 1701388800 

) __cdb_filtered_source_query, __cdb_basics 
GROUP BY 10, __cdb_basics.__cdb_bins_number 
ORDER BY 10;

Which is incorrect because it executes the function date_part as part of __ctx_query which is not an schema but an alias for a subquery.

This is because in the function _buildQuery of the class NumericHistogram cast the column if it is date type and then it uses it in _buildQueryTpl as part of the alias __ctx_query.

dgaubert commented 4 years ago

@manmorjim

Nice catch! It seems a perfect issue to sort it out as your first contribution to this project! 🙄