Multidimensional array BigQuery - arrays

In bigQuery is possible delcare an Array of Array like this
DECLARE ar2 ARRAY DEFAULT [['A','B','C'],['G','H','I'],['N','O','P']];
This syntax return error and I didn't find the right.

Seems that you need to work with array of arrays, if so the documentation says:
BigQuery does not support building arrays of arrays directly. Instead,
you must create an array of structs, with each struct containing a
field of type ARRAY
The page also gives a solution for that by using a array of structs. May something like:
DECLARE ar2 DEFAULT (
WITH words AS
(SELECT ['A','B','C'] as word
UNION ALL SELECT ['G','H','I'] as word
UNION ALL SELECT ['N','O','P'] as word)
SELECT ARRAY(
SELECT STRUCT(word)
FROM words)
AS all_words);

You can't have array of arrays on BigQuery. It does not support it. As per documentation about Declaring an ARRAY type shows:
ARRAY<ARRAY>
(not supported) This is an invalid type declaration which is included here just in case you came looking for how to create a multi-level ARRAY. ARRAYs cannot contain ARRAYs directly. Instead see the next example.
But there are workarounds for it, like using array with structs. Please see below code:
DECLARE TEST ARRAY<STRUCT<x ARRAY<STRING>,y ARRAY<STRING>,z ARRAY<STRING>>>
DEFAULT[(['A','B','C'],['E','F'],['W','X','Y','Z'])];
SELECT TEST;

Related

pyspark filter an array of structs based on one value in the struct

I have a a df with an array of structs:
When I call df.dtypes for this column I would get:
('forminfo', 'array<struct<id: string, code: string>>')
I want to create a new column called 'forminfo_approved' which takes my array and filters within that array to keep only the structs with code == "APPROVED". So if I did a df.dtypes on this new field, the type would be the same, (another array of structs) but I would only have the APPROVED structs from the array.
I've played around with udf's and expr's for a long time now and I can't quite seem to get this one to perform the behavior above. Thanks so much if you can help!
Christie
I think I got it:
df.withColumn("forminfo_approved", expr("filter(form_info, s-> s.code == 'APPROVED')"))

How to cast and pass an argument properly in delphi

I have a very simple code snippet which you can check here:
type
TMatrix = array of array of Byte;
PMatrix = ^TMatrix;
const
testarray:array [0..2,0..2] of Byte=(
(1,2,3), (4,5,6), (7,8,9));
function PickValue(input:PMatrix):Byte;
begin
Result:=input^[1,3];
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Showmessage(inttostr(PickValue(#testarray)));
end;
end.
How can I cast testarray properly to pass it to the PickValue function? Above code crashes in its current form. I'm using delphi 2007.
Thanks in advance!
You cannot cast that static array to be a dynamic array. These types are simply not compatible. The static array is laid out in one contiguous block of memory. The dynamic array has indirection to variable sized arrays at each dimension. In effect think of it as ^^Byte with extra compiler management and meta data. No amount of casting can help you.
You have, at least, the following options:
Copy the contents of the static array to a dynamic array. Then pass that dynamic array to your function.
Switch your static array to be a dynamic array so that no conversion is needed.
Arrange that your function accepts static arrays rather than dynamic arrays, again to avoid requiring a conversion.
Have the function accept a pointer to the first element and the inner dimension. Then perform the indexing manually. The i,j element is at linear offset i*innerDim + j.
Your pointer type PMatrix is probably not needed. Dynamic arrays are already implemented as pointers. This seems to be a level of indirection too far.
Of course, asking for element 3 when the array indices only go up to 2 isn't right, but that is presently the lesser of your concerns. Remember that dynamic arrays are zero based and you have specified zero based for your static array.
I am struggling to be able to recommend which solution is best since I don't understand your real goals and usage based on the simplified example presented here.

How can i recognise an Integer array contains characters in C?

Scenario :-
My array contains elements like 56,12,ew34,45 or 56,12,34rt,45 how
can I show that the array is not integer array?
var Array =[56,12,'ew34',45 or 56,12,'34rt',45];
Actually am trying to find a solution with out Inbuilt Functions.
If array is declared as integer type then it won't accept any char type data.
If you are trying to insert 0 instead of char type data, handle the same conveniently at the insertion time.
Also you can make use of compiler extension typeof.

VFP: 3d arrays?

The following doesn't work... Can you do 3d arrays in foxpro?
DIMENSION sqlresults[10]
select list_code, count(donor) as ndine FROM cGift group by list_code INTO ARRAY sqlresults[1]
edit:
ah, a google search for "vfp multi-dimensional arrays" turned up something ("vfp 3d arrays" didn't)
Foxpro only supports 2d arrays. Guess i'll have to fake it with some substitution (&).
The only problem with your code is that you included a dimension in the query. Try this instead:
select list_code, count(donor) as ndine
FROM cGift
group by list_code
INTO ARRAY sqlresults
That said, on the whole, you're better off putting query results into a cursor than an array.
Sqlresults[1] = sys(2015)
Select ... into cursor (sqlresults[1])
This way your array holds names of the cursors, and you can access their values like:
Select (sqlresults[1])
?fieldname
Or use eval or &

dynamic arrays and flexible arrays

what is the difference between those two types of arrays, thanks in advance for any good example taken from different languages
In C/C++ a flexible array is a member of a struct that is an array (not just a pointer) but doesn't specify a length (reference). As such, a struct with a flexible array is an incomplete type, so the typeof operator can't be used.
A dynamic array is an ordered collection (list) that can grow and shrink. Dynamic arrays are usually implemented as a linked list or something similar.
Dynamic arrays have values that can be changed by code and more values populated. The flexible array is an array that does not have a hard coded limit to its length.

Resources