Not
Bu sayfaya erişim yetkilendirme gerektiriyor. Oturum açmayı veya dizinleri değiştirmeyi deneyebilirsiniz.
Bu sayfaya erişim yetkilendirme gerektiriyor. Dizinleri değiştirmeyi deneyebilirsiniz.
Column EXISTS Alt Sorgusu için bir nesne döndürür.
Sözdizimi
exists()
İadeler
Column: EXISTS Column alt sorgularını temsil eden bir nesne.
Notlar
yöntemi, exists bir alt sorguda ilgili kayıtların varlığını denetleyen bir boole sütunu oluşturmanın bir yolunu sağlar. bir içinde DataFrameuygulandığında bu yöntem, eşleşen kayıtların ilgili veri kümesinde bulunup bulunmadığına göre satırları filtrelemenize olanak tanır. Sonuçta elde edilen Column nesne doğrudan filtreleme koşullarında veya hesaplanan sütun olarak kullanılabilir.
Örnekler
data_customers = [
(101, "Alice", "USA"), (102, "Bob", "Canada"), (103, "Charlie", "USA"),
(104, "David", "Australia")
]
data_orders = [
(1, 101, "2023-01-15", 250), (2, 102, "2023-01-20", 300),
(3, 103, "2023-01-25", 400), (4, 101, "2023-02-05", 150)
]
customers = spark.createDataFrame(
data_customers, ["customer_id", "customer_name", "country"])
orders = spark.createDataFrame(
data_orders, ["order_id", "customer_id", "order_date", "total_amount"])
from pyspark.sql import functions as sf
customers.alias("c").where(
orders.alias("o").where(
sf.col("o.customer_id") == sf.col("c.customer_id").outer()
).exists()
).orderBy("customer_id").show()
# +-----------+-------------+-------+
# |customer_id|customer_name|country|
# +-----------+-------------+-------+
# | 101| Alice| USA|
# | 102| Bob| Canada|
# | 103| Charlie| USA|
# +-----------+-------------+-------+
customers.alias("c").where(
~orders.alias("o").where(
sf.col("o.customer_id") == sf.col("c.customer_id").outer()
).exists()
).orderBy("customer_id").show()
# +-----------+-------------+---------+
# |customer_id|customer_name| country|
# +-----------+-------------+---------+
# | 104| David|Australia|
# +-----------+-------------+---------+