MoonBit-native Iceberg v2 reading with partition evolution, delete semantics and explainable scan planning.
Dependencies
///|
test "negative timestamps floor to the previous day and strings count code points" {
assert_eq(
@moonice.transform_partition(
@moonice.Integer(-1L),
Json::string("timestamp"),
"day",
),
Some(@moonice.Integer(-1L)),
)
assert_eq(
@moonice.transform_partition(
@moonice.Text("月🌙冰"),
Json::string("string"),
"truncate[2]",
),
Some(@moonice.Text("月🌙")),
)
}///|
test "bind a filter using the current column name" {
let schema : @moonice.Schema = {
id: 1,
fields: [
{
id: 2,
name: "region",
required: false,
field_type: Json::string("string"),
},
],
}
let p = @moonice.parse_predicate(
"{\"field\":\"region\",\"op\":\"=\",\"value\":\"北京\"}", schema,
)
assert_true(p.matches(Map([(2, @moonice.Text("北京"))])))
assert_false(p.matches(Map([(2, @moonice.Missing)])))
}///|
test "renaming preserves field values and new columns null-fill" {
let row : @moonice.DataRow = {
file_path: "memory://table/data.parquet",
position: 0L,
values: Map([(2, @moonice.Text("北京"))]),
}
let schema : @moonice.Schema = {
id: 1,
fields: [
{
id: 2,
name: "region",
required: false,
field_type: Json::string("string"),
},
{
id: 3,
name: "note",
required: false,
field_type: Json::string("string"),
},
],
}
let result = row.project(schema)
assert_eq(result.get("region"), Some(@moonice.Text("北京")))
assert_eq(result.get("note"), Some(@moonice.Missing))
}///|
let metadata = @moonice.parse_metadata(raw_metadata_json)
///|
let state = @moonice.load_snapshot(metadata, path => storage_read(path))
///|
let predicate = @moonice.parse_predicate(filter_json, state.schema)
///|
let plan = @moonice.plan_scan(metadata, state, predicate)
///|
let result = @moonice.scan_rows(metadata, state, predicate, path => {
storage_read(path)
})fn Bundle::scan(self : Bundle, predicate : Predicate, snapshot_id? : Int64, limit? : Int) -> ScanResult raise IceErrorpub(all) struct DataFile {
content : Int
path : String
format : String
partition : Map[String, Scalar]
record_count : Int64
size_bytes : Int64
lower_bounds : Map[Int, Bytes]
upper_bounds : Map[Int, Bytes]
null_counts : Map[Int, Int64]
nan_counts : Map[Int, Int64]
equality_ids : Array[Int]
} derive(Eq, ToJson, Debug)pub(all) struct FileDecision {
entry : ManifestEntry
kept : Bool
reason_code : String
explanation : String
} derive(ToJson, Debug)pub(all) struct SnapshotDiff {
from_id : Int64
to_id : Int64
added : Array[ManifestEntry]
removed : Array[ManifestEntry]
retained_files : Int
added_records : Int64
removed_records : Int64
schema_changes : Array[SchemaChange]
} derive(ToJson, Debug)pub(all) struct TableMetadata {
uuid : String
location : String
current_schema_id : Int
default_spec_id : Int
last_sequence_number : Int64
current_snapshot_id : Int64?
schemas : Array[Schema]
partition_specs : Array[PartitionSpec]
snapshots : Array[Snapshot]
refs : Array[SnapshotRef]
} derive(ToJson, Debug)fn TableMetadata::snapshot(self : TableMetadata, id? : Int64, ref_name? : String) -> Snapshot raise IceErrorfn explain_delete(metadata : TableMetadata, data : ManifestEntry, deletion : ManifestEntry) -> DeleteDecision raise IceErrorfn load_snapshot(metadata : TableMetadata, read_file : (String) -> Bytes raise IceError, snapshot_id? : Int64) -> SnapshotState raise IceErrorfn plan_deletes(metadata : TableMetadata, state : SnapshotState, plan : ScanPlan) -> Array[DeleteDecision] raise IceErrorfn plan_scan(metadata : TableMetadata, state : SnapshotState, predicate : Predicate) -> ScanPlan raise IceErrorfn run_request(bundle_json : String, options_json : String) -> Stringfn scan_batches(metadata : TableMetadata, state : SnapshotState, predicate : Predicate, read_file : (String) -> Bytes raise IceError, emit : (Array[DataRow]) -> Unit raise IceError, batch_size? : Int) -> ScanSummary raise IceErrorfn scan_rows(metadata : TableMetadata, state : SnapshotState, predicate : Predicate, read_file : (String) -> Bytes raise IceError, limit? : Int) -> ScanResult raise IceErrorInstall
Download zipMoonBit-native Iceberg v2 reading with partition evolution, delete semantics and explainable scan planning.
Dependencies