I have a problem in transposing a large amount of data table in BigQuery (1.5 billion rows) from rows to columns. I could figure out how to do it with small amount of data when hardcoded, but with this large amount. A snapshot of the table looks like this:
+--------------------------+
| CustomerID Feature Value |
+--------------------------+
| 1 A123 3 |
| 1 F213 7 |
| 1 F231 8 |
| 1 B789 9.1 |
| 2 A123 4 |
| 2 U123 4 |
| 2 B789 12 |
| .. .. .. |
| .. .. .. |
| 400000 A123 8 |
| 400000 U123 7 |
| 400000 R231 6 |
+--------------------------+
So basically there are approximately 400,000 distinct customerID with 3000 features, and not every customerID has the same features, so some customerID may have 2000 features while some have 3000. The end result table I would like to get is each row presents one distinct customerID, and with 3000 columns that presents all the features. Like this:
CustomerID Feature1 Feature2 ... Feature3000
So some of the cells may have missing values.
Anyone has idea how to do this in BigQuery or SQL?
Thanks in advance.