Expand my Community achievements bar.

SOLVED

Need to use Multiple explode function

Avatar

Level 2

Hello @Kumar_Saurabh_ 

 

How to use multiple explode function in the query?  

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Employee

Hi @BellaSnow5378,

 

If you have just one Object Array in the schema, then explode the Object itself and then use the outer query to fetch the attribute value:

Say the object array name is transactionDetails, and there are string fields (transactionAmt, transactionChannel) inside it, then your query will look like this:

select aa.transactionAmt, aa.transactionChannel,... from (select explode(transactionDetails) as aa from table_name);

 

If you have multiple string arrays in the schema, you may need to explode one array first, and then wrap that SELECT with another SELECT to explode:

select distinct aa, explode (column_name2) as bb, eventType timestamp from (select explode(column_name1) as aa, eventType from table_name);

 

Note: explode() will explode one array into multiple records, duplicating the fields that are not part of the explode. You can nest queries including the aggregation (use Distinct or Group by).

 

Regards,

Kumar Saurabh

View solution in original post

1 Reply

Avatar

Correct answer by
Employee

Hi @BellaSnow5378,

 

If you have just one Object Array in the schema, then explode the Object itself and then use the outer query to fetch the attribute value:

Say the object array name is transactionDetails, and there are string fields (transactionAmt, transactionChannel) inside it, then your query will look like this:

select aa.transactionAmt, aa.transactionChannel,... from (select explode(transactionDetails) as aa from table_name);

 

If you have multiple string arrays in the schema, you may need to explode one array first, and then wrap that SELECT with another SELECT to explode:

select distinct aa, explode (column_name2) as bb, eventType timestamp from (select explode(column_name1) as aa, eventType from table_name);

 

Note: explode() will explode one array into multiple records, duplicating the fields that are not part of the explode. You can nest queries including the aggregation (use Distinct or Group by).

 

Regards,

Kumar Saurabh