How to get a length of the array in Denodo? - denodo

I have a column in the Denodo view with the type ARRAY. How can I get the length of this array? Standard sql ARRAY_LENGTH function is not working.

You can use
COUNT((<ARRAY_FIELD>).value)
Notice that you can not use COUNT() over the aggregate function LIST() directly.

Related

PowerAutomate : Get max columnvalue From dataverse table

I have a Dataverse table named my_sample_table.
Inside the table I have a column named my_sample_column of type integer whose max value should be returned. Am trying to achieve this by using the List rows action provided with PowerAutomate.
Is there a filter query that can be written on the Filter rows property ? similar to what we use with SQL : max(columnname)
Or any other queries that can be included in the List rows action which will return the same result.
I know that I can iterate through the column values to get the max value using an expresion or by sorting it and getting the topmost one. But I was wondering whether there are any direct approach to it.
I would try and use a max aggregate for this column in a Fetch Xml query:
https://learn.microsoft.com/en-us/power-apps/developer/data-platform/use-fetchxml-aggregation#max

I have an array a=[1,2,3,4,5,6] and in next line i want array that has only even values in it. Trying to do this by .collect but value is in boolean

a=[1,2,3,4,5,6,7,8]
w=a.collect{|i| i%2==0}
p w
The result is coming to be
[false,true,false,true]
why?
When i am doing
w=a.collect{|i| i+2}
Result is an array like
[3,4,5,6,7,8,9,10,11]
Why? What am i doing wrong?
You don't need map / collect (they are aliases), you need
array.select(&:even?)
or
array.reject(&:odd?)
These methods filter original array, unlike map that performs actions with every element and returns new array of the same length
That's why you get boolean array same length instead of filtering
Please read more in docs:
Array#map, Array#select, Array#reject

Higher order function sort() used it with other higher order function its working with let content also

So, any reason behind happen this things, because when i perform sort() function with let type at that time xcode give me a compile time error
i tried it in my playgound with only sort function and sort() function with other higher order function.
like so
let name = ["mehul","HeLLi","JeniFER","Ankul"]
name.sort()
error :
Cannot use mutating member on immutable value: 'name' is a 'let' constant
but with other higher order functions
let nameStartingWithBArray = name.filter {$0.first != "B"}.map {$0.uppercased()}.sorted()
now there is no error
Please consider the subtle but crucial difference between sort and sorted
sort has no return value. It sorts in place that means the calling object is mutated.
sorted ( as well as filter and map) returns a new object with the result of the operation.
sort() basically works with the list itself. It modifies the original list in place. The return value is None.
name.sort() sorts the list and save the sorted list.
sorted() works on any iterable that may include list, dict and so on. It returns another list and doesn't modify the original list.
sorted() returns a sorted copy of the list (a new sorted list), without changing the original list.
Keynote : sort() is faster than sorted()
The sort function sorts the collection in place - i.e. it modifies the array, name, on which you call sort.
filter on the other hand returns an array and does not modify the original array.
Compare sort with sorted which again returns a new array and does not modify the original array.
So, you can write
let sortedNames = name.sorted()
sortedNames will be in order, while name will be in the original, unsorted, order.
If you write
var name = ["mehul","HeLLi","JeniFER","Ankul"]
name.sort()
then name will be in order, and because it is declared as var rather than a constant with let the change is permitted.
The sort func you are using is the mutating func, that means sort function internally sort the array in the same variable.
Mutating Func : To modify the properties of your structure or enumeration within a particular method, you can opt in to mutating behavior for that method. The method can then mutate (that is, change) its properties from within the method, and any changes that it makes are written back to the original structure when the method ends.
So. let doesn't allow sort for doing mutating, so you need to make it var.
More ever, if you use sorted(by:) , it returns new array of sorted values. So here you don't get any error.

What is simplest way to convert :pluck or :collect results to array of strings in Rails?

I have a model called Record and belongs Product model,
the price column type is hexadecimal. Rails already convert it to string in view. But I wanna get them in my console queries.
Example code for pluck:
Product.first.records.pluck(:price)
This query displays the values in array as hexadecimal. There is a method called to_sentences for pluck values but its not enough for my case.
The problem is same in collect method:
Product.first.records.collect(&:price)
What is the pluck query to display my hexadecimal data as array of strings like:
["45,46","75,42"]
Product.first.records.pluck(:price).map(&:to_s)
please try this:
Product.first.records.pluck(:price).join(',')

Create and iterate through an array in Velocity Template Language

How to create an array in VTL and add contents to the array? Also how to retrieve the contents of the array by index?
According to Apache Velocity User Guide, right hand side of assignments can be of type
Variable reference
List item
String literal
Property reference
Method reference
Number literal
ArrayList
Map
You can create an empty list, which would satisfy all your needs for an array, in an Apache Velocity template with an expression like:
#set($foo = [])
or initialize values:
#set($foo = [42, "a string", 21, $myVar])
then, add elements using the Java add method:
$foo.add(53);
$foo.add("another string");
but beware, as the Java .add() method for the list type returns a boolean value, when you add an element to the list, Velocity will print, for instance, "true" or "false" based on the result of the "add" function.
A simple work around is assigning the result of the add function to a variable:
#set($bar = $foo.add(42))
You can access the elements of the list using index numbers:
<span>$foo[1]</span>
Expression above would show a span with the text "a string". However the safest way to access elements of a list is using foreach loops.
Creating an array is easy:
#set($array = [])
Putting an element into an array is also easy:
$array.add(23)
Getting an element from an array depends from your Velocity version.
In Velocity 1.6 you must use
$array.get($index)
Since Velocity 1.7 you can use the classic form:
$array[$index]
I haven't created an array in VTL but passed arrays to VTL context and used them. In VTL, you can not retrieve array contents by index, you only use foreach, as example this code is copied from my Dynamic SQL generation VTL Script:
#foreach( $col in $Columns ) SUM($col.DBColumn) AS ''$col.Name''#if($velocityCount!=$Columns.Count), #end #end
For this reason, we also can not have 2D arrays. When I needed an array to store 2 objects in a row, I used the workaround of defining a new class, and putting objects of that class in the single dimensional array.

Resources