class IcebergTable
A table in a catalog discovered or registered by the application. Tracks the table’s health, maintenance schedules, and executions.
Constants
- HEALTH_STATUSES
- RootTableNotAddressable
-
Raised when a SQL identifier is requested for a table Trino cannot name.
Two causes, both structural rather than transient: * the table is at the catalog root, so there is no schema to address - Trino’s identifier is catalog.schema.table with no two-part form; * the table is in a NESTED namespace on a native-Nessie catalog, whose connector passes the schema as one namespace level and never splits on the dot, so no SQL syntax reaches it.
Kept under the original name so existing rescues keep working.
Public Instance Methods
Source
# File app/models/iceberg_table.rb, line 181 def addressable_in_trino? unaddressable_reason.nil? end
Whether this table can be named in a Trino statement at all.
Callers that need to know BEFORE acting - the UI, plan creation - should ask this rather than rescuing an exception.
@return [Boolean]
Source
# File app/models/iceberg_table.rb, line 120 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 size of the table’s data files, or nil when the stats are unknown. @return [Integer, nil]
# File app/models/iceberg_table.rb, line 41 def deactivate!(at: Time.current) update!(active: false, deactivated_at: at) end
Marks the table as inactive after being dropped from its catalog, keeping its history and configuration recorded.
Source
# File app/models/iceberg_table.rb, line 114 def fully_qualified_name [ catalog&.trino_catalog_name, namespace.presence, name ].compact.join(".") end
The three-part identifier: catalog.namespace.table.
Uses trino_catalog_name rather than the catalog’s display name, because trino_catalog_name_override means the two can differ and only the former resolves in Trino - the value is presented as an identifier, so it should be the resolvable one.
A table at the repository root has a blank namespace and renders as catalog.table, without the empty middle part that a plain join produces.
Display only. trino_identifier / trino_metadata_table build their own quoted identifiers for SQL and never call this.
@return [String]
# File app/models/iceberg_table.rb, line 62 def health_attributes(health, at: Time.current) return { health_components: serialize_health_components(health), health_evaluated_at: at } if health[:score].nil? attributes = { health_score: health[:score], health_status: health[:status].to_s, health_components: serialize_health_components(health), health_evaluated_at: at } # Only stamp when the state actually CHANGES. Stamping on every sync would # reset the clock and make "broke most recently" ordering just sync order. attributes[:health_status_changed_at] = at if attributes[:health_status] != health_status attributes end
The attributes that persist a HealthEvaluator result.
ONE writer shape for every caller, so the score, the status label and the component breakdown are always written together from a single evaluation. Recomputing on read is what let the list and the detail page disagree on both the score and the label (see #215); persisting the breakdown lets the detail page render by reading, so a divergence cannot arise.
An unscoreable table still records that it WAS evaluated: the breakdown and the timestamp are written while the score and label are left untouched. Without that, health_components stayed blank and the detail page treated the table as never-evaluated and re-evaluated it on every single render - the very thing this exists to prevent.
@param health [Hash] a HealthEvaluator.evaluate result @param at [Time] the evaluation clock @return [Hash] attributes to assign
Source
# File app/models/iceberg_table.rb, line 129 def metadata_snapshot { "total_records" => total_records, "total_data_files" => total_data_files, "total_size_bytes" => total_size_bytes, "position_deletes" => position_deletes, "equality_deletes" => equality_deletes, "snapshot_count" => snapshot_count, "manifest_count" => manifest_count, "oldest_snapshot_at" => oldest_snapshot_at&.iso8601 } end
Snapshot of key metadata fields for before/after comparison. Only includes fields that maintenance operations actually move. @return [Hash] the metadata snapshot
Source
# File app/models/iceberg_table.rb, line 214 def nested_namespace? = namespace.to_s.include?(".")
Whether the namespace has more than one level. @return [Boolean]
# File app/models/iceberg_table.rb, line 81 def persisted_health_evaluation return nil if health_components.blank? stored = health_components components = (stored["components"] || {}).transform_keys(&:to_sym) { score: health_score, # An unscoreable table keeps whatever label it last had, but the panel # must render :unknown rather than a stale badge with no score behind it. status: health_score.nil? ? :unknown : health_status.to_sym, components: components, coverage: stored["coverage"], worst_component: stored["worst_component"]&.to_sym, worst_ratio: stored["worst_ratio"], details: (stored["details"] || {}).transform_keys(&:to_sym), evaluated_at: health_evaluated_at } end
The persisted breakdown, in the shape HealthEvaluator.evaluate returns, so the view renders a read and a fresh evaluation identically.
@return [Hash, nil] the evaluation shape, or nil when nothing is persisted
Source
# File app/models/iceberg_table.rb, line 157 def trino_identifier ensure_addressable! [ catalog.trino_catalog_name, namespace, name ].map { |part| quote_identifier(part) }.join(".") end
Trino SQL identifier, always exactly three parts: catalog.schema.table.
A dotted namespace stays inside ONE quoted part. Trino’s identifier model is strictly three levels, and the Iceberg connector represents a nested namespace as a single dotted schema name, splitting it internally on its separator. Emitting “cat”.“a”.“b”.“tbl” would be a four-part reference the grammar does not accept - it must not be “corrected” into one (see #227). “catalog”.“ns1.ns2.ns3”.“table”
A table at the repository root has no schema to address, so there is no valid three-part identifier for it: an empty middle part (“cat”.“”.“tbl”) names a schema that cannot exist. Raise rather than emit SQL that fails later with an opaque resolution error.
@raise [RootTableNotAddressable] when the table has no namespace
# File app/models/iceberg_table.rb, line 224 def trino_identifier_for_display addressable_in_trino? ? trino_identifier : nil end
The Trino identifier for DISPLAY, or nil when there is none.
Execution paths must keep using trino_identifier and let RootTableNotAddressable propagate - a statement built for an unaddressable table has to fail. A read-only field rendering the same value must not, which is what took the detail page down for every root table.
@return [String, nil]
# File app/models/iceberg_table.rb, line 169 def trino_metadata_table(suffix) ensure_addressable! [ catalog.trino_catalog_name, namespace, "#{name}$#{suffix}" ] .map { |part| quote_identifier(part) }.join(".") end
Trino SQL identifier for an Iceberg metadata table ($files, $manifests, $snapshots, $partitions). The suffix is part of the table name and must be inside the quotes: “catalog”.“ns”.“table$files”
@param suffix [String] the metadata table suffix (e.g. “files”, “manifests”) @return [String] the quoted three-part identifier
Source
# File app/models/iceberg_table.rb, line 205 def unaddressable_reason return :root if namespace.blank? return :nested_native_nessie if nested_namespace? && native_nessie_catalog? nil end
Why Trino cannot name this table, or nil when it can.
Two structural cases:
:root - no namespace at all. Trino’s identifier is catalog.schema.table with no two-part form, so there is no schema to address.
:nested_native_nessie - a nested namespace on a native-Nessie catalog. TrinoNessieCatalog#namespaceExists and IcebergNessieUtil#toIdentifier build Namespace.of with the schema string as a SINGLE element - they never split on the dot - so “a.b” addresses a one-level namespace that does not exist. 3 parts fails at the connector and 4 parts fails at the parser, so no syntax reaches the table. The REST connector does split (TrinoRestCatalog#toNamespace, under nested-namespace-enabled), which is why nesting is fine there and the dotted 3-part identifier stays correct.
@return [Symbol, nil]