Related problem: How to create dummy variable columns for thousands of categories in Google BigQuery
I have a table of a list of weighted edges, which is a list of the rating of the user element, it looks like this:
| userId | itemId | rating | 001 | 001 | 5.0 | 001 | 002 | 4.0 | 002 | 001 | 4.5 | 002 | 002 | 3.0
I want to convert this list of weighted edges to an adjacency matrix:
| userId | item001 | item002 | 001 | 5.0 | 4.0 | 002 | 4.5 | 3.0
In accordance with this message, we can do this in two stages, the first step is to extract the input value of the matrix to generate the query, and the second step is to run the query that is generated from the 1st step.
But my question is how to extract the rating value and use the rating value in the expression IF() ? My intuition is to put a subquery inside an IF() , for example:
IF(itemId = blah, (select rating from mytable where userId = blahblah and itemId = blah), 0)
But this query looks too expensive, can anyone give me an example?
thanks
matrix transpose google-bigquery
Charles Chow
source share