How to deal with empty/null values that appear as an Error on my transform tables? - palantir-foundry

I have applied a numeric formula transform on my transform table that has inherited null/empty values from upstream charts. How can I resolve this error?

Reinterpreting the null as 0 will get rid of the error, because the numeric formula transform is expecting a numeric value. In order to do this, you must use the coalesce transform in the transform table by first selecting the column that contains the null values, and then replacing it with 0 as shown it the screenshot below.

Related

SSIS conditional expression not handling conditional cast to NULL DT_STR

I'm having a little trouble with an SSIS expression where, in a Derived Column Transformation Data Flow Task, I am attempting to grab a 6 character substring from a string input, casting the derived columns value to NULL if it doesn't exist. This is the code I am using, with line breaks and indentation added for readability:
KeyValueLength == -2 ?
NULL(DT_STR,6,65001) :
(
KeyValueLength == -1 ?
(DT_STR,6,65001)RTRIM(SUBSTRING(StringInput,KeyValueStart,999)) :
(DT_STR,6,65001)SUBSTRING(StringInput,KeyValueStart,KeyValueLength)
)
(For reference, when KeyValueLength is -2 the key value is not found, when it is -1 then it is found at the end of StringInput, any other number and it is found in the middle of StringInput. This code works for other key values I'm getting that are casting to DT_I4 and DT_DECIMAL)
Individually, the following three expressions do not generate an error:
NULL(DT_STR,6,65001)
(DT_STR,6,65001)RTRIM(SUBSTRING(StringInput,KeyValueStart,999))
(DT_STR,6,65001)SUBSTRING(StringInput,KeyValueStart,KeyValueLength)
But when put together in that nested conditional above, I get the following error when trying to save the window:
For operands of the conditional operator, the data type DT_STR is
supported only for input columns and cast operations. The expression
"KeyValueLength == -2 ? NULL(DT_STR,6,65001) : (KeyValueLength == -1 ?
(DT_STR,6,65001)RTRIM(SUBSTRING(StringInput,KeyValueStart,999)) :
(DT_STR,6,65001)SUBSTRING(StringInput,KeyValueStart,KeyValueLength))"
has a DT_STR operand that is not an input column or the result of a
cast, and cannot be used with the conditional operation. To perform
this operation, the operand needs to be explicitly cast with a cast
operator.
I'm having a little trouble figuring out exactly what the issue is here. That error message suggests it's to do with the use of conditionals, but I'm not seeing the problem.
So, in the infinite wisdom of Microsoft, this is null as a DT_STR and perfectly valid as a direct value assignment:
NULL(DT_STR,6,65001)
But if you want to assign that value in a conditional where all eventual conditions must be the same type you have to do this:
(DT_STR,6,65001)NULL(DT_STR,6,65001)
The same does not apply for other types, where something like NULL(DT_I4) is valid irrespective of whether it is directly assigned or assigned via condition. SMH

Expression in query treated as string

I am having a hell of a time trying to add two calculated fields in a query together. My first record has field1= 1, and field2= 5, and the field that is trying to add them as 15!
So it’s treating them as a string.
When I try to use the function of SUM() I get an error of some of the other fields not being used in expressions, which I don’t understand.
Subtracting the two fields works as does multiplication.
I am unable to change the format of either fields in the properties as the drop down menu is blank.
Please help!
Aggregate functions act on rows not fields. Sum(field1) adds the values of field1 for group of records. Use aggregate functions in an aggregate (GROUP BY) query.
Plus (+) character will concatenate text values but add numeric. Apparently, your two fields are providing text values. Either correct the field data type or use function to convert values to number. Convert at least one field and Access will perform arithmetic instead of concatenation on all terms of expression.
Val(field1) + field2
This assumes no fields are Null. Number conversion functions will error with Null. Also, arithmetic with Null returns Null. If Null is possibility, handle with Nz().
Val(Nz(field1,0)) + Nz(field2,0)

PGSQL - No function matches the given name and argument types. You might need to add explicit type casts

This code gives an error. I have looked similar type questions and couldn't find the answer.
sum(COALESCE(((rpt.report_target_data::json->>'itemQuantity')::int)::int),0) as itemQuantity,
report_target_data is a json object and 'itemQuantity' is an element of that json. Sometimes that field contains an empty value. So when I try to get the sum it gives an error because postgres cannot get the sum if a column had a empty value. What is the wrong with the above code. It there a way to walk around that matter? Is there a way to calculate sum even if some rows contain empty values?
Here is the error of the above code ->
No function matches the given name and argument types. You might need to add explicit type casts.
In my case, it was not a COALESCE problem but I ended up in this question.
I noticed that my column values were characters (the varchar type) so what I did is:
select sum(cast(num_suf as int)) as total from results;
Just in case someone lands in this question again :)

CountDistinct to return negative values gives #error

I'm writing a simple expression to count distinct values in my sql query. For a subset of properties, if they equal "lost/sold" I want them to be negative, but I am receiving #Error. Any idea why this is?
=Countdistinct(IIF(Fields!PortfolioChangeStatusCodeID.Value="Lost/Sold",Fields!LeaseNumber.Value*-1,Fields!LeaseNumber.Value))
Fields!LeaseNumber.Value is either null or not numeric. Checking for both would solve this.
Clearly, there is no need to check for both if (for instance) the value could never be null.
=Countdistinct( IIF(Fields!PortfolioChangeStatusCodeID.Value="Lost/Sold",ISNOTHING(CINT(Fields!LeaseNumber.Value),0)*-1,ISNOTHING(CINT(Fields!LeaseNumber.Value),0)))

Is there any way to modify a column before it is ordered in MySQL?

I have a table with a field value which is a varchar(255). The contents of the field can be quite varied:
$1.20
$2994
$56 + tax (This one can be ignored or truncated to $56 if necessary)
I have a query constructed:
SELECT value FROM unnamed_table ORDER BY value
However, this of course uses ASCII string comparison to order the results and does not use any numerical type of comparison.
Is there a way to truly order by value without changing the field type to DECIMAL or something else? In other words, can the value field be modified ('$' removed, value converted to decimal) on the fly before the results are sorted?
You could sort on an expression made to "parse" the text into decimal
SELECT value FROM unnamed_table ORDER BY expression_returning_decimal(value)
Where your expression uses MySQL functions to extract the number from the string depending on what form you expect it to take (something like CAST(value AS DECIMAL(10,2)), but you'll probably need to deal with the extraneous non-numeric characters somehow as I'm not sure what the CAST will give if you don't strip them).
Create a second column without the $-sign, sort on that one and use the data of the original column in your application.
In order to create the helper column and sort on it you would need something like this:
SELECT value, CAST(SUBSTR(value, 2) AS UNSIGNED) sort_col
FROM unnamed_table ORDER BY sort_col