Opened 10 years ago

Closed 9 years ago

#589 closed defect (fixed)

WCPS cast precedence

Reported by: Piero Campalani Owned by: Vlad Merticariu
Priority: critical Milestone: 9.1
Component: petascope Version: development
Keywords: cast precedence Cc: Dimitar Misev, mantovani@…, Vlad Merticariu, Alex Dumitru
Complexity: Hard

Description

Petascope does not properly prioritize a cast operator before a binary expression when mapping WCPS queries to RasQL.

In WCPS (OGC 08-068r2 — Sec.7.2.4), as in almost any other (programming) languages, casting (unary operator) takes precedence over binary expressions.

This is not currently true, thus leading to unexpected results.

In this example, I multiply two 16-bit signed short values from eobstest which result in short overflow and hence need to be cast to a longer format.

c[Lat(0), Long(51), t("1950-01-04")] = -918
c[Lat(1), Long(51), t("1950-01-04")] = -1103

> (-918) * (-1103)
[1] 1012554

> log2(1012554)
[1] 19.94957

for c in (eobstest)
return encode (
  (long) c[Lat(0), Long(51), t("1950-01-04")] * 
         c[Lat(1), Long(51), t("1950-01-04")] 
, "csv")
[1] 32767

The result is wrong, since casting is applied at RasQL level to the result of the multiplication, and not the first operand.

Currently a workaround is to cast the second operand, or make explicit use of parenthesis.

Change History (5)

comment:1 by Piero Campalani, 10 years ago

Cc: Vlad Merticariu Alex Dumitru added

comment:2 by Dimitar Misev, 10 years ago

Owner: changed from Piero Campalani to uadhikari
Status: newassigned

comment:3 by Dimitar Misev, 9 years ago

Milestone: 9.0.x9.1

comment:4 by Dimitar Misev, 9 years ago

Owner: changed from uadhikari to Vlad Merticariu

comment:5 by Vlad Merticariu, 9 years ago

Resolution: fixed
Status: assignedclosed

Fixed in wcps2.

for c in (eobstest)
return encode (

(long) c[Lat(0), Long(51), t("1950-01-04")] *

c[Lat(1), Long(51), t("1950-01-04")]

, "csv")

{1012554}

Note: See TracTickets for help on using tickets.