### Create and Append to Iceberg Table (File Catalog) Source: https://github.com/hyparam/icebird/blob/master/README.md Demonstrates creating an Iceberg table and appending records using a file-based catalog. Ensure the 'icebird' library is imported. ```javascript import { fileCatalog, icebergAppend, icebergCreateTable, icebergDelete, icebergExpireSnapshots, icebergSetRef, } from 'icebird' // `urlResolver()` ships with a `writer` (HTTP PUT) and `deleter` (HTTP DELETE); // pass a custom `requestInit` to it for auth headers. For non-HTTP backends, // supply your own `Resolver` with `writer` and (for drop) `deleter`. const catalog = fileCatalog({ resolver }) const tableUrl = 's3://my-bucket/warehouse/orders' const schema = { type: 'struct', 'schema-id': 0, fields: [ { id: 1, name: 'id', required: true, type: 'long' }, { id: 2, name: 'name', required: false, type: 'string' }, ], } await icebergCreateTable({ catalog, tableUrl, schema }) await icebergAppend({ catalog, tableUrl, records: [{ id: 1n, name: 'alice' }] }) ``` -------------------------------- ### Authentication with Custom Fetch Options Source: https://github.com/hyparam/icebird/blob/master/README.md Adds authentication or custom fetch options by creating a resolver and lister with requestInit. This is useful for private buckets or custom authorization. ```javascript import { icebergMetadata, icebergRead, s3Lister, urlResolver } from 'icebird' const requestInit = { headers: { Authorization: 'Bearer my_token', }, } const resolver = urlResolver({ requestInit }) const lister = s3Lister({ requestInit }) const metadata = await icebergMetadata({ tableUrl, resolver, lister, }) const data = await icebergRead({ tableUrl, metadata, resolver, lister, }) ``` -------------------------------- ### Manage Iceberg Snapshots Source: https://github.com/hyparam/icebird/blob/master/README.md Illustrates how to manage snapshots in an Iceberg table, including setting a reference and expiring old snapshots. ```javascript // snapshot management await icebergSetRef({ catalog, tableUrl, ref: 'main', snapshotId }) await icebergExpireSnapshots({ catalog, tableUrl, snapshotIds: [oldSnapshotId] }) ``` -------------------------------- ### Connect to Iceberg REST Catalog Source: https://github.com/hyparam/icebird/blob/master/README.md Connects to an Iceberg REST Catalog and loads table metadata. Multi-level namespaces are supported and must be quoted in SQL queries. ```javascript import { icebergRead, restCatalogConnect, restCatalogLoadTable } from 'icebird' const ctx = await restCatalogConnect({ url: 'https://catalog.example.com' }) const { metadata } = await restCatalogLoadTable(ctx, { namespace: 'analytics', table: 'orders' }) const data = await icebergRead({ tableUrl: metadata.location, metadata }) ``` -------------------------------- ### Append to Iceberg Table (REST Catalog) Source: https://github.com/hyparam/icebird/blob/master/README.md Demonstrates appending records to an Iceberg table using a REST catalog. This requires connecting to the catalog URL first. ```javascript const catalog = await restCatalogConnect({ url: 'https://catalog.example.com' }) await icebergAppend({ catalog, namespace: 'analytics', table: 'orders', records }) ``` -------------------------------- ### Secure S3-Compatible Bucket Access Source: https://github.com/hyparam/icebird/blob/master/README.md Uses s3SignedResolver for secure access to private S3-compatible buckets (AWS, R2, MinIO) by signing requests with SigV4. Works in browsers and Node.js. ```javascript import { icebergRead, s3SignedResolver } from 'icebird' const resolver = s3SignedResolver({ accessKeyId, secretAccessKey, region: 'us-east-1', // For R2/MinIO, set endpoint and pathStyle: // endpoint: 'https://.r2.cloudflarestorage.com', pathStyle: true, }) const data = await icebergRead({ tableUrl: 's3://my-bucket/warehouse/orders', resolver }) ``` -------------------------------- ### Query Iceberg Tables with SQL Source: https://github.com/hyparam/icebird/blob/master/README.md Executes SQL queries against Iceberg tables using the integrated SQL engine. Rows are streamed lazily. Use dot-separated and quoted multi-level namespaces in FROM clauses. ```javascript import { collect, icebergQuery, restCatalogConnect } from 'icebird' const catalog = await restCatalogConnect({ url: 'https://catalog.example.com' }) const result = await icebergQuery({ catalog, query: 'SELECT "Breed Name", "Popularity Rank" FROM "java.bunnies" WHERE "Popularity Rank" <= 3 ORDER BY "Popularity Rank"', }) const rows = await collect(result) ``` -------------------------------- ### Time Travel: Fetch Previous Table Version Source: https://github.com/hyparam/icebird/blob/master/README.md Retrieves a previous version of an Iceberg table by specifying the metadata file name. ```javascript import { icebergRead } from 'icebird' const data = await icebergRead({ tableUrl, metadataFileName: 'v1.metadata.json', }) ``` -------------------------------- ### Read Iceberg Table Metadata Source: https://github.com/hyparam/icebird/blob/master/README.md Fetches the metadata (schema, etc.) for an Iceberg table. Providing metadata in subsequent reads can improve performance. ```javascript import { icebergMetadata } from 'icebird' const metadata = await icebergMetadata({ tableUrl }) // subsequent reads will be faster if you provide the metadata: const data = await icebergRead({ tableUrl, metadata, }) ``` -------------------------------- ### Delete Records in Iceberg Table Source: https://github.com/hyparam/icebird/blob/master/README.md Shows how to delete records from an Iceberg table using position deletes. This supports v3 deletion vectors and v2 parquet delete files. ```javascript // position deletes — v3 writes deletion vectors; v2 writes parquet delete files await icebergDelete({ catalog, tableUrl, deletes: [{ file_path: 's3://.../data/abc.parquet', pos: 0 }], }) ``` -------------------------------- ### Read Iceberg Table Data Source: https://github.com/hyparam/icebird/blob/master/README.md Reads a specified range of rows from an Iceberg table. Ensure the 'icebird' package is imported. ```javascript const { icebergRead } = await import('icebird') const tableUrl = 'https://s3.amazonaws.com/hyperparam-iceberg/spark/bunnies' const data = await icebergRead({ tableUrl, rowStart: 0, rowEnd: 10, }) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.