Exploding nested array in PySpark - multidimensional-array

I am trying to reach to the 3rd cn Array (highlighted) in, please suggest and logic and sample code.

To solve the nested array, first see the schema of the preceding array, keep the notice of the elements and then follow the following logic to get the array exploded.
explode(preceding_array.first_lv_element.nested_array_name)
I used the below code
cn_cn_cn_arr=cn_cn_arr.select(cn_cn_arr.pid,
cn_cn_arr.id,
explode(cn_cn_arr.cn_cn.cn).alias('cn_cn_cn'))

Related

Need help to iterate through array of JSON response in TOSCA

I just started working on TOSCA, I need one help with the technical issue which I am facing now.
I have an API which sends a array of objects and my test condition should validate a particular field in all objects in array.
In TOSCA when I scanned my API, I see an item attribute is created and that has all fields within it.As per the source I see that we can extract any data from the item either by making the item as "$index" or by setting the value as index==1(index value).
or like this
But I don't want to iterate like this as for each test data, the number of items may vary and I don't want to hard code the response by index.As it fails with a new data set as below
With one test data I got four records and in next iteration response has only three records and also data updated so the verification is failed.
Can someone help me to find out a solution to iterate / loop through all items at once(using some loops) and extract data into buffer.

Find index of item within the array by value?

I am trying to find the index of an item in a classic asp array. i get how it's possible with looping, but is there something else i can use? indexOf() or something along those lines? i can't seem to find anything online
Is it an array of strings, or some other type of objects?
For standard data types you can use Array.BinarySearch(myArray, searchString), but you have to sort the array first.

how to display multiple select list after node submit

I have been reading around and just havent found any type of answer.
I have a multiple select list and need to take the the values of the multiple select and pass them to an API call.
But I dont understand how drupal renders the multiple select list and how to habdle this.
Can someone please explain this to me or if you have come across any docs that explain this, please point me in the right direction.
Also, when I try to write the select to the db, I always get a the value 1... never changes...
Any help is appreciated :)
Solved:
The Multiple select is stored in an associative array where the key value pair are taken from the key value of the list, this means that both the key and value get the same value.
I did this by using devels dvm(); function which displays the array in the message area after the node was saved.

Order of different collection type in java?

Just wanted to confirm the in what order we get the elements from different collection
List
ArrayList:- the sequence in which we put the element we get them in same sequence
LinkedList:- when we add an element in linked list with add(E e) it will be added at last when we get it with itertator it will start from first element to last element. So we can say
the sequence in which we put the element we get them in reverse sequence
Set
HashSet:- No sequence(for getting the elemnets) is guaranted. It will be a random sequence
Tresset:- Will get the elements as per their natural ordering or comparator defined at the time of creation
Map
HashMap:- No sequence(for getting the elemnets) is guaranted. It will be a random sequence
TreeMap:- Will get the elements as per their natural ordering of key or comparator defined at the time of creation
Please let me know if it is correct?
Yup - apart from your use of the word random. The order from a hash set/map won't actually be random; it will just be implementation-specific and unpredicatable. Not quite the same thing - in particular, you shouldn't use it as a source of randomness - but you're right that you shouldn't rely on it being any specific ordering.
This ordering is what you would get if you used an iterator. I think the Java Doc are clear enough for this to be apparent. Mind you this is not all on one page.

Good way to rename fields in Actionscript array?

Should be easy but google couldn't give me a straight answer. I have an array. The fields in the array have underscores that I would like to remove e.g. "Column_1" to "Column 1". Does anyone know a good way to do this without looping through the whole array and rebuilding it anew? I didn't see any methods in the reference that would make this easy. thx
Depending on where you are using this Array, you could use the labelFunction to format the data before presenting it. It is present in Lists, DataGrids and Trees.
But you'd only need this if you have a very large data and wouldn't want to loop over all the records before showing them. A labelFunction would "reprocess" the label everytime before it's presented.
Flex 3 has built in refactoring
Edit... I may have misunderstood..
If you want to format the data in the array just loop through it and use regex to remove the underscores... or you can modify your query which grabs the data (if it is populated from a query)

Resources