Gebruik automatische liquid clustering

Met automatische liquid clustering kiest Azure Databricks clusteringsleutels die de queryprestaties optimaliseren. Gebruik de CLUSTER BY AUTO clausule om het in te schakelen.

Voor een overzicht van liquid clustering, inclusief handmatig opgegeven clusteringssleutels, zie Gebruik liquid clustering voor tabellen.

Note

Automatische vloeistofclustering wordt ook ondersteund voor gerealiseerde weergaven en streamingtabellen, waaronder Lakeflow-pijplijnen en zelfstandige pijplijnen. Geef CLUSTER BY AUTO in uw pijplijn of SQL-definitie op.

Requirements

Automatische vloeistofclustering heeft de volgende vereisten:

  • Voor Unity Catalog beheerde Delta Lake-tabellen is Databricks Runtime 15.4 LTS en hoger vereist.
  • Voor Unity Catalog beheerde Apache Iceberg v3-tabellen is Databricks Runtime 18 LTS en hoger vereist.
  • Voorspellende optimalisatie moet ingeschakeld zijn. Zie Voorspellende optimalisatie voor beheerde tabellen in Unity Catalog.

Hoe automatische vloeistofclustering werkt

Automatische vloeistofclustering maakt gebruik van voorspellende optimalisatie voor automatische sleutelselectie en clusteringoperaties en draait asynchroon.

Automatische vloeistofclustering past zich aan aan je gebruikspatronen:

  • Analyseert query-workload: Azure Databricks analyseert de historische query-workload van de tabel en identificeert de beste geschikte kolommen voor clustering.
  • Past zich aan veranderingen: Als uw querypatronen of dataverdelingen in de loop van de tijd veranderen, selecteert automatische liquid clustering nieuwe sleutels om de prestaties te optimaliseren.
  • Kostenbewuste selectie: Azure Databricks wijzigt clusteringsleutels alleen wanneer de voorspelde kostenbesparingen door data-overspringverbeteringen opwegen tegen de kosten van dataclustering.

Automatische groepering van vloeistoffen kan om de volgende redenen niet in staat zijn om sleutels te selecteren:

  • De tabel is te klein om te profiteren van vloeistofclustering.
  • De tabel heeft al een effectief clusteringschema, ofwel uit eerdere handmatige sleutels of natuurlijke invoegvolgorde die overeenkomt met querypatronen.
  • De tabel heeft geen frequente query's.
  • U gebruikt Databricks Runtime 15.4 LTS of hoger niet.

Tip

Om te zien waarom voorspellende optimalisatie clusteringsleutelkeuze voor een specifieke tabel oversloeg, kijk dan in het tabblad Geschiedenis in Catalog Explorer. Om de reden voor overslaan te bekijken, klik je op de AUTO LIQUID rij met het label Niet toegepast in de kolom Operatie . Zie Gebruik het tabblad geschiedenis in Catalogusverkenner.

U kunt automatische liquide clustering toepassen voor alle beheerde Unity Catalog-tabellen, ongeacht de gegevens- en querykenmerken. Voorspellende optimalisatie beslist of het kiezen van clusteringsleutels kostenvoordelig is.

Sleutels selecteren en op aanvraag optimaliseren

Important

Deze functie bevindt zich in de bètaversie. Om het te gebruiken moet een werkruimtebeheerder OPTIMIZE EXTENDED inschakelen op de Previews-pagina. Zie Azure Databricks previews beheren.

Gebruik OPTIMIZE table_name EXTENDED om clusteringsleutels te selecteren en een tabel op aanvraag te clusteren voor een proof of concept of benchmark, of om een gewijzigde workload opnieuw te beoordelen. Voer eerst representatieve query's uit. Zie Tabelindeling optimaliseren met OPTIMIZE EXTENDED voor de walkthrough en voorbeelduitvoer.

Compatibiliteit van Databricks Runtime-versies

U kunt tabellen lezen of schrijven waarvoor automatische clustering is ingeschakeld vanuit alle Databricks Runtime-versies die ondersteuning bieden voor liquide clustering. Automatische sleutelselectie is gebaseerd op metadata die is geïntroduceerd in Databricks Runtime 15.4 LTS. Voor de Databricks Runtime-versies die tabellen met liquid clustering kunnen lezen en schrijven, zie Compatibiliteit voor tabellen met liquid clustering.

Gebruik Databricks Runtime 15.4 LTS of hoger om ervoor te zorgen dat automatisch geselecteerde sleutels profiteren van al uw workloads en dat deze workloads worden overwogen bij het selecteren van nieuwe sleutels.

Automatische vloeistofclustering in- of uitschakelen

Gebruik SQL of de Python API om automatische vloeibare clustering in te schakelen op een nieuwe of bestaande tabel, stel de initiële clustering-sleutelhints in of schakel deze uit.

SQL

Een tabel maken met automatische vloeistofclustering:

CREATE OR REPLACE TABLE table1 (column01 int, column02 string) CLUSTER BY AUTO;

Automatische liquide clustering inschakelen voor een bestaande tabel, inclusief tabellen met handmatig opgegeven sleutels:

ALTER TABLE table1 CLUSTER BY AUTO;

Als u initiële tips voor clusteringkolommen voor het selecteren van sleutels wilt instellen, stelt u de clusteringsleutels in en schakelt u vervolgens automatische clustering in:

ALTER TABLE table1 CLUSTER BY (column01, column02);
ALTER TABLE table1 CLUSTER BY AUTO;

U kunt ook de Python-API gebruiken om hints in één bewerking in te stellen.

Om het automatisch clusteren van vloeistoffen uit te schakelen:

ALTER TABLE table1 CLUSTER BY NONE;

Automatische vloeistofclustering uitschakelen en clusteringkolommen opgeven:

ALTER TABLE table1 CLUSTER BY (column01, column02);

Als voor een bestaande tabel automatische liquid clustering is ingeschakeld, wordt automatische clustering uitgeschakeld wanneer CREATE OR REPLACE table_name zonder CLUSTER BY AUTO wordt uitgevoerd, en blijven de clusteringkolommen niet behouden. Als u automatische vloeistofclustering en eerder geselecteerde kolommen wilt behouden, neemt u CLUSTER BY AUTO op in de replace-instructie. Voorspellende CLUSTER BY AUTOoptimalisatie maakt gebruik van de historische queryworkload voor de tabel om de beste clusteringsleutels te identificeren.

Python

De Python API is beschikbaar in Databricks Runtime 16.4 LTS en hoger. Gebruik SQL om automatische clustering te wijzigen zonder de gegevens van de tabel te herschrijven.

Een tabel met automatische vloeistofclustering maken met behulp van DataFrameWriter:

df = spark.read.table("table1")
(df.write
  .format("delta")
  .option("clusterByAuto", "true")
  .saveAsTable("target_table")
)

Initiële clusteringkolomhints instellen voor sleutelselectie met behulp van DataFrameWriter:

(df.write
  .format("delta")
  .clusterBy("clusteringColumn1", "clusteringColumn2")
  .option("clusterByAuto", "true")
  .saveAsTable("target_table")
)

Een tabel met automatische vloeistofclustering maken met behulp van DataFrameWriterV2:

(df.writeTo("target_table")
  .using("delta")
  .option("clusterByAuto", "true")
  .create()
)

Initiële clusteringkolomhints instellen voor sleutelselectie met behulp van DataFrameWriterV2:

(df.writeTo("target_table")
  .using("delta")
  .clusterBy("clusteringColumn1", "clusteringColumn2")
  .option("clusterByAuto", "true")
  .create()
)

Om automatische vloeibare clustering in te schakelen op een bestaande Delta Lake-tabel met DataFrameWriter, of om deze te behouden wanneer u een tabel overschrijft die deze al gebruikt, overschrijft u de gehele tabel met saveAsTable() met overwriteSchema en clusterByAuto stelt u in op true:

df = spark.read.table("source_table")
(df.write
  .format("delta")
  .mode("overwrite")
  .option("overwriteSchema", "true")
  .option("clusterByAuto", "true")
  .saveAsTable("target_table"))

Met saveAsTable() schakelt een volledige tabeloverschrijving waarbij true is ingesteld op clusterByAuto automatische clustering uit en worden de sleutels gewist als je zowel .clusterBy() als overwriteSchema weglaat.

Met DataFrameWriterV2, om automatische clustering op een bestaande Delta Lake-tabel mogelijk te maken, stel clusterByAuto in op true en roep createOrReplace() of replace() aan.

Een streamingtabel maken met automatische liquid clustering:

(spark.readStream.table("source_table")
  .writeStream
  .option("clusterByAuto", "true")
  .option("checkpointLocation", checkpointPath)
  .toTable("target_table")
)

Initiële clusteringkolomhints instellen voor sleutelselectie in een streamingtabel:

(spark.readStream.table("source_table")
  .writeStream
  .clusterBy("column1", "column2")
  .option("clusterByAuto", "true")
  .option("checkpointLocation", checkpointPath)
  .toTable("target_table")
)

Wanneer u .clusterBy gebruikt voor selectiehints voor clustersleutels in combinatie met .option('clusterByAuto', 'true'), is het gedrag als volgt:

  • Als hiermee automatische vloeistofclustering voor het eerst wordt ingesteld, worden de clusterkolommen ingesteld op de opgegeven kolommen in .clusterBy.
  • Als dit een bestaande tabel is met automatische vloeistof clustering ingeschakeld, wordt een .clusterBy hint slechts één keer geaccepteerd. De kolommen die zijn opgegeven door .clusterBy worden alleen ingesteld als de tabel nog geen clusterkolommen heeft.

Important

Voor Delta Lake-tabellen verandert de appendmodus de automatische clustering-instelling niet. Met saveAsTable(), het instellen clusterByAuto op true op een tabel zonder automatische clustering mislukt bij DELTA_CLUSTER_BY_AUTO_MISMATCH in append-modus of bij overschrijven zonder schema-vervanging. Voor overwrites zonder schemavervanging of clusteropties, zie Tabellen maken met clustering.

Gebruik SQL ALTER TABLE om automatische clustering apart van een toevoeging te wijzigen.

Controleren of automatische clustering ingeschakeld is

Om te controleren of een tabel automatische liquid clustering heeft ingeschakeld, gebruikt u DESCRIBE TABLE of SHOW TBLPROPERTIES.

Als automatische vloeistofclustering is ingeschakeld, wordt de clusterByAuto eigenschap ingesteld op true. De clusteringColumns eigenschap toont de huidige clusterkolommen die automatisch of handmatig zijn geselecteerd.

Limitations

Automatische vloeistofclustering is niet beschikbaar voor beheerde Apache Iceberg v2-tabellen. Het wordt ondersteund voor beheerde Apache Iceberg v3-tabellen in Databricks Runtime 18 LTS en hoger.