1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
//! Actions are the fundamental unit of work in Delta Lake. Each action performs a single atomic
//! operation on the state of a Delta table. Actions are stored in the `_delta_log` directory of a
//! Delta table in JSON format. The log is a time series of actions that represent all the changes
//! made to a table.
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
pub(crate) mod actions;
pub(crate) mod fields;
mod schema;
pub use actions::*;
pub use schema::*;
#[derive(Debug)]
/// The type of action that was performed on the table
pub enum ActionType {
/// modify the data in a table by adding individual logical files
Add,
/// add a file containing only the data that was changed as part of the transaction
Cdc,
/// additional provenance information about what higher-level operation was being performed
CommitInfo,
/// contains a configuration (string-string map) for a named metadata domain
DomainMetadata,
/// changes the current metadata of the table
Metadata,
/// increase the version of the Delta protocol that is required to read or write a given table
Protocol,
/// modify the data in a table by removing individual logical files
Remove,
/// Transactional information
Txn,
/// Checkpoint metadata
CheckpointMetadata,
/// Sidecar
Sidecar,
}
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[allow(missing_docs)]
pub enum Action {
#[serde(rename = "metaData")]
Metadata(Metadata),
Protocol(Protocol),
Add(Add),
Remove(Remove),
Cdc(AddCDCFile),
Txn(Txn),
CommitInfo(CommitInfo),
DomainMetadata(DomainMetadata),
}
impl Action {
/// Create a commit info from a map
pub fn commit_info(info: HashMap<String, serde_json::Value>) -> Self {
Self::CommitInfo(CommitInfo {
info,
..Default::default()
})
}
}
impl From<Add> for Action {
fn from(a: Add) -> Self {
Self::Add(a)
}
}
impl From<Remove> for Action {
fn from(a: Remove) -> Self {
Self::Remove(a)
}
}
impl From<AddCDCFile> for Action {
fn from(a: AddCDCFile) -> Self {
Self::Cdc(a)
}
}
impl From<Metadata> for Action {
fn from(a: Metadata) -> Self {
Self::Metadata(a)
}
}
impl From<Protocol> for Action {
fn from(a: Protocol) -> Self {
Self::Protocol(a)
}
}
impl From<Txn> for Action {
fn from(a: Txn) -> Self {
Self::Txn(a)
}
}
impl From<CommitInfo> for Action {
fn from(a: CommitInfo) -> Self {
Self::CommitInfo(a)
}
}
impl From<DomainMetadata> for Action {
fn from(a: DomainMetadata) -> Self {
Self::DomainMetadata(a)
}
}
impl Action {
/// Get the action type
pub fn action_type(&self) -> ActionType {
match self {
Self::Add(_) => ActionType::Add,
Self::Remove(_) => ActionType::Remove,
Self::Cdc(_) => ActionType::Cdc,
Self::Metadata(_) => ActionType::Metadata,
Self::Protocol(_) => ActionType::Protocol,
Self::Txn(_) => ActionType::Txn,
Self::CommitInfo(_) => ActionType::CommitInfo,
Self::DomainMetadata(_) => ActionType::DomainMetadata,
}
}
}