Apache Iceberg Go
repository·main·Indexed 19 days ago
https://github.com/apache/iceberg-goA Golang implementation of the Apache Iceberg table specification. It provides programmatic interfaces and a CLI to interact with Iceberg tables, supporting multiple catalogs (REST, Hive, Glue, SQL, Hadoop) and filesystems (S3, GCS, Azure Blob Storage, Local). Key capabilities include metadata operations, write operations (append, rewrite, overwrite), and management of namespaces, tables, branches, and tags.
What's inside iceberg-go
- Apache Iceberg Go is a Go-native implementation of the Apache Iceberg open table format. It allows developers to read and write Iceberg tables directly from Go services and tooling without requiring a JVM. This makes it suitable for lightweight microservices, CLI tools, and other Go-based data engineering pipelines.
Choosing an Iceberg implementation
mainApache Iceberg has multiple official implementations across different languages. While the table format and catalog protocols are identical across all implementations, you should choose the one that matches your runtime environment. All implementations target the same core Iceberg specification.
| Project | Language | Repository | Documentation | |---|---|---|---| | Apache Iceberg | Java (reference) | [apache/iceberg](https://github.com/apache/iceberg) | [iceberg.apache.org](https://iceberg.apache.org/) | | PyIceberg | Python | [apache/iceberg-python](https://github.com/apache/iceberg-python) | [py.iceberg.apache.org](https://py.iceberg.apache.org/) | | iceberg-rust | Rust | [apache/iceberg-rust](https://github.com/apache/iceberg-rust) | [rust.iceberg.apache.org](https://rust.iceberg.apache.org/) | | iceberg-cpp | C++ | [apache/iceberg-cpp](https://github.com/apache/iceberg-cpp) | [cpp.iceberg.apache.org](https://cpp.iceberg.apache.org/) (early stage) |Understand Partitioning and Partition Transforms
mainPartitioning logically divides table data to improve query performance via selective reading.
Partitioning Terms
- Partition: A logical division based on column values.
- Partition Spec: Defines how data is partitioned using source columns and transformations.
- Partition Field: A field in the spec defining how a source column is transformed.
- Partition Path: The file system path structure (e.g.,
partition_name=value/).
Partition Transforms
Transform Description identityUse the column value directly bucket[n]Hash the value into n buckets truncate[n]Truncate strings to n characters yearExtract year from date/timestamp monthExtract month from date/timestamp dayExtract day from date/timestamp hourExtract hour from timestamp voidAlways returns null (for unpartitioned tables) Comparison of Iceberg implementations by use case
mainSelect an implementation based on your primary language and ecosystem:
- Java (Reference): The canonical choice for JVM workloads and query engines like Spark, Flink, Trino, Hive, Presto, and Dremio.
- PyIceberg (Python): Best for data science and ML workflows involving the Python dataframe ecosystem (PyArrow, Pandas, Polars, DuckDB, Daft, Ray).
- iceberg-rust (Rust): Used by
pyiceberg-core, DataFusion-based engines, and other Rust-native systems. - iceberg-cpp (C++): An early-stage implementation for native C++ integration.
- iceberg-go (Go): Ideal for Go services and streaming Apache Arrow record batches.
Define column references with Terms
mainA term represents the left-hand side of a predicate.
- Unbound Terms: Use
iceberg.Reference("column_name")to name a column. This is the standard way to build expressions; typing is resolved later during the binding phase against a schema. - Bound Terms: These are resolved forms produced by calling
Reference.Bind(schema, caseSensitive). You typically only interact with these when writing custom expression visitors.
// Create an unbound term (most common use case) term := iceberg.Reference("column_name")- Unbound Terms: Use
Understand Schema Evolution and Time Travel
mainSchema Evolution
Iceberg allows modifying a table's schema over time while maintaining backward compatibility:
- Column Addition: Adding new (typically optional) columns.
- Column Deletion: Removing columns (logically or physically).
- Column Renaming: Changing names while preserving data/type info.
- Type Evolution: Changing types in compatible ways (e.g.,
int32toint64).
Time Travel
- Time Travel: Querying a table as it existed at a specific point in time using snapshot timestamps.
- Snapshot Isolation: Ensuring queries see a consistent view of data from a specific snapshot.
Understand Iceberg Core Concepts
mainThe Iceberg ecosystem relies on several key abstractions to manage data and metadata:
- Catalog: A centralized service (e.g., Hive metastore, AWS Glue, REST API, or SQL) that manages table metadata and provides a unified interface for accessing tables.
- Table: A collection of data files organized by a Schema, supporting ACID transactions and schema evolution.
- Snapshot: A point-in-time view of a table's data representing the state after an operation (append, overwrite, etc.).
- Manifest: A metadata file listing data files and their metadata (location, partition info, etc.).
- Manifest List: A file containing references to manifest files for a specific snapshot, used for efficient data discovery.
Use constants for dynamic filter composition
mainWhen building filters dynamically (e.g., in a loop or conditional logic), use
iceberg.AlwaysTrue{}andiceberg.AlwaysFalse{}as identity elements.- Use
AlwaysTrue{}as the starting point when folding multiple clauses withNewAnd. - Use
AlwaysFalse{}as the starting point when folding multiple clauses withNewOr.
iceberg.AlwaysTrue{} iceberg.AlwaysFalse{}- Use
Iceberg Go Spec Format Version Coverage
mainApache Iceberg Go supports table format versions 1, 2, and 3. The maximum supported version is enforced in
table/metadata.go(supportedTableFormatVersion = 3).V1
All V1 features are supported. V1 serves as the baseline format version.
V2
Supported features include:
- Sequence numbers
- Manifest entry status (added / existing / deleted)
- Positional deletes (read + write)
- Equality deletes (read + write). Write via
Transaction.WriteEqualityDeletes; row-level commits viaTransaction.NewRowDelta. - Partition spec evolution
- Sort order enforcement on write
Note:
ReplaceDataFilesusingOpReplaceis currently pending.V3
Supported features include:
- Nanosecond timestamps (
timestamp_ns,timestamptz_ns) - Default values (
initial-default,write-default) - Row lineage (
_row_id,_last_updated_sequence_number) - Encryption keys in metadata
- Variant type, non-shredded
- Deletion vectors (read, and unpartitioned write)
- Geometry / Geography types (schema)
Note: Variant type shredded reader/writer, partitioned deletion vector writes, and Geometry/Geography transforms/statistics/pruning are currently in progress.
Configure Concurrency settings
mainConcurrency can be controlled globally via the CLI config, or overridden per-operation in code:
- Global: Set
max-workersin~/.iceberg-go.yaml(Default:5). - Per-Scan: Use
table.WithMaxConcurrency(n int). - Per-Write: Use
WithMaxWriteWorkers(n int)onWriteRecordsmethods. - Single-threaded: Use
WithClusteredWrite()to force single-threaded writes (mutually exclusive withWithMaxWriteWorkers).
- Global: Set
Understand Iceberg Table Operations
mainCommon operations used to modify table state and create new snapshots:
- Append: Adds new data files without removing existing ones.
- Overwrite: Replaces existing data files with new ones, typically based on a partition predicate.
- Delete: Removes data files by marking them as deleted or removing references.
- Replace: Replaces all data in a table, typically for full refreshes.
How LocationProviders work
mainThe
LocationProviderdetermines how file paths are generated for tables. Currently, there are two implementations:simpleLocationProvider: The default implementation.objectStoreLocationProvider: Used for hashed object-storage layouts. This is automatically selected when the table propertywrite.object-storage.enabledis set totrue.
Note: The
LocationProvideris not currently user-pluggable; it is selected based on table properties.