Expression cannot be evaluated. in SSIS (IDTSVariableDispenser100 vars, Boolean isSensitive) - ssis

Attempt to parse the expression "#[User::IncrementVal]==1? #[User::SrcFolderCases]: #[User::SrcFolderAdd]: #[User::SrcFolderDeath]" failed. The expression might contain an invalid token, an incomplete token, or an invalid element. It might not be well-formed, or might be missing part of a required element such as a parenthesis.

Syntax of SSIS conditional operator is the following
boolean_expression?expression1:expression2
In your case, the third variable after :, i.e. #[User::SrcFolderDeath] makes the expression void. Either remove it or transform with concatenation with other variable, for example.

Related

Regular Expression extractor in Jmeter not capturing value,

I am writing a regular expression extractor for a dynamic value id from the response data as below
I wrote the expression like this
But this is not capturing the value. This id value is to be used in the next request.
If i use the template as $0$, then it captures the value as %202197
Please help to correct the mistake I have made
I tried with template $0$, and match number 0 and 1, but I am getting the same expression
When I try with $1$ as template,the value is not identified at all
Your response seems to be JSON
JSON is not a regular language hence using regular expressions for parsing it is not the best idea
Consider switching to JSON Extractor, the relevant configuration would be something like:
More information: How to Use the JSON Extractor For Testing
If you want to proceed with regular expressions for any reason consider changing your regular expression part from [0-9]+ to (\d+)

Alternative ways to extract the contents of a JSON string

Consider the following query:
select '"{\"foo\":\"bar\"}"'::json;
This will return a single record of a single element containing a JSON string. See:
test=# select json_typeof('"{\"foo\":\"bar\"}"'::json); json_typeof
-------------
string
(1 row)
It is possible to extract the contents of the string as follows:
=# select ('"{\"foo\":\"bar\"}"'::json) #>>'{}';
json
---------------
{"foo":"bar"}
(1 row)
From this point onward, the result can be cast as a JSON object:
test=# select json_typeof((('"{\"foo\":\"bar\"}"'::json) #>>'{}')::json);
json_typeof
-------------
object
(1 row)
This way seems magical.
I define no path within the extraction operator, yet what is returned is not what I passed. This seems like passing no index to an array accessor, and getting an element back.
I worry that I will confuse the next maintainer to look at this logic.
Is there a less magical way to do this?
But you did define a path. Defining "root" as path is just another path. And that's just what the #>> operator is for:
Extracts JSON sub-object at the specified path as text.
Rendering as text effectively applies the escape characters in the string. When casting back to json the special meaning of double-quotes (not escaped any more) kicks in. Nothing magic there. No better way to do it.
If you expect it to be confusing to the afterlife, add comments explaining what you are doing there.
Maybe, in the spirit of clarity, you might use the equivalent function json_extract_path_text() instead. The manual:
Extracts JSON sub-object at the specified path as text. (This is functionally equivalent to the #>> operator.)
Now, the function has a VARIADIC parameter, and you typically enter path elements one-by-one, like the example in the manual demonstrates:
json_extract_path_text('{"f2":{"f3":1},"f4":{"f5":99,"f6":"foo"}}',
'f4', 'f6') → foo
You cannot enter the "root" path this way. But (what the manual does not add at this point) you can alternatively provide an actual array after adding the keyword VARIADIC. See:
Pass multiple values in single parameter
So this does the trick:
SELECT json_extract_path_text('"{\"foo\":\"bar\"}"'::json, VARIADIC '{}')::json;
And since we are all about being explicit, use the verbose SQL standard cast syntax:
SELECT cast(json_extract_path_text('"{\"foo\":\"bar\"}"'::json, VARIADIC '{}') AS json)
Any clearer, yet? (I would personally prefer your shorter original, but I may be biased, being a "native speaker" of Postgres..)
The question is, why do you have that odd JSON literal including escapes as JSON string in the first place?

How to correctly parse SSIS variable expression?

I created an SSIS variable, which I want to turn into an expression, so I write this as the Expression:
="\\livprodad1.liv.local\UserProfiles$\mike.jones\Documents\Files"
The actual link that I am referencing is:
\livprodad1.liv.local\UserProfiles$\mike.jones\Documents\Files
But I get this message: Expression can not be evaluated
Attempt to parse the expression failed. The expression might contain an invalid token, an incomplete token, or an invalid element. It might not be well-formed, or might be missing part of a required element such as a parenthesis.
What am I doing wrong? How should it be written?
You need to double all the slashes in an expression so
"\livprodad1.liv.local\UserProfiles$\mike.jones\Documents\Files"
becomes
"\\livprodad1.liv.local\\UserProfiles$\\mike.jones\\Documents\\Files"
And if you were intending to encode
"\\livprodad1.liv.local\UserProfiles$\mike.jones\Documents\Files"
it would become
"\\\\livprodad1.liv.local\\UserProfiles$\\mike.jones\\Documents\\Files"
The leading equals sign might point to a different issue as the only explicit location that I can think of where one assigns a value is in the Expression Task. Everywhere else, there's a separate field where you list the variable you are modifying
And if the double quote is part of the expression itself, then you also escape it with a backslash \" Excellent example of escaping both on What is the escape character for SSIS Expression Builder?

Powershell function returning all params when only one is explicitly returned [duplicate]

This question already has answers here:
How do I pass multiple parameters into a function in PowerShell?
(15 answers)
Closed 3 years ago.
I am trying to simplify a script I wrote by creating some functions, however, I can't seem to get them to work the way I want.
An example function will accept 2 or more parameters but only return 1 value. When I do this, it is returning every value, which in this case are all the parameters (2 in this case) which are passed to the function.
I understand from some research that Powershell returns more than is explicitly called on, which is a little confusing, so I have tried some suggestions about assigning those other values to $null but to no avail.
My function and its result when run looks like the following:
function postReq($path, $payload) {
Write-Host $path
}
postReq($url, $params)
> [path value (is correct)] [$payload (shouldn't be included here)]
Your syntax in how you are calling a function is not correct semantically. You write:
postReq($url, $params)
But that is not the correct syntax in PowerShell. (It's valid syntactically, but not semantically.) In PowerShell, functions are called without ( and ) and without ,, as in:
postReq $url $params
When you use ( ), you are passing a single argument to your function.
Solution
You're not invoking the function how you think you are. PowerShell functions are called without parentheses and the argument delimiter is whitespace, not a comma. Your function call should look like this:
postReq $url $params
What is wrong with using traditional C#-like syntax?
Calling it like you are above as postReq($url, $params) has two undesired consequences here:
The parentheses indicate a sub-expression, the code in the parentheses will run first before the outer code and be treated as a single argument. If you are familiar with solving algebraic equations, the order of operations is the same as in PEMDAS - parentheses first.
Whitespace (), and NOT commas (,) are the argument delimiter to Powershell functions. However, the commas do mean something in Powershell syntax - they signify a collection. [1, 2, 3, 4] is functionally the same as 1, 2, 3, 4 in Powershell. In your case above, you are rolling both parameters into a single array argument of [$url, $params], which the stream-writing cmdlets will do an array join with a , as the delimiter in the rendered string.
But what about object instance and static methods?
This can be confusing to some because object instance and class (RE: static) methods ARE called with the traditional C#-like syntax, where you DO need the parentheses to indicate parameter values, and commas are the delimiter. For example:
([DateTime]::Now).ToString()
returns the current local time, and runs the ToString() method on the returned DateTime object. If you used one of its overloads as shown below, you would separate each argument with a , and regardless of whether you need to pass in arguments or not, you still must specify the outer parentheses:
OverloadDefinitions
-------------------
string ToString()
string ToString(string format)
string ToString(System.IFormatProvider provider)
string ToString(string format, System.IFormatProvider provider)
string IFormattable.ToString(string format, System.IFormatProvider formatProvider)
string IConvertible.ToString(System.IFormatProvider provider)
If you were to omit the parentheses on the empty parameter overload above, you would get the preceding output showing the overload definitions, unlike the behavior when calling functions with no argument.
It's a little odd, but I remember that in any programming language, functions and methods are similar, but distinct, and it's no different in Powershell other than functions and methods are less alike than they are in other languages. I find a good rule of thumb for this is:
Invoke methods with C# syntax and functions with shell syntax.

Pattern does not work about lazy regular expressions in json context

I have this context:
{"id":"123","title":"aaa","url":"aaaa","visit":"1"},{"id":"456","title":"aaa","url":"aaaa","visit":"0"},{"id":"789","title":"aaa","url":"aaaa","visit":"0"},
I want to get all id with visit equal to 0.
I write this pattern:
{"id":"(.*?)".*?"visit":"0"}
As you can see result in here:
https://regex101.com/r/H0LXQ9/2
return 123 and 789 !
But correct return that I expect must be 456 and 789.
What's correct pattern for it?
This is because .*?, although lazy, will extend until the first "visit":"0" match succeeds (as opposed to greedy .*, which would extend until the last match.)
You need to change "any char" pattern to "not a string boundary" and "not an object boundary":
{"id":"([^"]*?)"[^}]*?"visit":"0"}
^^^^ ^^^^
Demo: https://regex101.com/r/H0LXQ9/3
Please note this would work only until string values contain (escaped) quotes or braces. Generally, parsing JSON with regex is bad idea. Use JSON parser and process the resulting objects instead.
You could use look ahead:
\d+(?=","title[^}]*?visit":"0"})
https://regex101.com/r/H0LXQ9/4