Skip to content

[SQL] Confusing error message for DATEDIFF #5821

@mihaibudiu

Description

@mihaibudiu

Calcite rewrites DATEDIFF to TIMESTAMPDIFF, and then gives confusing error messages:

CREATE TABLE shipments (
  shipment_id BIGINT,
  warehouse_id BIGINT,
  shipped_at TIMESTAMP,
  expected_at TIMESTAMP,
  delivered_at TIMESTAMP,
  shipping_mode VARCHAR
);

CREATE MATERIALIZED VIEW bm07_shipping_performance AS
SELECT
  warehouse_id,
  TIMESTAMP_TRUNC(shipped_at, WEEK) AS ship_week,
  AVG(CASE WHEN delivered_at > expected_at THEN 1.0 ELSE 0.0 END) AS late_rate,
  MAX(DATEDIFF(delivered_at, shipped_at)) AS max_days_in_transit
FROM shipments
GROUP BY
  warehouse_id,
  TIMESTAMP_TRUNC(shipped_at, WEEK);
error: Compilation error From line 15, column 7 to line 15, column 40: Invalid number of arguments to function 'TIMESTAMPDIFF'. Was expecting 3 arguments
 15| MAX(DATEDIFF(delivered_at, shipped_at)) AS max_days_in_transit
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 16|FROM shipments

Metadata

Metadata

Assignees

Labels

SQL compilerRelated to the SQL compiler

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions