Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Si applica a:
Databricks SQL
Databricks Runtime
Restituisce un log delle modifiche apportate a una tabella Delta Lake con flusso di dati delle modifiche abilitato.
Per richiamare questa funzione è necessario avere almeno uno dei seguenti elementi:
-
SELECTprivilegio sulla tabella specificata - Diventa il proprietario della tabella
- Disporre di privilegi amministrativi
Sintassi
table_changes ( table_str, start [, end ] )
Argomenti
table_str: valore letterale STRING che rappresenta il nome facoltativamente qualificato della tabella.start: valore letterale BIGINT o TIMESTAMP che rappresenta la prima versione o il timestamp della modifica da restituire.La funzione restituisce un errore se
startè:- Una versione precedente alla versione più antica disponibile della tabella.
- Una versione successiva all'ultima versione della tabella.
- Un timestamp successivo rispetto all'ultimo timestamp del commit.
end: Un valore letterale BIGINT o TIMESTAMP facoltativo, che rappresenta l'ultima versione o il timestamp della modifica da restituire. Se non specificato, tutte le modifiche finostartalla modifica corrente vengono restituite.La funzione restituisce un errore se
endè:- Una versione successiva all'ultima versione della tabella, o un timestamp successivo all'ultimo timestamp del commit.
- Una versione precedente alla versione più antica disponibile della tabella, o un timestamp precedente al timestamp di commit più antico disponibile.
Per restituire tutte le modifiche fino
startall'ultima versione, omettiend.
Valori restituiti
Tabella che include tutte le colonne della tabella identificate in table_str, oltre alle colonne seguenti:
_change_type STRING NOT NULLSpecifica la modifica:
delete,insert,update_preimageoupdate_postimage_commit_version BIGINT NOT NULLSpecifica la versione commit della tabella associata alla modifica.
_commit_timestamp TIMESTAMP NOT NULLSpecifica il timestamp di commit associato alla modifica.
Se table_str non rappresenta un nome di tabella qualificato, il nome è qualificato con il valore di current_schema.
Se il nome della tabella contiene spazi o punti, usare le virgolette all'interno della stringa per citare tale parte del nome.
Esempi
-- Create a Delta table with Change Data Feed;
> CREATE TABLE myschema.t(c1 INT, c2 STRING) TBLPROPERTIES(delta.enableChangeDataFeed=true);
-- Modify the table
> INSERT INTO myschema.t VALUES (1, 'Hello'), (2, 'World');
> INSERT INTO myschema.t VALUES (3, '!');
> UPDATE myschema.t SET c2 = upper(c2) WHERE c1 < 3;
> DELETE FROM myschema.t WHERE c1 = 3;
-- Show the history of table change events
> DESCRIBE HISTORY myschema.t;
version timestamp userId userName operation operationParameters ...
4 2022-09-01T18:32:35.000+0000 6167625779053302 alf@melmak.et DELETE {"predicate":"[\"(spark_catalog.myschema.t.c1 = 3)\"]"}
3 2022-09-01T18:32:32.000+0000 6167625779053302 alf@melmak.et UPDATE {"predicate":"(c1#3195878 < 3)"}
2 2022-09-01T18:32:28.000+0000 6167625779053302 alf@melmak.et WRITE {"mode":"Append","partitionBy":"[]"}
1 2022-09-01T18:32:26.000+0000 6167625779053302 alf@melmak.et WRITE {"mode":"Append","partitionBy":"[]"}
0 2022-09-01T18:32:23.000+0000 6167625779053302 alf@melmak.et CREATE TABLE {"isManaged":"true","description":null,"partitionBy":"[]","properties":"{\"delta.enableChangeDataFeed\":\"true\"}"}
-- Show the change table feed using a the commit timestamp retrieved from the history.
> SELECT * FROM table_changes('`myschema`.`t`', 2);
c1 c2 _change_type _commit_version _commit_timestamp
3 ! insert 2 2022-09-01T18:32:28.000+0000
2 WORLD update_postimage 3 2022-09-01T18:32:32.000+0000
2 World update_preimage 3 2022-09-01T18:32:32.000+0000
1 Hello update_preimage 3 2022-09-01T18:32:32.000+0000
1 HELLO update_postimage 3 2022-09-01T18:32:32.000+0000
3 ! delete 4 2022-09-01T18:32:35.000+0000
-- Show the ame change table feed using a point in time.
> SELECT * FROM table_changes('`myschema`.`t`', '2022-09-01T18:32:27.000+0000') ORDER BY _commit_version;
c1 c2 _change_type _commit_version _commit_timestamp
3 ! insert 2 2022-09-01T18:32:28.000+0000
2 WORLD update_postimage 3 2022-09-01T18:32:32.000+0000
2 World update_preimage 3 2022-09-01T18:32:32.000+0000
1 Hello update_preimage 3 2022-09-01T18:32:32.000+0000
1 HELLO update_postimage 3 2022-09-01T18:32:32.000+0000
3 ! delete 4 2022-09-01T18:32:35.000+0000