RussellSpitzer commented on code in PR #16961: URL: https://github.com/apache/iceberg/pull/16961#discussion_r3983389689
########## format/index-spec.md: ########## @@ -0,0 +1,730 @@ +--- +title: "Index Spec" +--- +<!-- + - Licensed to the Apache Software Foundation (ASF) under one or more + - contributor license agreements. See the NOTICE file distributed with + - this work for additional information regarding copyright ownership. + - The ASF licenses this file to You under the Apache License, Version 2.0 + - (the "License"); you may not use this file except in compliance with + - the License. You may obtain a copy of the License at + - + - http://www.apache.org/licenses/LICENSE-2.0 + - + - Unless required by applicable law or agreed to in writing, software + - distributed under the License is distributed on an "AS IS" BASIS, + - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + - See the License for the specific language governing permissions and + - limitations under the License. + --> +# Iceberg Index Specification + +## Background and Motivation + +An index is most valuable when it is a property of the table rather than of the engine that built it. This +specification defines a common format for index metadata and a common storage architecture for index data, so that any +engine can build an index, maintain it, and use it to plan queries against the table. + +## Goals + +* **Portability** -- An index written by one engine will be readable by any other engine. +* **Separation** -- Index metadata will be committed separately from table metadata. Building and maintaining an index + will not rewrite the table. +* **Optionality** -- Indexes will be optional. Engines may ignore an index they do not support. +* **Consistency** -- Each index snapshot will index exactly the live rows of one source table snapshot. + +## Overview + +An index is recorded in an index metadata file that contains the index definition and a set of index snapshots. Each +index snapshot corresponds to a snapshot of the source table and references the index data for that state. + +Index metadata files and index data files are immutable. Every update writes a new metadata file and a new tracking +file, may reuse existing range files, and is committed by an atomic swap of the index metadata file, as defined in +[Commits and Concurrency](#commits-and-concurrency). + +The index data of a snapshot is organized as a [tracking file](#tracking-file) that lists a set of +[range files](#range-files): + +```text +Index Metadata + | + +-- Index Snapshot(s) + | + +-- Tracking File + | + +-- Range Files +``` + +## Specification + +### Terms + +* **Index** -- A structure that accelerates retrieval of rows from a source table. +* **Index snapshot** -- The state of an index for a single snapshot of the source table. +* **Index entry** -- The values produced by the index fields for one indexed row of the source table. +* **Clustering key** -- The tuple of values that determines the position of an index entry within an index snapshot. +* **Tracking file** -- A file that lists the range files of an index snapshot; one per index snapshot. +* **Range file** -- A file that stores the index entries for a range of clustering keys; a subset of an index snapshot. + +### Paths in Metadata + +Path strings stored in index metadata are classified and resolved as defined by +[paths in metadata](spec.md#paths-in-metadata) in the table specification. Relative paths are resolved against the +index `location`, which must be an absolute path. + +### Index Definition + +An index is defined by a source table, an index type, identity fields, materialized fields, non-materialized fields, a +cluster spec, and optional index properties. The definition is fixed when the index is created and must not change for +the lifetime of the index, so range files remain readable through every index snapshot that references them. A different +definition requires a new index. + +A table may have multiple indexes of the same index type. + +#### Index Type + +The index type defines the logical category of an index and the class of queries it accelerates. + +| Type | Status | Description | +|----------|-----------------------------------|-----------------------------------------------------------------------------------------------------------------------| +| `SCALAR` | Defined by this specification | Accelerates point lookups on clustered fields, and range filters when the clustering expressions are order preserving | +| `VECTOR` | Reserved for future specification | Accelerates similarity search over vector embeddings | + +Writers must write `type` in upper case. Readers must match it case-insensitively. A reader that does not implement an +index type must ignore the index and read the source table directly; it must not fail. + +#### Index Fields + +An index field defines one value of an index entry, produced for an indexed row of the source table. An index declares +three lists of index fields: [identity fields](#identity-fields) and [materialized fields](#materialized-fields), whose +values are stored in [range files](#range-files), and [non-materialized fields](#non-materialized-fields), which are +represented only by statistics in [tracking file entries](#tracking-file-entry). Every index field has a field ID that +must be unique across the three lists. + +#### Expression Fields + +The value of an expression field is produced by evaluating an +[Iceberg value expression](expressions-spec.md#value-expressions) for an indexed row of the source table. +An expression field has the following fields: + +| Requirement | Field name | Type | Description | +|-------------|---------------|-------------------|--------------------------------------------------------------| +| _required_ | `field-id` | `int` | ID that uniquely identifies the index field | +| _required_ | `type` | `string` | Expression field representation; must be `expr-value` | +| _required_ | `data-type` | Iceberg type | Type produced by the expression | +| _required_ | `expr` | JSON expression | Value expression that produces the field, serialized as JSON | + +Each expression field must satisfy the following requirements: + +- `expr` must contain only ID references to source table fields or + [metadata columns](spec.md#reserved-field-ids). Named references must not be used. The `_deleted`, `_change_type`, + `_change_ordinal`, and `_commit_snapshot_id` metadata columns must not be referenced, and neither must the + `file_path`, `pos`, and `row` columns of delete files. +- `expr` must be deterministic and must produce the declared `data-type`. +- `field-id` must not be a [reserved field ID](spec.md#reserved-field-ids) and must not be a field ID in the source Review Comment: I think "must not be a field id in the source" can't be guaranteed to be true if the source table evolves. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
