Get the whole group where at least one member meets the specified condition #eg36

Below is a table queried from BigQuery database. Its 4th field has comma-separated strings.

Use Java to do this: Retain the first 3 fields, split values the 4th field, make the distinct values names of the fields from 4th to Nth, write 1 or 0 under …


This content originally appeared on DEV Community and was authored by Judy

Below is a table queried from BigQuery database. Its 4th field has comma-separated strings.

Image description

Use Java to do this: Retain the first 3 fields, split values the 4th field, make the distinct values names of the fields from 4th to Nth, write 1 or 0 under each new field to record whether they are originally included in the current row or not, and save result as a new file. Below is the expected result:

Image description

Write SPL code as follows:

Image description

A1: Query the database through JDBC.

A2: Split up each value of the 4th field and generate a record for each distinct value; ~ is the current item.

A3: Perform row-to-column transposition – retain the first 3 columns, transform values of the 4th column to the new field names, and write 1 under each new field if they are included in the current row in the original table and 0 if they are not.

A4: Write result to a csv file.

Read How to Call a SPL Script in Java to find how to integrate SPL into a Java application.

This is one of the problems on StackOverflow. You can click on it to see that the conventional solution is quite complicated, but the SPL approach is really simple and efficient.

SPL open source address


This content originally appeared on DEV Community and was authored by Judy


Print Share Comment Cite Upload Translate Updates
APA

Judy | Sciencx (2024-09-04T00:09:00+00:00) Get the whole group where at least one member meets the specified condition #eg36. Retrieved from https://www.scien.cx/2024/09/04/get-the-whole-group-where-at-least-one-member-meets-the-specified-condition-eg36/

MLA
" » Get the whole group where at least one member meets the specified condition #eg36." Judy | Sciencx - Wednesday September 4, 2024, https://www.scien.cx/2024/09/04/get-the-whole-group-where-at-least-one-member-meets-the-specified-condition-eg36/
HARVARD
Judy | Sciencx Wednesday September 4, 2024 » Get the whole group where at least one member meets the specified condition #eg36., viewed ,<https://www.scien.cx/2024/09/04/get-the-whole-group-where-at-least-one-member-meets-the-specified-condition-eg36/>
VANCOUVER
Judy | Sciencx - » Get the whole group where at least one member meets the specified condition #eg36. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/04/get-the-whole-group-where-at-least-one-member-meets-the-specified-condition-eg36/
CHICAGO
" » Get the whole group where at least one member meets the specified condition #eg36." Judy | Sciencx - Accessed . https://www.scien.cx/2024/09/04/get-the-whole-group-where-at-least-one-member-meets-the-specified-condition-eg36/
IEEE
" » Get the whole group where at least one member meets the specified condition #eg36." Judy | Sciencx [Online]. Available: https://www.scien.cx/2024/09/04/get-the-whole-group-where-at-least-one-member-meets-the-specified-condition-eg36/. [Accessed: ]
rf:citation
» Get the whole group where at least one member meets the specified condition #eg36 | Judy | Sciencx | https://www.scien.cx/2024/09/04/get-the-whole-group-where-at-least-one-member-meets-the-specified-condition-eg36/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.