class TableMetadataExtractor
Pulls the full Iceberg REST TableMetadata out of a GetTableResponse payload (the metadata object, or a top-level table object).
Distinguishes “no data” (nil) from “zero” - the difference is what keeps the health score from lying.
Public Class Methods
Source
# File app/services/table_metadata_extractor.rb, line 17 def self.from_persisted(table) summary = {} summary["total-records"] = table.total_records if table.total_records summary["total-data-files"] = table.total_data_files if table.total_data_files summary["total-files-size"] = table.total_size_bytes if table.total_size_bytes summary["total-position-deletes"] = table.position_deletes if table.position_deletes summary["total-equality-deletes"] = table.equality_deletes if table.equality_deletes summary["manifest-count"] = table.manifest_count if table.manifest_count snapshots = persisted_snapshots(table, summary) # No current-snapshot-id: the summary is attached to the LAST entry and # #current_snapshot falls back to it. Passing an id (0) made the lookup # match a real snapshot that happened to carry that id, so the rebuilt # summary was never read and every summary metric came back nil. new( "properties" => table.properties_json || {}, "snapshots" => snapshots ) end
Rebuilds an extractor from the metadata already persisted on the table (CR-42 columns), without calling the catalog again. Summary fields come straight from the snapshot the sync chose as current.
Source
# File app/services/table_metadata_extractor.rb, line 10 def initialize(metadata) @metadata = metadata end
Creates an extractor around a TableMetadata hash.
@param metadata [Hash] the raw TableMetadata payload
Public Instance Methods
Source
# File app/services/table_metadata_extractor.rb, line 179 def average_file_size return nil if total_size_bytes.nil? || total_data_files.nil? || total_data_files.zero? total_size_bytes / total_data_files end
Average data-file size in bytes, nil when there are no files.
@return [Integer, nil] the average size
Source
# File app/services/table_metadata_extractor.rb, line 168 def equality_deletes = summary_int("total-equality-deletes")
Total equality-delete count, nil when absent - NOT zero.
@return [Integer, nil] the count
Source
# File app/services/table_metadata_extractor.rb, line 141 def last_snapshot_at = snapshot_time(current_snapshot)
Timestamp of the current (last) snapshot.
@return [Time, nil] the snapshot time
Source
# File app/services/table_metadata_extractor.rb, line 174 def manifest_count = summary_int("manifest-count")
Manifest count, nil when absent - NOT zero. Persisted by the Trino enrichment and carried here so any caller reconstructing state from the database feeds the evaluator the same inputs (see #198).
@return [Integer, nil] the count
Source
# File app/services/table_metadata_extractor.rb, line 145 def oldest_snapshot_at = snapshot_time(snapshots.first)
Timestamp of the oldest snapshot.
@return [Time, nil] the snapshot time
Source
# File app/services/table_metadata_extractor.rb, line 123 def partition_specs = @metadata["partition-specs"] || []
The table’s partition spec list.
@return [Array] the partition specs
Source
# File app/services/table_metadata_extractor.rb, line 164 def position_deletes = summary_int("total-position-deletes")
Total position-delete count, nil when absent - NOT zero.
@return [Integer, nil] the count
Source
# File app/services/table_metadata_extractor.rb, line 115 def properties = @metadata["properties"] || {}
The table’s properties map.
@return [Hash] the properties
Source
# File app/services/table_metadata_extractor.rb, line 127 def refs = @metadata["refs"] || {}
The table’s named refs map.
@return [Hash] the refs
Source
# File app/services/table_metadata_extractor.rb, line 119 def schemas = @metadata["schemas"] || []
The table’s schema list.
@return [Array] the schemas
Source
# File app/services/table_metadata_extractor.rb, line 136 def snapshot_count = snapshots.size
The number of snapshots.
@return [Integer] the snapshot count
Source
# File app/services/table_metadata_extractor.rb, line 132 def snapshots = @metadata["snapshots"] || @metadata["snapshot-list"] || []
The table’s snapshot list.
@return [Array] the snapshots
Source
# File app/services/table_metadata_extractor.rb, line 111 def storage_location = @metadata["location"]
The table’s storage location.
@return [String, nil] the location
Source
# File app/services/table_metadata_extractor.rb, line 107 def table_uuid = @metadata["table-uuid"]
The table’s UUID.
@return [String, nil] the table-uuid
Source
# File app/services/table_metadata_extractor.rb, line 152 def total_data_files = summary_int("total-data-files")
Total data-file count, nil when absent - NOT zero.
@return [Integer, nil] the count
Source
# File app/services/table_metadata_extractor.rb, line 148 def total_records = summary_int("total-records")
nil when the summary does not carry the field - NOT zero.
Source
# File app/services/table_metadata_extractor.rb, line 160 def total_size_bytes = summary_int("total-files-size")
Total size of data files in bytes, nil when absent - NOT zero.
Iceberg writes this key as total-files-size (bytes), not the total-files-size-in-bytes spelling this code historically read — the wrong key made size and average_file_size nil after every catalog sync.
@return [Integer, nil] the size