Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2024 07:43 AM
Hi @dpc ,
if you like using SQL:
1. Test data:
# Sample data
data = [("1", "A"), ("1", "A"), ("2", "B"), ("2", "B"), ("3", "C")]
# Create DataFrame
df = spark.createDataFrame(data, ["id", "value"])
# Write to Delta table
df.write.format("delta").mode("overwrite").saveAsTable("duplicates")2. Removing the duplicates from the table
%sql
CREATE OR REPLACE TEMP VIEW dedups AS
SELECT DISTINCT * FROM duplicates;
-- Overwrite the existing Delta table with distinct rows
INSERT OVERWRITE duplicates
SELECT * FROM dedups;
SELECT *
FROM duplicates;3. No duplicates in duplicates: