Sto usando Apache Spark nella mia applicazione Java. Ho due DataFrame
s: df1
e df2
. Lo df1
contiene s con email
, firstName
e lastName
. df2
contiene s con email
.Come implementare NOT IN per due DataFrames con struttura diversa in Apache Spark
Voglio creare un DataFrame
: df3
che contiene tutte le righe df1
, che e-mail non è presente in df2
.
C'è un modo per farlo con Apache Spark? Ho cercato di creare JavaRDD<String>
da df1
e df2
da loro toJavaRDD()
colata e filtrando df1
a contenere tutte le email e dopo che l'utilizzo di subtract
, ma non so come mappare la nuova JavaRDD
per ds1
e ottenere un DataFrame
.
Fondamentalmente ho bisogno di tutte le righe che sono in df1
la cui e-mail non è in df2
.
DataFrame customers = sqlContext.cassandraSql("SELECT email, first_name, last_name FROM customer ");
DataFrame customersWhoOrderedTheProduct = sqlContext.cassandraSql("SELECT email FROM customer_bought_product " +
"WHERE product_id = '" + productId + "'");
JavaRDD<String> customersBoughtEmail = customersWhoOrderedTheProduct.toJavaRDD().map(row -> row.getString(0));
List<String> notBoughtEmails = customers.javaRDD()
.map(row -> row.getString(0))
.subtract(customersBoughtEmail).collect();
Grazie. Il primo esempio ha funzionato per me. Questa è la versione Java 'DataFrame customersWhoHaventOrderedTheProduct = clienti .join (customersWhoOrderedTheProduct.select (customersWhoOrderedTheProduct.col (" email ")), customers.col (" email "). EqualTo (customersWhoOrderedTheProduct.col (" email "))," leftouter ") . where (customersWhoOrderedTheProduct.col (" email "). isNull()). drop (customersWhoOrderedTheProduct.col (" email ")); Ho provato l'equivalente SQL ma questo è accaduto' scala.MatchError: UUIDType (di classe org.apache.spark.sql.cassandra.types.UUIDType $) ' –
Sono felice di poterti aiutare. – zero323
Sto usando 'Cassandra' e ho un' UUID' come chiave primaria. Forse Scala non è in grado di eguagliare il tipo. –