Hi everybody,
I am trying to subtract a string with this new node "Expression " and I get an error!
I attached the screenshot to this post.
Any thoughts?
regards,
Peyman
I encountered the same issue when recreating a simple example:
It appears that it doesn’t like to get the length argument as a column - if I replace with a “hardcoded” number it works… :
Feels like a bug
It might not like that the arguments you supplied can be missing
because it comes from a column and not from a literal value. (Indicated by the question mark after the type I think – I don’t have experience with the language yet, but it seems intuitive to me that this is the case).
Edit: i tested it and it works if you wrap the column in parse_int(string($["column"]))
but based on the documentation, I am not sure why it works:
string(...)
produces"MISSING"
for a missing valueparse_int(...)
produces a missing value if the input is not an integer
So it should end up with a missing value either way – the output signature ofparse_int
also mentions it:INTEGER | MISSING
… which I assume is the long-form forINTEGER?
.
based on @hotzm answer I suppose I could have missing value somewhere down in my data and command recognize that missing value so it doesnt let me to use the command
Is this what you mean?
In my simple example it still produces an error - at least if the column is of INTEGER type.
If I change the column to string it also does not seem to work:
When hovering over the function I see this documentation:
Arguments
string: Original string
start: Start index (inclusive, 1-indexed)
length: Length - if unspecified, or bigger than the string, get entire string after the start
Return value
STRING | MISSING
Extracted substring
Description
Get a substring of the string. If the length is unspecified or bigger than the remaining characters in the string after the start index, it returns the entire substring after the start index. The start index begins at 1.
**If any of the arguments are MISSING, the result is also MISSING.**
The last sentence sounds like it should be working even if there is a risk of missing values in any of the input arguments…
yeah you are right so now I don’t have any idea why I got an error
Is this what you mean?
parse_int
doesn’t take an Integer?
(as it says), so I converted the Integer
column to a string with string(...)
.
With my int->string->int dance I think I was able to satisfy the expression engine.
So, it is a bug, that the function refuses the length argument from a column directly (internal ticket AP-23042). Thanks for reporting!
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
Hi everyone,
I wanted to wrap up our discussion on the bugs we’ve encountered and explain how they will be addressed in version 5.3.2.
-
substring
Does Not AcceptINTEGER | MISSING
as LengthAs we’ve discussed,
substring($value, 0, $target_length)
currently fails because$target_length
can beMISSING
. While this behavior was intentional, it’s not ideal. In version 5.3.2, this will be fixed so that if$target_length
isMISSING
, the function will behave as if thelength
argument is omitted, returning the substring from the start to the end of the input. -
parse_int
Type Inference Incorrectly ReturnsINTEGER
for Non-Optional InputThe expression
parse_int("not an integer")
should result inMISSING
, but due to a bug, the type inference mistakenly returnsINTEGER
, which does not accommodateMISSING
values. This will be corrected in 5.3.2, ensuring that the type inference accurately reflects whenMISSING
is possible.For example, the workaround discussed earlier:
substring($value, 0, parse_int(string($target_length)))
currently works because of the type inference bug. However, once the bug is fixed in 5.3.2, this workaround will no longer be possible (but also unnecessary, as Bug 1 will be resolved).
As a more robust approach, I’d also like to mention the “Missing coalescing operator” (??
). This operator is designed to handle missing values and could be used as a workaround like this:
substring($value, 0, $target_length ?? 0)
Once 5.3.2 is released, these bugs will be fixed, and the need for hacky workarounds should be eliminated.