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

Problem with $replace 2nd argument #180

Open
wnm3 opened this issue Dec 29, 2021 · 5 comments
Open

Problem with $replace 2nd argument #180

wnm3 opened this issue Dec 29, 2021 · 5 comments
Assignees

Comments

@wnm3
Copy link
Member

wnm3 commented Dec 29, 2021

I tried the $sum function and that seemed to work fine:
image

Using the debugger and looking at the state of the system, the variables map doesn’t have the $date value so when attempting to get the pattern for the $replace function, it is getting a null.
I believe you are getting caught on this part of the expression:

image

The attempt to get the $dt value is returning null because it isn't defined:
image

which causes the exception you are seeing.
image

This is a very complicated expression, and it will take a while to try to simplify it to determine where the actual problem is getting created. I’ll try to take a look but with the holidays it will be a while.

@wnm3 wnm3 self-assigned this Dec 29, 2021
@sayyadrahim48
Copy link

Thanks, Nat for the opening defect. please update once resolved

@wnm3
Copy link
Member Author

wnm3 commented Dec 29, 2021

So, while trying to simplify, I wanted to see if the $dt: expression would work...

Using Tester passing in an Issue180.json containing your JSON object, I see a problem when adding the fromMillis chained function:

$map($.NotificationData.dynamicData.flights, function($v, $i, $a){ ($dt := $toMillis($v.departure.datetimeStd) ~> $fromMillis('[FNn,*-3], [D1] [MNn,*-3]');) })
[ ]

As the try.jsonata.org here works fine...

If I rewrite without the chain function (e.g., calling the $fromMillis with the results of the $toMillis) it works:

Enter jsonata expression (or q to quit):
$map($.NotificationData.dynamicData.flights, function($v, $i, $a){ ($dt := $toMillis($v.departure.datetimeStd) ~> $fromMillis('[FNn,-3], [D1] [MNn,-3]');) })
[ ]
Enter jsonata expression (or q to quit):
$map($.NotificationData.dynamicData.flights, function($v, $i, $a){ ($dt := $fromMillis($toMillis($v.departure.datetimeStd),'[FNn,-3], [D1] [MNn,-3]');) })
[ "Mon, 27 Dec", "Mon, 27 Dec" ]

I'm not sure if I remove the chaining if this would help the parser to evaluate in the proper order or not...

Enter jsonata expression (or q to quit):
$map($.NotificationData.dynamicData.flights, function($v, $i, $a){ ($dt := $toMillis($v.departure.datetimeStd)) })
[ 1640607060000, 1640649240000 ]
Enter jsonata expression (or q to quit):
$fromMillis(1640607060000,'[FNn,-3], [D1] [MNn,-3]')
"Mon, 27 Dec"
Enter jsonata expression (or q to quit):
$fromMillis(1640607060000,'[FNn,-3], [D1] [MNn,-3]')
"Mon, 27 Dec"
Enter jsonata expression (or q to quit):
$fromMillis([ 1640607060000, 1640649240000 ],'[FNn,-3], [D1] [MNn,-3]')
Argument 1 of function $fromMillis does not match function signature

@wnm3
Copy link
Member Author

wnm3 commented Dec 29, 2021

This is the parsetree for the expression:

expression={
    "enCurrentDatetime" : (
        $in := $toMillis($now())
          ~> $fromMillis('[FNn], [MNn] [D1], [Y0001] [h01]:[m01]', '-0500');
        $p := $toMillis($now())
          ~> $fromMillis(' [P]') ~> $uppercase();
       
        $return:= $in & $p;
    ),
    "esCurrentDatetime" : (
     $in := $toMillis($now())
          ~> $fromMillis('[FNn], [MNn] [D1], [Y0001] [h01]:[m01]', '-0500');
     $p := $toMillis($now())
          ~> $fromMillis(' [P]') ~> $uppercase();

     $day := $trim($substringBefore($in,','));
     $esDay := $.dateTranslation.es[$lowercase(key)=$lowercase($day)].value;
    
     $month := $trim($substringBefore($substringAfter($in, ', '),' '));
     $esMonth := $.dateTranslation.es[$lowercase(key)=$lowercase($month)].value;

     $return := $replace($in, $day, $esDay) ~> $replace($month, $esMonth);
     $return & $p;
    ),

    "ptCurrentDatetime" : (
     $in := $toMillis($now())
          ~> $fromMillis('[FNn], [MNn] [D1], [Y0001] [h01]:[m01]', '-0500');

     $p := $toMillis($now())
          ~> $fromMillis(' [P]') ~> $uppercase();

     $day := $trim($substringBefore($in,','));
     $ptDay := $.dateTranslation.pt[$lowercase(key)=$lowercase($day)].value;
    
     $month := $trim($substringBefore($substringAfter($in, ', '),' '));
     $ptMonth := $.dateTranslation.pt[$lowercase(key)=$lowercase($month)].value;

     $return := $replace($in, $day, $ptDay) ~> $replace($month, $ptMonth);
     $return & $p;

    ),
    "reservation" : $.NotificationData.dynamicData.reservation,
    "reservationDetails":{
	"issueDate": $.NotificationData.dynamicData.reservationDetails.issueDate,
	"ticketStatus":$.NotificationData.dynamicData.reservationDetails.ticketStatus,
	"ticketType":$.NotificationData.dynamicData.reservationDetails.ticketType,
	"economyBasicFare":$.isBasicEconomyPNR
},
    "translations" : {
        "enUrl" : $.LangURLs[Lang="EN"].LangURL,
        "esUrl" : $.LangURLs[Lang="ES"].LangURL,
        "ptUrl" : $.LangURLs[Lang="PT"].LangURL
    },
    
    "passengers" : $.NotificationData.dynamicData.passengers,
    "flights" : [ $map($.NotificationData.dynamicData.flights, function($v, $i, $a){
                {
                    "operatingAirlineCode" : $v.operatingAirlineCode,
                    
                    "flightNumber": $v.flightNumber,
                    "isFinalDestination":$v.isFinalDestination="true",
					"fareFamily":$v.fareFamily,
					"bookingClass" : $v.nvPair[$lowercase(name)=$lowercase('bookingClass')].value,
                    "status": $v.status,
                    "departure" : {
                        "enDate" : (
                                $dt := $toMillis($v.departure.datetimeStd) ~> $fromMillis('[FNn,*-3], [D1] [MNn,*-3]')
                                
                            ),
                        "esDate" : (
                                $dt := $toMillis($v.departure.datetimeStd) ~> $fromMillis('[FNn,*-3], [D1] [MNn,*-3]');
                                $date := $substringBefore($dt, ',');
                                $month:=$toMillis($v.departure.datetimeStd) ~> $fromMillis('[MNn]');
                                $esDate := $.dateTranslation.es[$lowercase(key)=$lowercase($date)].value;
                                $esMonth:=$.dateTranslation.es[$lowercase(key)=$lowercase($month)].value;
                                
                                $replace($dt, $date, $esDate) ~> $replace($month,$esMonth);
                                
                            ),
                        "ptDate" : (
                                $dt := $toMillis($v.departure.datetimeStd) ~> $fromMillis('[FNn,*-3], [D1] [MNn,*-3]');
                                $date := $substringBefore($dt, ',');
                                $month := $toMillis($v.departure.datetimeStd) ~> $fromMillis('[MNn,*-3]');
                                $ptDate := $.dateTranslation.pt[$lowercase(key)=$lowercase($date)].value;
                                $ptMonth := $.dateTranslation.pt[$lowercase(key)=$lowercase($month)].value;
                                $replace($dt, $date, $ptDate) ~> $replace($month,$ptMonth);
                            ),
                        "dateFormat2" : {
                            "en" : (
                                $dt := $toMillis($v.departure.datetimeStd) ~> $fromMillis('[MNn,*-3] [D1]');
                                 $dt ? $dt : ' '

                            ),
                            "es" : (
                                $dt := $toMillis($v.departure.datetimeStd) ~> $fromMillis('[MNn,*-3] [D1], [Y0001]');
 
                                $date := $substringBefore($substringAfter($dt, ' '), ',');
                                $month := $substringBefore($dt, ' ');
                                $year := $substringAfter($dt, ',') ~> $trim();
 
                                $esMonth := $.dateTranslation.es[$lowercase(key)=$lowercase($month)].value;
 
                                $esMonth & ' ' & $date 
                            ),
                            "pt" : (
                                $dt := $toMillis($v.departure.datetimeStd) ~> $fromMillis('[MNn,*-3] [D1], [Y0001]');
 
                                $date := $substringBefore($substringAfter($dt, ' '), ',');
                                $month := $substringBefore($dt, ' ');
                                $year := $substringAfter($dt, ',') ~> $trim();
 
                                $ptMonth := $.dateTranslation.pt[$lowercase(key)=$lowercase($month)].value;
 
                                $ptMonth& ' ' &$date
                            )
 
                      
                            },
                        "time" : $v.departure.time,
                        "airportCode" : $v.departure.airportCode,
                        "city" : $v.departure.city,
                        "datetimeStd" : $v.departure.datetimeStd,
						"countryCode": $lowercase($v.departure.nvPair[$lowercase(name)=$lowercase('countryCode')].value)
                    },
                    "arrival" : {
                        "enDate" : (
                                $dt := $toMillis($v.arrival.datetimeStd) ~> $fromMillis('[FNn,*-3], [D1] [MNn,*-3]')
                                
                            ),
                        "esDate" : (
                                $dt := $toMillis($v.arrival.datetimeStd) ~> $fromMillis('[FNn,*-3], [D1] [MNn,*-3]');
                                $date := $substringBefore($dt, ',');
                                $month:=$toMillis($v.arrival.datetimeStd) ~> $fromMillis('[MNn]');
                                $esDate := $.dateTranslation.es[$lowercase(key)=$lowercase($date)].value;
                                $esMonth:=$.dateTranslation.es[$lowercase(key)=$lowercase($month)].value;
                                
                                $replace($dt, $date, $esDate) ~> $replace($month,$esMonth);
                                
                            ),
                        "ptDate" : (
                                $dt := $toMillis($v.arrival.datetimeStd) ~> $fromMillis('[FNn,*-3], [D1] [MNn,*-3]');
                                $date := $substringBefore($dt, ',');
                                $month := $toMillis($v.arrival.datetimeStd) ~> $fromMillis('[MNn]');
                                $ptDate := $.dateTranslation.pt[$lowercase(key)=$lowercase($date)].value;
                                $ptMonth := $.dateTranslation.pt[$lowercase(key)=$lowercase($month)].value;
                                $replace($dt, $date, $ptDate) ~> $replace($month,$ptMonth);
                            ),
                        "dateFormat2" : {
                            "en" : (
                                $dt := $toMillis($v.arrival.datetimeStd) ~> $fromMillis('[MNn,*-3] [D1]');
                                 $dt ? $dt : ' '

                            ),
                            "es" : (
                                $dt := $toMillis($v.arrival.datetimeStd) ~> $fromMillis('[MNn,*-3] [D1], [Y0001]');
 
                                $date := $substringBefore($substringAfter($dt, ' '), ',');
                                $month := $substringBefore($dt, ' ');
                                $year := $substringAfter($dt, ',') ~> $trim();
 
                                $esMonth := $.dateTranslation.es[$lowercase(key)=$lowercase($month)].value;
 
                                $esMonth & ' ' & $date 
                            ),
                            "pt" : (
                                $dt := $toMillis($v.arrival.datetimeStd) ~> $fromMillis('[MNn,*-3] [D1], [Y0001]');
 
                                $date := $substringBefore($substringAfter($dt, ' '), ',');
                                $month := $substringBefore($dt, ' ');
                                $year := $substringAfter($dt, ',') ~> $trim();
 
                                $ptMonth := $.dateTranslation.pt[$lowercase(key)=$lowercase($month)].value;
 
                                $ptMonth& ' ' &$date
                            )
 
                        },
                        "time" : $v.arrival.time,
                        "airportCode" : $v.arrival.airportCode,
                        "city" : $v.arrival.city,
                        "datetimeStd" : $v.arrival.datetimeStd,
						"countryCode": $lowercase($v.arrival.nvPair[$lowercase(name)=$lowercase('countryCode')].value)
                    },
                    "flightDuration" : $v.flightDuration,
					"layover":$v.layover,
                    "key" : $v.key
                    
                }

            })],
            "notificationData" : $.NotificationData.message
       
          
}

expr {
fieldList "enCurrentDatetime":
expr (
expr $in:=
expr
expr $toMillis
exprValues (
exprList
expr $now
emptyValues ()
)
~>
expr $fromMillis
exprValues (
exprList
expr '[FNn], [MNn] [D1], [Y0001] [h01]:[m01]'
,
expr '-0500'
)
;
expr $p:=
expr
expr
expr $toMillis
exprValues (
exprList
expr $now
emptyValues ()
)
~>
expr $fromMillis
exprValues (
exprList
expr ' [P]'
)
~>
expr $uppercase
emptyValues ()
;
expr $return:=
expr
expr $in
&
expr $p
;)
,"esCurrentDatetime":
expr (
expr $in:=
expr
expr $toMillis
exprValues (
exprList
expr $now
emptyValues ()
)
~>
expr $fromMillis
exprValues (
exprList
expr '[FNn], [MNn] [D1], [Y0001] [h01]:[m01]'
,
expr '-0500'
)
;
expr $p:=
expr
expr
expr $toMillis
exprValues (
exprList
expr $now
emptyValues ()
)
~>
expr $fromMillis
exprValues (
exprList
expr ' [P]'
)
~>
expr $uppercase
emptyValues ()
;
expr $day:=
expr $trim
exprValues (
exprList
expr $substringBefore
exprValues (
exprList
expr $in
,
expr ','
)
)
;
expr $esDay:=
expr
expr
expr
expr
expr $
.
expr dateTranslation
.
expr es
[
expr
expr $lowercase
exprValues (
exprList
expr key
)
=
expr $lowercase
exprValues (
exprList
expr $day
)
]
.
expr value
;
expr $month:=
expr $trim
exprValues (
exprList
expr $substringBefore
exprValues (
exprList
expr $substringAfter
exprValues (
exprList
expr $in
,
expr ', '
)
,
expr ' '
)
)
;
expr $esMonth:=
expr
expr
expr
expr
expr $
.
expr dateTranslation
.
expr es
[
expr
expr $lowercase
exprValues (
exprList
expr key
)
=
expr $lowercase
exprValues (
exprList
expr $month
)
]
.
expr value
;
expr $return:=
expr
expr $replace
exprValues (
exprList
expr $in
,
expr $day
,
expr $esDay
)
~>
expr $replace
exprValues (
exprList
expr $month
,
expr $esMonth
)
;
expr
expr $return
&
expr $p
;)
,"ptCurrentDatetime":
expr (
expr $in:=
expr
expr $toMillis
exprValues (
exprList
expr $now
emptyValues ()
)
~>
expr $fromMillis
exprValues (
exprList
expr '[FNn], [MNn] [D1], [Y0001] [h01]:[m01]'
,
expr '-0500'
)
;
expr $p:=
expr
expr
expr $toMillis
exprValues (
exprList
expr $now
emptyValues ()
)
~>
expr $fromMillis
exprValues (
exprList
expr ' [P]'
)
~>
expr $uppercase
emptyValues ()
;
expr $day:=
expr $trim
exprValues (
exprList
expr $substringBefore
exprValues (
exprList
expr $in
,
expr ','
)
)
;
expr $ptDay:=
expr
expr
expr
expr
expr $
.
expr dateTranslation
.
expr pt
[
expr
expr $lowercase
exprValues (
exprList
expr key
)
=
expr $lowercase
exprValues (
exprList
expr $day
)
]
.
expr value
;
expr $month:=
expr $trim
exprValues (
exprList
expr $substringBefore
exprValues (
exprList
expr $substringAfter
exprValues (
exprList
expr $in
,
expr ', '
)
,
expr ' '
)
)
;
expr $ptMonth:=
expr
expr
expr
expr
expr $
.
expr dateTranslation
.
expr pt
[
expr
expr $lowercase
exprValues (
exprList
expr key
)
=
expr $lowercase
exprValues (
exprList
expr $month
)
]
.
expr value
;
expr $return:=
expr
expr $replace
exprValues (
exprList
expr $in
,
expr $day
,
expr $ptDay
)
~>
expr $replace
exprValues (
exprList
expr $month
,
expr $ptMonth
)
;
expr
expr $return
&
expr $p
;)
,"reservation":
expr
expr
expr
expr $
.
expr NotificationData
.
expr dynamicData
.
expr reservation
,"reservationDetails":
expr {
fieldList "issueDate":
expr
expr
expr
expr
expr $
.
expr NotificationData
.
expr dynamicData
.
expr reservationDetails
.
expr issueDate
,"ticketStatus":
expr
expr
expr
expr
expr $
.
expr NotificationData
.
expr dynamicData
.
expr reservationDetails
.
expr ticketStatus
,"ticketType":
expr
expr
expr
expr
expr $
.
expr NotificationData
.
expr dynamicData
.
expr reservationDetails
.
expr ticketType
,"economyBasicFare":
expr
expr $
.
expr isBasicEconomyPNR
}
,"translations":
expr {
fieldList "enUrl":
expr
expr
expr
expr $
.
expr LangURLs
[
expr
expr Lang
=
expr "EN"
]
.
expr LangURL
,"esUrl":
expr
expr
expr
expr $
.
expr LangURLs
[
expr
expr Lang
=
expr "ES"
]
.
expr LangURL
,"ptUrl":
expr
expr
expr
expr $
.
expr LangURLs
[
expr
expr Lang
=
expr "PT"
]
.
expr LangURL
}
,"passengers":
expr
expr
expr
expr $
.
expr NotificationData
.
expr dynamicData
.
expr passengers
,"flights":
expr [
exprOrSeqList
exprOrSeq
expr $map
exprValues (
exprList
expr
expr
expr
expr $
.
expr NotificationData
.
expr dynamicData
.
expr flights
,
expr function
varList ($v,$i,$a)
{
exprList
expr {
fieldList "operatingAirlineCode":
expr
expr $v
.
expr operatingAirlineCode
,"flightNumber":
expr
expr $v
.
expr flightNumber
,"isFinalDestination":
expr
expr
expr $v
.
expr isFinalDestination
=
expr "true"
,"fareFamily":
expr
expr $v
.
expr fareFamily
,"bookingClass":
expr
expr
expr
expr $v
.
expr nvPair
[
expr
expr $lowercase
exprValues (
exprList
expr name
)
=
expr $lowercase
exprValues (
exprList
expr 'bookingClass'
)
]
.
expr value
,"status":
expr
expr $v
.
expr status
,"departure":
expr {
fieldList "enDate":
expr (
expr $dt:=
expr
expr $toMillis
exprValues (
exprList
expr
expr
expr $v
.
expr departure
.
expr datetimeStd
)
~>
expr $fromMillis
exprValues (
exprList
expr '[FNn,-3], [D1] [MNn,-3]'
)
)
,"esDate":
expr (
expr $dt:=
expr
expr $toMillis
exprValues (
exprList
expr
expr
expr $v
.
expr departure
.
expr datetimeStd
)
~>
expr $fromMillis
exprValues (
exprList
expr '[FNn,-3], [D1] [MNn,-3]'
)
;
expr $date:=
expr $substringBefore
exprValues (
exprList
expr $dt
,
expr ','
)
;
expr $month:=
expr
expr $toMillis
exprValues (
exprList
expr
expr
expr $v
.
expr departure
.
expr datetimeStd
)
~>
expr $fromMillis
exprValues (
exprList
expr '[MNn]'
)
;
expr $esDate:=
expr
expr
expr
expr
expr $
.
expr dateTranslation
.
expr es
[
expr
expr $lowercase
exprValues (
exprList
expr key
)
=
expr $lowercase
exprValues (
exprList
expr $date
)
]
.
expr value
;
expr $esMonth:=
expr
expr
expr
expr
expr $
.
expr dateTranslation
.
expr es
[
expr
expr $lowercase
exprValues (
exprList
expr key
)
=
expr $lowercase
exprValues (
exprList
expr $month
)
]
.
expr value
;
expr
expr $replace
exprValues (
exprList
expr $dt
,
expr $date
,
expr $esDate
)
~>
expr $replace
exprValues (
exprList
expr $month
,
expr $esMonth
)
;)
,"ptDate":
expr (
expr $dt:=
expr
expr $toMillis
exprValues (
exprList
expr
expr
expr $v
.
expr departure
.
expr datetimeStd
)
~>
expr $fromMillis
exprValues (
exprList
expr '[FNn,-3], [D1] [MNn,-3]'
)
;
expr $date:=
expr $substringBefore
exprValues (
exprList
expr $dt
,
expr ','
)
;
expr $month:=
expr
expr $toMillis
exprValues (
exprList
expr
expr
expr $v
.
expr departure
.
expr datetimeStd
)
~>
expr $fromMillis
exprValues (
exprList
expr '[MNn,-3]'
)
;
expr $ptDate:=
expr
expr
expr
expr
expr $
.
expr dateTranslation
.
expr pt
[
expr
expr $lowercase
exprValues (
exprList
expr key
)
=
expr $lowercase
exprValues (
exprList
expr $date
)
]
.
expr value
;
expr $ptMonth:=
expr
expr
expr
expr
expr $
.
expr dateTranslation
.
expr pt
[
expr
expr $lowercase
exprValues (
exprList
expr key
)
=
expr $lowercase
exprValues (
exprList
expr $month
)
]
.
expr value
;
expr
expr $replace
exprValues (
exprList
expr $dt
,
expr $date
,
expr $ptDate
)
~>
expr $replace
exprValues (
exprList
expr $month
,
expr $ptMonth
)
;)
,"dateFormat2":
expr {
fieldList "en":
expr (
expr $dt:=
expr
expr $toMillis
exprValues (
exprList
expr
expr
expr $v
.
expr departure
.
expr datetimeStd
)
~>
expr $fromMillis
exprValues (
exprList
expr '[MNn,
-3] [D1]'
)
;
expr
expr $dt
?
expr $dt
:
expr ' '
)
,"es":
expr (
expr $dt:=
expr
expr $toMillis
exprValues (
exprList
expr
expr
expr $v
.
expr departure
.
expr datetimeStd
)
~>
expr $fromMillis
exprValues (
exprList
expr '[MNn,-3] [D1], [Y0001]'
)
;
expr $date:=
expr $substringBefore
exprValues (
exprList
expr $substringAfter
exprValues (
exprList
expr $dt
,
expr ' '
)
,
expr ','
)
;
expr $month:=
expr $substringBefore
exprValues (
exprList
expr $dt
,
expr ' '
)
;
expr $year:=
expr
expr $substringAfter
exprValues (
exprList
expr $dt
,
expr ','
)
~>
expr $trim
emptyValues ()
;
expr $esMonth:=
expr
expr
expr
expr
expr $
.
expr dateTranslation
.
expr es
[
expr
expr $lowercase
exprValues (
exprList
expr key
)
=
expr $lowercase
exprValues (
exprList
expr $month
)
]
.
expr value
;
expr
expr
expr $esMonth
&
expr ' '
&
expr $date
)
,"pt":
expr (
expr $dt:=
expr
expr $toMillis
exprValues (
exprList
expr
expr
expr $v
.
expr departure
.
expr datetimeStd
)
~>
expr $fromMillis
exprValues (
exprList
expr '[MNn,
-3] [D1], [Y0001]'
)
;
expr $date:=
expr $substringBefore
exprValues (
exprList
expr $substringAfter
exprValues (
exprList
expr $dt
,
expr ' '
)
,
expr ','
)
;
expr $month:=
expr $substringBefore
exprValues (
exprList
expr $dt
,
expr ' '
)
;
expr $year:=
expr
expr $substringAfter
exprValues (
exprList
expr $dt
,
expr ','
)
~>
expr $trim
emptyValues ()
;
expr $ptMonth:=
expr
expr
expr
expr
expr $
.
expr dateTranslation
.
expr pt
[
expr
expr $lowercase
exprValues (
exprList
expr key
)
=
expr $lowercase
exprValues (
exprList
expr $month
)
]
.
expr value
;
expr
expr
expr $ptMonth
&
expr ' '
&
expr $date
)
}
,"time":
expr
expr
expr $v
.
expr departure
.
expr time
,"airportCode":
expr
expr
expr $v
.
expr departure
.
expr airportCode
,"city":
expr
expr
expr $v
.
expr departure
.
expr city
,"datetimeStd":
expr
expr
expr $v
.
expr departure
.
expr datetimeStd
,"countryCode":
expr $lowercase
exprValues (
exprList
expr
expr
expr
expr
expr $v
.
expr departure
.
expr nvPair
[
expr
expr $lowercase
exprValues (
exprList
expr name
)
=
expr $lowercase
exprValues (
exprList
expr 'countryCode'
)
]
.
expr value
)
}
,"arrival":
expr {
fieldList "enDate":
expr (
expr $dt:=
expr
expr $toMillis
exprValues (
exprList
expr
expr
expr $v
.
expr arrival
.
expr datetimeStd
)
~>
expr $fromMillis
exprValues (
exprList
expr '[FNn,-3], [D1] [MNn,-3]'
)
)
,"esDate":
expr (
expr $dt:=
expr
expr $toMillis
exprValues (
exprList
expr
expr
expr $v
.
expr arrival
.
expr datetimeStd
)
~>
expr $fromMillis
exprValues (
exprList
expr '[FNn,-3], [D1] [MNn,-3]'
)
;
expr $date:=
expr $substringBefore
exprValues (
exprList
expr $dt
,
expr ','
)
;
expr $month:=
expr
expr $toMillis
exprValues (
exprList
expr
expr
expr $v
.
expr arrival
.
expr datetimeStd
)
~>
expr $fromMillis
exprValues (
exprList
expr '[MNn]'
)
;
expr $esDate:=
expr
expr
expr
expr
expr $
.
expr dateTranslation
.
expr es
[
expr
expr $lowercase
exprValues (
exprList
expr key
)
=
expr $lowercase
exprValues (
exprList
expr $date
)
]
.
expr value
;
expr $esMonth:=
expr
expr
expr
expr
expr $
.
expr dateTranslation
.
expr es
[
expr
expr $lowercase
exprValues (
exprList
expr key
)
=
expr $lowercase
exprValues (
exprList
expr $month
)
]
.
expr value
;
expr
expr $replace
exprValues (
exprList
expr $dt
,
expr $date
,
expr $esDate
)
~>
expr $replace
exprValues (
exprList
expr $month
,
expr $esMonth
)
;)
,"ptDate":
expr (
expr $dt:=
expr
expr $toMillis
exprValues (
exprList
expr
expr
expr $v
.
expr arrival
.
expr datetimeStd
)
~>
expr $fromMillis
exprValues (
exprList
expr '[FNn,-3], [D1] [MNn,-3]'
)
;
expr $date:=
expr $substringBefore
exprValues (
exprList
expr $dt
,
expr ','
)
;
expr $month:=
expr
expr $toMillis
exprValues (
exprList
expr
expr
expr $v
.
expr arrival
.
expr datetimeStd
)
~>
expr $fromMillis
exprValues (
exprList
expr '[MNn]'
)
;
expr $ptDate:=
expr
expr
expr
expr
expr $
.
expr dateTranslation
.
expr pt
[
expr
expr $lowercase
exprValues (
exprList
expr key
)
=
expr $lowercase
exprValues (
exprList
expr $date
)
]
.
expr value
;
expr $ptMonth:=
expr
expr
expr
expr
expr $
.
expr dateTranslation
.
expr pt
[
expr
expr $lowercase
exprValues (
exprList
expr key
)
=
expr $lowercase
exprValues (
exprList
expr $month
)
]
.
expr value
;
expr
expr $replace
exprValues (
exprList
expr $dt
,
expr $date
,
expr $ptDate
)
~>
expr $replace
exprValues (
exprList
expr $month
,
expr $ptMonth
)
;)
,"dateFormat2":
expr {
fieldList "en":
expr (
expr $dt:=
expr
expr $toMillis
exprValues (
exprList
expr
expr
expr $v
.
expr arrival
.
expr datetimeStd
)
~>
expr $fromMillis
exprValues (
exprList
expr '[MNn,-3] [D1]'
)
;
expr
expr $dt
?
expr $dt
:
expr ' '
)
,"es":
expr (
expr $dt:=
expr
expr $toMillis
exprValues (
exprList
expr
expr
expr $v
.
expr arrival
.
expr datetimeStd
)
~>
expr $fromMillis
exprValues (
exprList
expr '[MNn,
-3] [D1], [Y0001]'
)
;
expr $date:=
expr $substringBefore
exprValues (
exprList
expr $substringAfter
exprValues (
exprList
expr $dt
,
expr ' '
)
,
expr ','
)
;
expr $month:=
expr $substringBefore
exprValues (
exprList
expr $dt
,
expr ' '
)
;
expr $year:=
expr
expr $substringAfter
exprValues (
exprList
expr $dt
,
expr ','
)
~>
expr $trim
emptyValues ()
;
expr $esMonth:=
expr
expr
expr
expr
expr $
.
expr dateTranslation
.
expr es
[
expr
expr $lowercase
exprValues (
exprList
expr key
)
=
expr $lowercase
exprValues (
exprList
expr $month
)
]
.
expr value
;
expr
expr
expr $esMonth
&
expr ' '
&
expr $date
)
,"pt":
expr (
expr $dt:=
expr
expr $toMillis
exprValues (
exprList
expr
expr
expr $v
.
expr arrival
.
expr datetimeStd
)
~>
expr $fromMillis
exprValues (
exprList
expr '[MNn,*-3] [D1], [Y0001]'
)
;
expr $date:=
expr $substringBefore
exprValues (
exprList
expr $substringAfter
exprValues (
exprList
expr $dt
,
expr ' '
)
,
expr ','
)
;
expr $month:=
expr $substringBefore
exprValues (
exprList
expr $dt
,
expr ' '
)
;
expr $year:=
expr
expr $substringAfter
exprValues (
exprList
expr $dt
,
expr ','
)
~>
expr $trim
emptyValues ()
;
expr $ptMonth:=
expr
expr
expr
expr
expr $
.
expr dateTranslation
.
expr pt
[
expr
expr $lowercase
exprValues (
exprList
expr key
)
=
expr $lowercase
exprValues (
exprList
expr $month
)
]
.
expr value
;
expr
expr
expr $ptMonth
&
expr ' '
&
expr $date
)
}
,"time":
expr
expr
expr $v
.
expr arrival
.
expr time
,"airportCode":
expr
expr
expr $v
.
expr arrival
.
expr airportCode
,"city":
expr
expr
expr $v
.
expr arrival
.
expr city
,"datetimeStd":
expr
expr
expr $v
.
expr arrival
.
expr datetimeStd
,"countryCode":
expr $lowercase
exprValues (
exprList
expr
expr
expr
expr
expr $v
.
expr arrival
.
expr nvPair
[
expr
expr $lowercase
exprValues (
exprList
expr name
)
=
expr $lowercase
exprValues (
exprList
expr 'countryCode'
)
]
.
expr value
)
}
,"flightDuration":
expr
expr $v
.
expr flightDuration
,"layover":
expr
expr $v
.
expr layover
,"key":
expr
expr $v
.
expr key
}
}
)
]
,"notificationData":
expr
expr
expr $
.
expr NotificationData
.
expr message
}

@wnm3
Copy link
Member Author

wnm3 commented Dec 29, 2021

So, from above, it appears it wants to evaluate the line: $replace($dt, $date, $esDate) ~> $replace($month,$esMonth);
before it evaluates the variable assignment for $dt so $dt will resolve to a null which is an invalid 2nd argument (recall 1st argument is the context variable from the $map's $v variable).

I'll continue to look into this, but it may take a while... This does explain why the $toMillis function break point isn't hit before the $replace function's break point is hit.

wnm3 pushed a commit that referenced this issue Jan 6, 2022
@wnm3
Copy link
Member Author

wnm3 commented Jan 6, 2022

I was able to find and fix one bug that dealt with how I was processing the Chain (~>) function and context variables. I needed to be more specific about whether we were executing the RHS of the chain where we should expect to use a context variable, whereas on processing the LHS it would depend on the function signature being called. I also found I wasn't handling the case where we had functions on either side of the Chain function so before this expression was failing but not it is working:

"$map($.NotificationData.dynamicData.flights, function($v, $i, $a){ ($dt := $toMillis($v.departure.datetimeStd) ~> $fromMillis('[FNn,-3], [D1] [MNn,-3]');) })";

Unfortunately, this still doesn't fix the overall problem where the variables are not being processed before the $replace function is being called. I've checked in the fixes I made thus far.

We will need to to find a simplified expression where we have the variables being defined ahead of the $replace function but not getting processed...

wnm3 pushed a commit that referenced this issue Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants