Skip to main content

deltalake_core/kernel/models/
mod.rs

1//! Actions are the fundamental unit of work in Delta Lake. Each action performs a single atomic
2//! operation on the state of a Delta table. Actions are stored in the `_delta_log` directory of a
3//! Delta table in JSON format. The log is a time series of actions that represent all the changes
4//! made to a table.
5
6use std::collections::HashMap;
7
8use serde::{Deserialize, Serialize};
9
10pub(crate) mod actions;
11pub(crate) mod fields;
12
13pub use actions::*;
14
15#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
16#[serde(rename_all = "camelCase")]
17#[allow(missing_docs)]
18pub enum Action {
19    #[serde(rename = "metaData")]
20    Metadata(Metadata),
21    Protocol(Protocol),
22    Add(Add),
23    Remove(Remove),
24    Cdc(AddCDCFile),
25    Txn(Transaction),
26    CommitInfo(CommitInfo),
27    DomainMetadata(DomainMetadata),
28}
29
30impl Action {
31    /// Create a commit info from a map
32    pub fn commit_info(info: HashMap<String, serde_json::Value>) -> Self {
33        Self::CommitInfo(CommitInfo {
34            info,
35            ..Default::default()
36        })
37    }
38}
39
40impl From<Add> for Action {
41    fn from(a: Add) -> Self {
42        Self::Add(a)
43    }
44}
45
46impl From<Remove> for Action {
47    fn from(a: Remove) -> Self {
48        Self::Remove(a)
49    }
50}
51
52impl From<AddCDCFile> for Action {
53    fn from(a: AddCDCFile) -> Self {
54        Self::Cdc(a)
55    }
56}
57
58impl From<Metadata> for Action {
59    fn from(a: Metadata) -> Self {
60        Self::Metadata(a)
61    }
62}
63
64impl From<Protocol> for Action {
65    fn from(a: Protocol) -> Self {
66        Self::Protocol(a)
67    }
68}
69
70impl From<Transaction> for Action {
71    fn from(a: Transaction) -> Self {
72        Self::Txn(a)
73    }
74}
75
76impl From<CommitInfo> for Action {
77    fn from(a: CommitInfo) -> Self {
78        Self::CommitInfo(a)
79    }
80}
81
82impl From<DomainMetadata> for Action {
83    fn from(a: DomainMetadata) -> Self {
84        Self::DomainMetadata(a)
85    }
86}