Nested ternaries, can't spot the error - ssis

I have this nested ternary expression in SSIS that I can't seem to get to work, my eyes are about to come out of my skull.
FINDSTRING(TRIM(f3),"BASICS",1) != 0 ? (UPPER(LEFT(TRIM(f3),1)) == "F" ? #[User::FallBasicsEntityId] : (UPPER(LEFT(TRIM(f3),1)) == "S" ? #[User::SpringBasicsEntityId] : #[user::BasicsEntityId])) : (UPPER(LEFT(TRIM(f3),1)) == "F" ? #[user::FallEntityId] : (UPPER(LEFT(TRIM(f3),1)) == "S" ? #[user::SpringEntityId] : #[user::DefaultEntityId]))
Here's an "indented" version:
FINDSTRING(TRIM(f3),"BASICS",1) != 0
? (
UPPER(LEFT(TRIM(f3),1)) == "F"
? #[User::FallBasicsEntityId]
: (
UPPER(LEFT(TRIM(f3),1)) == "S"
? #[User::SpringBasicsEntityId]
: #[user::BasicsEntityId]
)
)
: (
UPPER(LEFT(TRIM(f3),1)) == "F"
? #[user::FallEntityId]
: (
UPPER(LEFT(TRIM(f3),1)) == "S"
? #[user::SpringEntityId]
: #[user::DefaultEntityId]
)
)
What am I missing? It looks to me like the parentheses are balanced and properly placed.. or are they?
I'm about to ditch this and resort to a script component... it seems to me such an expression would be easier to maintain with C# code...

The parentheses are balanced; the problem is that user is not the same as User.

Related

Postgres : can't make JSONB_PATH_EXISTS work correctly

I'm struggling with JSONB_PATH_EXISTS Postgres function
I'm using PG 12 and following this documentation : https://www.postgresql.org/docs/12/functions-json.html
With the following request (test it on DBFiddle: https://dbfiddle.uk/?rdbms=postgres_12&fiddle=d5aa984182852438c6f71cf5fa70324e) :
select
json
from (
select '{
"fields": {
"foo": true,
"number": 3,
"listnb": [3, 4],
"listenb2": ["3", "4"],
"txt": "hello how are you",
"listtxt": ["hello","how","are", "you", "3"],
"nullval": null
}
}'::jsonb as json
) t
where 1=1
-- Works with 'strict'
AND JSONB_PATH_EXISTS(json -> 'fields' -> 'listtxt', 'strict $ ? (#.type() == "array")')
-- Doesn't work without 'strict'. Why ?
--AND JSONB_PATH_EXISTS(json -> 'fields' -> 'listtxt', '$ ? (#.type() == "array")')
-- Can't add a nested condition on an array element value (syntax error)
--AND JSONB_PATH_EXISTS(json -> 'fields' -> 'listtxt', 'strict $ ? (#.type() == "array" && #[*] ? (# == "how"))')
;
#1 - I can't get type() function work without strict mode
It could be related to the lax mode unwrapping arrays automatically, but the documentation explicitly states that it is not done when type() function is called :
The lax mode facilitates matching of a JSON document structure and path expression if the JSON data does not conform to the expected schema. [...] Automatic unwrapping is not performed only when:
The path expression contains type() or size() methods that return the type and the number of elements in the array, respectively.
[...]
So I don't understand why we have a difference in the result
#2 I can't get the nested condition work (3rd AND in the sample request)
According to the examples in the documentation, the syntax looks OK but I have a syntax error that I don't understand.
Thank you for your help
If you pass the complete JSON value to the function, then the following works:
where jsonb_path_exists(json, '$ ? (#.fields.listtxt.type() == "array")')
However I would probably simply use jsonb_typeof() without a path query
where jsonb_typeof(json -> 'fields' -> 'listtxt') = 'array'

PhpStorm over-indenting multi-line functions

I'm currently attempting to configure PhpStorm to produce fully-PSR-2-compliant code, however its formatter is tripping up on long lines which contain functions with multiple parameters.
When I run the formatter, it converts this:
return ($thisIsALongLine || functionCall($arg1, $arg2));
into this:
return ($thisIsALongLine || functionCall(
$arg1,
$arg2
));
However, what I want is this:
return ($thisIsALongLine || functionCall(
$arg1,
$arg2
));
Does anyone know which formatter option tells it to further indent multi-line function calls in this instance?
Note: Usually, I'd format the above as this:
return ($thisIsALongLine
|| functionCall($arg1, $arg2));
However, that just bypasses the extra indentation issue, which I'd still need to fix for other situations.
Edit: This is the state of Wrapping and Braces, as requested by #LazyOne below:
Edit 2: Examples of two different types of line which PhpStorm's formatter isn't handling correctly. (Disclaimer: This is old code from a legacy system.)
Firstly, this:
if ($validateBudget && $this->getFinancialPeriodService()->validateBudget($formModel->action, $formModel->estimatedBudget, $formModel->startDate, $formModel->endDate, $formModel->isFirstPeriod)) {
becomes this:
if ($validateBudget && $this->getFinancialPeriodService()
->validateBudget($formModel->action, $formModel->estimatedBudget,
$formModel->startDate, $formModel->endDate, $formModel->isFirstPeriod)) {
when I would expect this based on the settings above:
if ($validateBudget && $this->getFinancialPeriodService()
->validateBudget(
$formModel->action,
$formModel->estimatedBudget,
$formModel->startDate,
$formModel->endDate,
$formModel->isFirstPeriod
)
) {
Secondly, if you enable alignment on chained methods, then this:
if ($evaluation->getExpert() != NULL && ($evaluation->getExpert()->getStatusId() == Evaluation::STATUS_ASSIGNED || $evaluation->getEvaluationStage() == Evaluation::STAGE_PROPOSED && CoreDateUtils::dateIsPast($proposal->getCalendar()->getStage1StartDate()) == false || $evaluation->getEvaluationStage() == Evaluation::STAGE_IN_PROGRESS && CoreDateUtils::dateIsPast($proposal->getCalendar()->getStage2StartDate()) == false)) {
is reformatted to this:
if ($evaluation->getExpert() != null && ($evaluation->getExpert()
->getStatusId() == Evaluation::STATUS_ASSIGNED || $evaluation->getEvaluationStage() == Evaluation::STAGE_PROPOSED && CoreDateUtils::dateIsPast($proposal->getCalendar()
->getStage1StartDate()) == false || $evaluation->getEvaluationStage() == Evaluation::STAGE_IN_PROGRESS && CoreDateUtils::dateIsPast($proposal->getCalendar()
->getStage2StartDate()) == false)) {
when I would expect this:
if ($evaluation->getExpert() != null
&& ($evaluation->getExpert()->getStatusId() == Evaluation::STATUS_ASSIGNED
|| $evaluation->getEvaluationStage() == Evaluation::STAGE_PROPOSED
&& CoreDateUtils::dateIsPast($proposal->getCalendar()->getStage1StartDate()) == false
|| $evaluation->getEvaluationStage() == Evaluation::STAGE_IN_PROGRESS
&& CoreDateUtils::dateIsPast($proposal->getCalendar()->getStage2StartDate()) == false)
) {
To be honest, at this point I suspect a bug in the formatter, so will open a ticket with JetBrains, however I'll leave this open in case anyone does know why it over-/underformats things.

SSIS Derived column Transformation setting to BOOL with UPPER(LTRIM(RTRIM

I have a Flag which needs to be set to 1 or 0. so i used Derived column transformation to convert it to bool
as you can se the code it works only when i use an OR operator for both Y and N .
This code below works for IF Flag is Y and N condition
(DT_BOOL)(Flag == "Y" ? 1 : 0) || (DT_BOOL)(Flag == "N" ? 0 : 1)
** working only when FLAG = (Capital)Y OR N *****************
but if my Flag is small 'n' it does not work it still sets to TRUE
I want to make it UPPER and TRIM it at the same time . Which i am having hard time to figure out .
This is my code but it does not work
(DT_BOOL)(UPPER(RTRIM(LTRIM
(Flag == "Y" ? 1 : 0)
)))
||(DT_BOOL)(UPPER(RTRIM(LTRIM(Flag == "N" ? 0 :1)
))) ***** this code is not working *****************
Thanks for your time.
PLEASE look at Tranformation Pic
Try this...
(DT_BOOL)(UPPER(RTRIM(LTRIM(Flag))) == "N" ? 0 :1)

Data Driven Validation/Rule Engine in JAVA

I have data and series of validation (Business logic) before I can use it further. Like following :-
{
"site" : "UK",
"domain" : "xyz.UK",
"currency" : "DOLLAR",
"type" : "unlimited",
"limit" : ""
}
{
"site" : "UK",
"domain" : "xyz.UK",
"currency" : "EURO",
"type" : "limited",
"limit" : "100"
}
{
"site" : "US",
"domain" : "xyz.COM",
"currency" : "DOLLAR",
"type" : "limited",
"limit" : ""
}
Validations FLOW is like
Domain validation
Site = us >> domain = .com
Site = uk >> domain = .uk
Currency validation
Site = us >> currency = DOLLAR
Site = uk >> currency = EURO
Type validation
Site = us >> type = "only limited"
Site = us >> type = "limited/unlimited"
type = limited >> limit > 0
type = unlimited >> limit == null
So only second JSON will pass the validations. First one have wrong Currency and 3 one limit is null.
More fields will keep on adding and the validations will keep on increasing. I dont want to put the validation in JAVA code
as in I have to change the code again and again. Is there any other way to save the validations/rules and there sequence in DB and
fetch the validation/rules from DB to validate the data. If I need to change or add more I can modify DB.
Assuming that the financial data set is available as a Java bean (and that there is a typo US/UK), the third validation can be written as:
rule "check type"
when
Data( site == "US" && type == "limited ||
site == "UK" && type == "limited || == "unlimited,
type == "limited" && limit != null && limit > 0 ||
type == "unlimited" && limit == null )
then
// Data's type and limit is OK
end
This rule would "pass" the check. For determining what is wrong you'll need more rules, each of which pinpoints some fault.

SSIS Derived Column IS NOT NULL with Or expression

I need assistance writing an Derived Column expression that meets this criteria.
IF ([Name of Job] is "Accenture Leadership" OR "Senior Executive") AND [Pay scale Group] IS NOT NULL THEN [Pay scale Group] ELSE [Name of Job].
Thanks,
Try this:([Name of Job] == "Accenture Leadership" ||[Name of Job] == "Senior Executive") && ISNULL([Pay scale Group]) == FALSE ? [Pay scale Group] : [Name of Job]
reference