How to expand this dynamic column with only 1 value - kql

This Id column is dynamic type, but only holds 1 value (f3019...). I want to get rid of the array so it only has the field value.
When I try mv-expand Id it doesn't do anything
Also the current query is like:
Id = Target.Properties[0].value
When I try
Id = Target.Properties[0].value[0]
Id returns a blank

The dynamic types can hold arrays and dictionaries, but also scalar types.
The fact that Target.Properties[0].value does not behave like an array indicates that it is not an array, but a string.
The representation of it as an array in the GUI relates to the serving lair and not the way it is actually stored.
Use tostring(parse_json(tostring(Target.Properties[0].value))[0]).
Every element within a dynamic field is also of dynamic type.
When running on a dynamic element, parse_json() returns the element As Is.
If we want the element to get parsed, we first need to convert it to string, using tostring().
parse_json() which is used to parse the string, returns an array (which is a dynamic element).
The first (and only) element of the array is also of a dynamic type.
We use an additional tostring() to convert it to string.
Demo
print value = dynamic('["Hello"]')
| extend value[0] // Null because it's not really an array
| extend result = tostring(parse_json(tostring(value))[0])
value
value_0
result
["Hello"]
Hello
Fiddle
Misleading representation in Azure Monitor:

Related

Convert String to array and validate size on Vertica

I need to execute a SQL query, which converts a String column to a Array and then validate the size of that array
I was able to do it easily with postgresql:
e.g.
select
cardinality(string_to_array('a$b','$')),
cardinality(string_to_array('a$b$','$')),
cardinality(string_to_array('a$b$$$$$','$')),
But for some reason trying to convert String on vertica to array is not that simple, Saw this links:
https://www.vertica.com/blog/vertica-quick-tip-dynamically-split-string/
https://forum.vertica.com/discussion/239031/how-to-create-an-array-in-vertica
And much more that non of them helped.
I also tried using:
select REGEXP_COUNT('a$b$$$$$','$')
But i get an incorrect value - 1.
How can i Convert String to array on Vertica and gets his Length ?
$ has a special meaning in a regular expression. It represents the end of the string.
Try escaping it:
select REGEXP_COUNT('a$b$$$$$', '[$]')
You could create a UDx scalar function (UDSF) in Java, C++, R or Python. The input would be a string and the output would be an integer. https://www.vertica.com/docs/9.2.x/HTML/Content/Authoring/ExtendingVertica/UDx/ScalarFunctions/ScalarFunctions.htm
This will allow you to use language specific array logic on the strings passed in. For example in python, you could include this logic:
input_list = input.split("$")
filtered_input_list = list(filter(None, input_list))
list_count = len(filtered_input_list)
These examples are a good starting point for writing UDx's for Vertica. https://github.com/vertica/UDx-Examples
I wasn't able to convert to an array - but Im able to get the length of the values
What i do is convert to Rows an use count - its not best performance wise
But with this way Im able to do also manipulation like filtering of each value between delimiter - and i dont need to use [] for characters like $
select (select count(1)
from (select StringTokenizerDelim('a$b$c','$') over ()) t)
Return 3

How to get a datatype DF16_RAW with precision 16 by using CL_ABAP_ELEMDESCR for internal table in ABAP?

I have internal type A for DF16_RAW and E for DF34_RAW and now at runtime I am creating a dynamic table for that I want datatype DF16_RAW and DF34_RAW with specified precision based on internal type. My code is like below:
CASE WA_COL-INTTYPE.
WHEN 'A'. LO_DESCR_RESULT = CL_ABAP_ELEMDESCR=>GET_DECFLOAT16( ).
WHEN 'E'. LO_DESCR_RESULT = CL_ABAP_ELEMDESCR=>GET_DECFLOAT34( ).
Here I want to get datatype with specified precision. I don't know how it be done?
Some parts of a variable are specific to the ABAP dictionary a.k.a. "DDIC" (search help, output style for the DF* types, etc.) If you want to create one variable with information specific to the ABAP dictionary, then you must refer to an element in the DDIC (i.e. a data element or table/structure component), then use:
lo_descr_result = cl_abap_typedescr=>describe_by_name( 'DDICdataelement' ).
or
lo_descr_result = cl_abap_typedescr=>describe_by_name( 'DDICtablestruct-Component' ).

Find records where length of array equal to - Rails 4

In my Room model, I have an attribute named available_days, which is being stored as an array.
For example:
Room.first.available_days
=> ["wed", "thurs", "fri"]
What is the best way to find all Rooms where the size of the array is equal to 3?
I've tried something like
Room.where('LENGTH(available_days) = ?', 3)
with no success.
Update: the data type for available_days is a string, but in order to store an array, I am serializing the attribute from my model:
app/models/room.rb
serialize :available_days
Can't think of a purely sql way of doing it for sqlite since available_days is a string.
But here's one way of doing it without loading all records at once.
rooms = []
Room.in_batches(of: 10).each_record do |r|
rooms << r if r.available_days.length == 3
end
p rooms
If you're using postgres you can parse the serialized string to an array type, then query on the length of the array. I expect other databases may have similar approaches. How to do this depends on how the text is being serialized, but by default for Rails 4 should be YAML, so I expect you data is encoded like this:
---
- first
- second
The following SQL will remove the leading ---\n- as well as the final newline, then split the remaining string on - into an array. It's not strictly necessary to cleanup the extra characters to find the length, but if you want to do other operations you may find it useful to have a cleaned up array (no leading characters or trailing newline). This will only work for simple YAML arrays and simple strings.
Room.where("ARRAY_LENGTH(STRING_TO_ARRAY(RTRIM(REPLACE(available_days,'---\n- ',''),'\n'), '\n- '), 1) = ?", 3)
As you can see, this approach is rather complex. If possible you may want to add a new structured column (array or jsonb) and migrate the serialized string into the a typed column to make this easier and more performant. Rails supports jsonb serialization for postgres.

Compare parameter in WHERE clause stored procedure

I have a stored procedures which receives a list of ItemId's. If the list only contain one item this works:
AND (#OrgItemIds = -1 OR ...)
AND (#OrgItemIds = -1 AND...)
but if the list contains more than one item it crashes.
Anybody knows how to fix this? Can I check the size of the list somehow?
Or can I check just the first element of the list like #OrgItemIds[0] or something like that?
There is no "comma-separated set of values" or "array" datatypes in SQL SERVER. You handle the parameter as a scalar variable in your code. Thus when you provide a single value in that list, server implicitly converts it to int and your sp succeeds.When you provide string with commas - it becomes impossible to convert it to int.You have to manually parse your argument, put it into a table variable and then use this table in WHERE clause. Or change handling of this argument to support a string of values instead of scalar value:
... where #OrgItemIds like '%,' + cast(t.OrgItemIds as varchar(10)) + ',%'
which is much worse for performance than filtering by id or list of ids.

Use single value of parameter List in queryString

I am using JasperStudio 5.6.0.final and the report is not generated dynamically from java code.
I have a problem with getting single value from parameter.
In the report I have a parameter A of a type List.
It is not a problem to use it in a clause as IN statement:
AND $X{IN, USER.ID_USER, A}
But I have a problem to get a single value from that list.
I know that my List has always 10 values.
So I want to use it in query, but I don't know how to write the statement:
AND USER.ID_USER = *first_value_of_list_A*
e.g.
AND USER.ID_USER = $P!{Atrybuty}.get(1)
doesn't work
I tried also to assign parameter value to a variable, but as I know it isn't possible to use variables in queryString.
So my question: How to get single value from parameter List in queryString.
What you need to do for this is use
AND $X{IN, USER.ID_USER, A}
Set A type as Collection and that will allow you to even have a single selection or multi selection or just a single value.
Hope that this helps.