How to: Handle duplicate records in Azure Data Explorer

Published Sep 12 2019 04:04 AM 8,121 Views

Azure Data Explorer is an append only database that isn’t designed to support frequent data deletion. If you accidentally ingest your data into Azure Data Explorer multiple times, the following tips can help you handle the duplicate records:

  1. Filter out the duplicate rows in the data during query. The arg_max() aggregated function can be used to filter out the duplicate records and return the last record based on the timestamp (or another column).
  2. Filter duplicates during the ingestion process.
  3. Drop extents with duplicated records and re-ingest the data. 
    // create table with the extent ids that include the duplicate data 
    // add the specific date 
    .set ExtentsToCompress <| bla //original table name
    | extend eid = extent_id()
    | dt=ingestion_time() // one option to find the date
    | where dt in a date range // alternative option to find the date
    |summarize by eid
    
    // present extent ids 
    ExtentsToCompress
    
    // ingest the distinct rows into a temp table
    // increase performance 
    .set BlaTmp <| bla
    | extend eid = extent_id()| where eid in (ExtentsToCompress)
    | project-away eid
    | distinct *
    
    // drop extents with duplicates values 
    .drop extents <| .show table bla extents | where ExtentId in(ExtentsToCompress)
    
    // re-ingest the distinct values 
    .set-or-append bla <| BlaTmp
    
    
  4. For few records, use purge command for remove specific records. Note that data deletion using the .purge command is designed to protect personal data and should not be used in other scenarios. It is not designed to support frequent delete requests, or deletion of massive quantities of data, and may have a significant performance impact on the service

 

For more information regarding how to handle queries with duplicated records read:  Handle duplicate data in Azure Data Explorer 

 

 

Learn more about Azure Data Explorer (Kusto):

  1. Azure Data Explorer
  2. Documentation
  3. Course – Basics of KQL
  4. Query explorer
  5. Azure Portal
  6. User Voice
  7. Cost Estimator

Join us to share questions, thoughts, or ideas about Azure Data Explorer (Kusto) and receive answers from the diverse and knowledgeable Azure Data Explorer community.

 

Azure Data Explorer product team

“Join the conversation on the Azure Data Explorer community”.

2 Comments
%3CLINGO-SUB%20id%3D%22lingo-sub-866714%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%3A%20Handle%20duplicate%20records%20in%20Azure%20Data%20Explorer%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-866714%22%20slang%3D%22en-US%22%3E%3CP%3EThank%20you%20for%20this%20information%20%3A)%3C%2Fimg%3E%3C%2FP%3E%3CP%3EJust%20wanted%20to%20check%2C%20instead%20of%20the%20following%20when%20there%20is%20large%20amounts%20of%20data%20%3A%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%2F%2F%20re-ingest%20the%20distinct%20values%20%0A.set-or-append%20bla%20%26lt%3B%7C%20BlaTmp%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3Ecan%20we%20use%20the%20move%20extents%20command%20%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E.move%20extents%20all%20from%20table%20BlaTmp%20to%20table%20bla%3C%2FPRE%3E%3CP%3EI%20was%20lucky%20enough%20to%20have%20some%20time%20with%20one%20of%20the%20product%20team%20who%20highlighted%20this%20command%20to%20me.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-869148%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%3A%20Handle%20duplicate%20records%20in%20Azure%20Data%20Explorer%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-869148%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F412290%22%20target%3D%22_blank%22%3E%40RobBarat%3C%2FA%3E%26nbsp%3Byes%2C%20and%20even%20move%20extents%20all%20has%20better%20performance%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-849028%22%20slang%3D%22en-US%22%3EHow%20to%3A%20Handle%20duplicate%20records%20in%20Azure%20Data%20Explorer%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-849028%22%20slang%3D%22en-US%22%3E%3CP%3EAzure%20Data%20Explorer%20is%20an%20append%20only%20database%20that%20isn%E2%80%99t%20designed%20to%20support%20frequent%20data%20deletion.%20If%20you%20%3CU%3E%3CSPAN%20style%3D%22color%3A%20black%3B%22%3E%3CSTRONG%3Eaccidentally%3C%2FSTRONG%3E%20%3C%2FSPAN%3E%3C%2FU%3Eingest%20your%20data%20into%20Azure%20Data%20Explorer%20multiple%20times%2C%20the%20following%20tips%20can%20help%20you%20handle%20the%20duplicate%20records%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EFilter%20out%20the%20duplicate%20rows%20in%20the%20data%20during%20%3CA%20href%3D%22https%3A%2F%2Fnam06.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253A%252F%252Fdocs.microsoft.com%252Fen-us%252Fazure%252Fdata-explorer%252Fdealing-with-duplicates%2523solution-2-handle-duplicate-rows-during-query%26amp%3Bdata%3D02%257C01%257Ctzgitlin%2540microsoft.com%257C3e5989e4182b43c28c0e08d7375aa7cd%257C72f988bf86f141af91ab2d7cd011db47%257C1%257C0%257C637038734810792575%26amp%3Bsdata%3DHY3tuP1uYt%252BP7PuPvsOI8Ck2tN21PvFEVK8XJX1x3VI%253D%26amp%3Breserved%3D0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Equery%3C%2FA%3E.%20The%20arg_max()%20aggregated%20function%20can%20be%20used%20to%20filter%20out%20the%20duplicate%20records%20and%20return%20the%20last%20record%20based%20on%20the%20timestamp%20(or%20another%20column).%3C%2FLI%3E%0A%3CLI%3EFilter%20duplicates%20during%20the%20%3CA%20href%3D%22https%3A%2F%2Fnam06.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253A%252F%252Fdocs.microsoft.com%252Fen-us%252Fazure%252Fdata-explorer%252Fdealing-with-duplicates%2523solution-3-filter-duplicates-during-the-ingestion-process%26amp%3Bdata%3D02%257C01%257Ctzgitlin%2540microsoft.com%257C3e5989e4182b43c28c0e08d7375aa7cd%257C72f988bf86f141af91ab2d7cd011db47%257C1%257C0%257C637038734810792575%26amp%3Bsdata%3DeFPmMoXwOkRaNlD30VC%252FCW4StHyPxlfgCpzCvLYWlOg%253D%26amp%3Breserved%3D0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Eingestion%20process%3C%2FA%3E.%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fnam06.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253A%252F%252Fdocs.microsoft.com%252Fen-us%252Fazure%252Fkusto%252Fmanagement%252Fextents-commands%2523drop-extents%26amp%3Bdata%3D02%257C01%257Ctzgitlin%2540microsoft.com%257C3e5989e4182b43c28c0e08d7375aa7cd%257C72f988bf86f141af91ab2d7cd011db47%257C1%257C0%257C637038734810802567%26amp%3Bsdata%3DfzWV1sFXE4%252FITCCZq4qwFtJxWeq6jIcNnyAHv5e6ouM%253D%26amp%3Breserved%3D0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EDrop%20extents%20with%20duplicated%20records%3C%2FA%3Eand%20re-ingest%20the%20data.%26nbsp%3B%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%2F%2F%20create%20table%20with%20the%20extent%20ids%20that%20include%20the%20duplicate%20data%20%0A%2F%2F%20add%20the%20specific%20date%20%0A.set%20ExtentsToCompress%20%26lt%3B%7C%20bla%20%2F%2Foriginal%20table%20name%0A%7C%20extend%20eid%20%3D%20extent_id()%0A%7C%20dt%3Dingestion_time()%20%2F%2F%20one%20option%20to%20find%20the%20date%0A%7C%20where%20dt%20in%20a%20date%20range%20%2F%2F%20alternative%20option%20to%20find%20the%20date%0A%7Csummarize%20by%20eid%0A%0A%2F%2F%20present%20extent%20ids%20%0AExtentsToCompress%0A%0A%2F%2F%20ingest%20the%20distinct%20rows%20into%20a%20temp%20table%0A%2F%2F%20increase%20performance%20%0A.set%20BlaTmp%20%26lt%3B%7C%20bla%0A%7C%20extend%20eid%20%3D%20extent_id()%7C%20where%20eid%20in%20(ExtentsToCompress)%0A%7C%20project-away%20eid%0A%7C%20distinct%20*%0A%0A%2F%2F%20drop%20extents%20with%20duplicates%20values%20%0A.drop%20extents%20%26lt%3B%7C%20.show%20table%20bla%20extents%20%7C%20where%20ExtentId%20in(ExtentsToCompress)%0A%0A%2F%2F%20re-ingest%20the%20distinct%20values%20%0A.set-or-append%20bla%20%26lt%3B%7C%20BlaTmp%0A%0A%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3EFor%20few%20records%2C%20use%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fnam06.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253A%252F%252Fdocs.microsoft.com%252Fen-us%252Fazure%252Fkusto%252Fconcepts%252Fdata-purge%26amp%3Bdata%3D02%257C01%257Ctzgitlin%2540microsoft.com%257C3e5989e4182b43c28c0e08d7375aa7cd%257C72f988bf86f141af91ab2d7cd011db47%257C1%257C0%257C637038734810802567%26amp%3Bsdata%3D1Uu2u2YuFwCMhh4zYo4tW1D94Wv3qB5mOmduiIGbnD8%253D%26amp%3Breserved%3D0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Epurge%20command%3C%2FA%3E%26nbsp%3Bfor%20remove%20specific%20records.%20Note%20that%20data%20deletion%20using%20the%26nbsp%3B.purge%26nbsp%3Bcommand%20is%20designed%20to%20protect%20personal%20data%20and%20should%20not%20be%20used%20in%20other%20scenarios.%20It%20is%20not%20designed%20to%20support%20frequent%20delete%20requests%2C%20or%20deletion%20of%20massive%20quantities%20of%20data%2C%20and%20may%20have%20a%20significant%20performance%20impact%20on%20the%20service%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20more%20information%20regarding%20how%20to%20handle%20queries%20with%20duplicated%20records%20read%3A%20%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fnam06.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253A%252F%252Fdocs.microsoft.com%252Fen-us%252Fazure%252Fdata-explorer%252Fdealing-with-duplicates%26amp%3Bdata%3D02%257C01%257Ctzgitlin%2540microsoft.com%257C3e5989e4182b43c28c0e08d7375aa7cd%257C72f988bf86f141af91ab2d7cd011db47%257C1%257C0%257C637038734810812565%26amp%3Bsdata%3D0GHnZRTRd1xcDqL8bGHW4E%252FWbJS%252Bp1SKTpiT3%252BJyxKQ%253D%26amp%3Breserved%3D0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EHandle%20duplicate%20data%20in%20Azure%20Data%20Explorer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELearn%20more%20about%20Azure%26nbsp%3BData%20Explorer%20(Kusto)%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CU%3E%3CA%20tabindex%3D%22-1%22%20title%3D%22https%3A%2F%2Femea01.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253a%252f%252fazure.microsoft.com%252fen-us%252fservices%252fdata-explorer%252f%26amp%3Bdata%3D02%257c01%257ctzgitlin%2540microsoft.com%257c33b94d34a7284713b30108d68cecb3ce%257c72f988bf86f141af91ab2d7cd011db47%257c1%257c0%257c636851345592939394%26amp%3Bsdata%3Dvgtfwifedpsnuqd4tclyljcmmq3cw%252fea7coupv%252fdoiw%253d%26amp%3Breserved%3D0%22%20href%3D%22https%3A%2F%2Femea01.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253A%252F%252Fazure.microsoft.com%252Fen-us%252Fservices%252Fdata-explorer%252F%26amp%3Bdata%3D02%257C01%257Ctzgitlin%2540microsoft.com%257C33b94d34a7284713b30108d68cecb3ce%257C72f988bf86f141af91ab2d7cd011db47%257C1%257C0%257C636851345592939394%26amp%3Bsdata%3DVgtfwIFedpSnuQd4TClYLJCmmQ3CW%252FeA7coUPv%252FDOiw%253D%26amp%3Breserved%3D0%22%20target%3D%22_blank%22%20rel%3D%22noreferrer%20noopener%20nofollow%22%3EAzure%20Data%20Explorer%3C%2FA%3E%3C%2FU%3E%3C%2FLI%3E%0A%3CLI%3E%3CU%3E%3CA%20tabindex%3D%22-1%22%20title%3D%22https%3A%2F%2Femea01.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253a%252f%252fdocs.microsoft.com%252fen-us%252fazure%252fdata-explorer%252f%26amp%3Bdata%3D02%257c01%257ctzgitlin%2540microsoft.com%257c33b94d34a7284713b30108d68cecb3ce%257c72f988bf86f141af91ab2d7cd011db47%257c1%257c0%257c636851345592949402%26amp%3Bsdata%3D1z9id3dkxvfw8sdd3m6syagfpt83lcwckxkktvpppbi%253d%26amp%3Breserved%3D0%22%20href%3D%22https%3A%2F%2Femea01.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253A%252F%252Fdocs.microsoft.com%252Fen-us%252Fazure%252Fdata-explorer%252F%26amp%3Bdata%3D02%257C01%257Ctzgitlin%2540microsoft.com%257C33b94d34a7284713b30108d68cecb3ce%257C72f988bf86f141af91ab2d7cd011db47%257C1%257C0%257C636851345592949402%26amp%3Bsdata%3D1Z9Id3dkxVfW8sDD3M6syagFpT83LCwCKxkKTvPppbI%253D%26amp%3Breserved%3D0%22%20target%3D%22_blank%22%20rel%3D%22noreferrer%20noopener%20nofollow%22%3EDocumentation%3C%2FA%3E%3C%2FU%3E%3C%2FLI%3E%0A%3CLI%3E%3CU%3E%3CA%20tabindex%3D%22-1%22%20title%3D%22https%3A%2F%2Femea01.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253a%252f%252fwww.pluralsight.com%252fcourses%252fkusto-query-language-kql-from-scratch%26amp%3Bdata%3D02%257c01%257ctzgitlin%2540microsoft.com%257c33b94d34a7284713b30108d68cecb3ce%257c72f988bf86f141af91ab2d7cd011db47%257c1%257c0%257c636851345592959411%26amp%3Bsdata%3Dlkjftf%252fazzi0nnn4jg2pcpfzflyxugj%252f2%252f%252fqksysedc%253d%26amp%3Breserved%3D0%22%20href%3D%22https%3A%2F%2Femea01.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253A%252F%252Fwww.pluralsight.com%252Fcourses%252Fkusto-query-language-kql-from-scratch%26amp%3Bdata%3D02%257C01%257Ctzgitlin%2540microsoft.com%257C33b94d34a7284713b30108d68cecb3ce%257C72f988bf86f141af91ab2d7cd011db47%257C1%257C0%257C636851345592959411%26amp%3Bsdata%3DlkjFtf%252FAzzi0nnn4jg2pCpfZfLYXugJ%252F2%252F%252FqksySeDc%253D%26amp%3Breserved%3D0%22%20target%3D%22_blank%22%20rel%3D%22noreferrer%20noopener%20nofollow%22%3ECourse%20%E2%80%93%20Basics%20of%20KQL%3C%2FA%3E%3C%2FU%3E%3C%2FLI%3E%0A%3CLI%3E%3CU%3E%3CA%20tabindex%3D%22-1%22%20title%3D%22http%3A%2F%2Faka.ms%2Fnkwe%22%20href%3D%22http%3A%2F%2Faka.ms%2Fnkwe%22%20target%3D%22_blank%22%20rel%3D%22noreferrer%20noopener%22%3EQuery%20explorer%3C%2FA%3E%3C%2FU%3E%3C%2FLI%3E%0A%3CLI%3E%3CU%3E%3CA%20tabindex%3D%22-1%22%20title%3D%22http%3A%2F%2Faka.ms%2Fazureportal%22%20href%3D%22http%3A%2F%2Faka.ms%2Fazureportal%22%20target%3D%22_blank%22%20rel%3D%22noreferrer%20noopener%22%3EAzure%20Portal%3C%2FA%3E%3C%2FU%3E%3C%2FLI%3E%0A%3CLI%3E%3CU%3E%3CA%20tabindex%3D%22-1%22%20title%3D%22https%3A%2F%2Femea01.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253a%252f%252ffeedback.azure.com%252fforums%252f915733-azure-data-explorer%26amp%3Bdata%3D02%257c01%257ctzgitlin%2540microsoft.com%257c33b94d34a7284713b30108d68cecb3ce%257c72f988bf86f141af91ab2d7cd011db47%257c1%257c0%257c636851345592959411%26amp%3Bsdata%3Dwrs2tfgokomhqyigu6dsruy93jdtzduzur6xxw7e0so%253d%26amp%3Breserved%3D0%22%20href%3D%22https%3A%2F%2Femea01.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253A%252F%252Ffeedback.azure.com%252Fforums%252F915733-azure-data-explorer%26amp%3Bdata%3D02%257C01%257Ctzgitlin%2540microsoft.com%257C33b94d34a7284713b30108d68cecb3ce%257C72f988bf86f141af91ab2d7cd011db47%257C1%257C0%257C636851345592959411%26amp%3Bsdata%3DWRs2tFgokomhQyIgu6dsRuy93JDtzDuzur6xXw7e0so%253D%26amp%3Breserved%3D0%22%20target%3D%22_blank%22%20rel%3D%22noreferrer%20noopener%20nofollow%22%3EUser%20Voice%3C%2FA%3E%3C%2FU%3E%3C%2FLI%3E%0A%3CLI%3E%3CU%3E%3CA%20tabindex%3D%22-1%22%20title%3D%22http%3A%2F%2Faka.ms%2Fadx.cost%22%20href%3D%22http%3A%2F%2Faka.ms%2Fadx.cost%22%20target%3D%22_blank%22%20rel%3D%22noreferrer%20noopener%22%3ECost%20Estimator%3C%2FA%3E%3C%2FU%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSPAN%3EJoin%20us%20to%20share%20questions%2C%20thoughts%2C%20or%20ideas%20about%20Azure%20Data%20Explorer%20(Kusto)%20and%20receive%20answers%20from%20the%20diverse%20and%20knowledgeable%20Azure%20Data%20Explorer%20community.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAzure%20Data%20Explorer%20product%20team%3C%2FP%3E%0A%3CP%3E%3CI%3E%3CSPAN%3E%E2%80%9CJoin%20the%20conversation%20on%20the%26nbsp%3B%5B%23%24dp46%5DAzure%20Data%20Explorer%20community%E2%80%9D.%3C%2FSPAN%3E%3C%2FI%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-849028%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20style%3D%22color%3A%20black%3B%22%3EAzure%20Data%20Explorer%20is%20an%20append%20only%20database%20that%20isn%E2%80%99t%20designed%20to%20support%20frequent%20data%20deletion.%20If%20you%20%3CU%3E%3CSPAN%20style%3D%22color%3A%20black%3B%22%3E%3CSTRONG%3E%3CU%3Eaccidentally%3C%2FU%3E%3C%2FSTRONG%3E%3CU%3E%20%3C%2FU%3E%3C%2FSPAN%3E%3C%2FU%3Eingest%20your%20data%20into%20Azure%20Data%20Explorer%20multiple%20times%2C%20the%20following%20tips%20can%20help%20you%20handle%20the%20duplicate%20records%3A%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E
Version history
Last update:
‎Aug 13 2020 09:12 AM
Updated by: