Mi sono imbattuto in qualcosa di strano con join esterni a sinistra su più chiavi in BigQuery. Se una delle chiavi è null
nella tabella di destra, non corrisponde e pertanto inserisce null
in tutti i valori per la tabella corretta.Un join esterno a sinistra in BigQuery su più chiavi non avviene se uno di questi è nullo
Se ho 2 tabelle
Table1 Table2
------------ ----------------
k1 |k2 |v3 k1 |k2 | v4
------------ ----------------
foo|boo |hey foo|NULL| you
bar|test|yo bar|test| hi
foo|NULL|hey
e mi unisco il seguente
SELECT t1.k1, t1.k2, t1.v3, t2.v4 FROM [Table1] t1
LEFT OUTER JOIN EACH [Table2] t2
ON t1.k1=t2.k1 AND t1.k2=t2.k2
ottengo un risultato come questo
t1_k1|t1_k2|t1_v3|t2_v4
-----------------------
foo |boo |hey |NULL --No match here so NULL in t2_v4 it's ok
bar |test |hey |hi --It matches here on bar and test
foo |NULL |hey |NULL --It doesn't match on foo NULL.
mi aspetterei che l'ultima riga era
foo |NULL |hey |you
È questo il comportamento previsto? Con questo intendo non ci sono corrispondenze su NULL
.
C'è qualche altro modo di produrre il risultato che voglio?
Alcuni altri SQL hanno "NON È DISTINTIVO DA", ma BigQuery non ce l'ha. Vedi di più su "Come riscrivere IS DISTINCT FROM e NON DISTINTIVO DA?" http://stackoverflow.com/questions/10416789/how-to-rewrite-is-distinct-from-and-is-not-distinct-from –