Search code examples
hpcc-eclhpcc

I wanted to return the obtained function output into a variable that I added into the RECORD using TRANSFORM. What does this error in image here mean?


distcomp (REAL4 lat1, REAL4 lon1,REAL4 lat2, REAL4 lon2, REAL4 dist) := FUNCTION

REAL4 lo1 := lon1/57.29577951;
REAL4 lo2 := lon2/57.29577951;
REAL4 la1 := lat1/57.29577951;
REAL4 la2 := lat2/57.29577951;
REAL4 dlon := lo2 - lo1;
REAL4 dlat := la2 - la1;
REAL4 a := sin(dlat / 2)*sin(dlat / 2) + cos(la1) * cos(la2) * sin(dlon/2)*sin(dlon/ 2);
REAL4 c := 2 * asin(sqrt(a));
REAL4 di := 6371 * c;
RETURN IF( di <= dist, 1,0);
END;

ProjResult := PROJECT(MENTORS,
                TRANSFORM(New_MentorsRaw_Rec,
                  SELF.Qualify :=  distcomp(LEFT.Latitude,LEFT.Longitude, Latitude, 
Longitude, Distance); // I'm getting error here in this line
                  SELF.RecCount := 0;    
                  SELF := LEFT // Assign everything from left recordset
                ));

-> I'm getting error at the line SELF.Qualify and the error goes like this:

ERROR - syntax error near ')':expected:=

Solution

  • This error usually means that the syntax check has found definitions in your code that have not been defined before they were referenced in the code. In your case, it appears that the third (i.e, "latitude"), fourth (i.e., "longitude"), and fifth (i.e., "distance") input parameters of your distcomp function call in SELF.Qualify are falling under this case. These input parameters would either need to be prefixed with "LEFT." in case they are values coming from the MENTORS recordset (* see note below) or be defined beforehand in the code with their respective values.

    * Word of caution: If I understood correctly, you trying to have two different pairs of latitude and longitude values to be used as an input of the distcomp function call in SELF.Qualify. Since the PROJECT() function processes one record at a time, in its associated TRANSFORM() function you will need to make sure you make a distinction between the names of the two different latitudes and longitudes being processed. This usually means that the MENTORS recordset will need to have these two different pair of values under different column names (such as latitude1, longitude1, latitude2 and longitude 2). Another alternative would be to replace the PROJECT() function by another function that processes two records at a time, such as an ITERATE() or even a JOIN() function (in the latter case you will also need a second recordset).