Skip to main content

feldera_types/transport/
iceberg.rs

1use serde::{Deserialize, Serialize};
2use std::{collections::HashMap, fmt::Display};
3use utoipa::ToSchema;
4
5/// Iceberg table read mode.
6///
7/// Three options are available:
8///
9/// * `snapshot` - read a snapshot of the table and stop.
10///
11/// * `follow` - continuously ingest changes to the table, starting from a specified snapshot
12///   or timestamp.
13///
14/// * `snapshot_and_follow` - read a snapshot of the table before switching to continuous ingestion
15///   mode.
16#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, ToSchema)]
17pub enum IcebergIngestMode {
18    /// Read a snapshot of the table and stop.
19    #[serde(rename = "snapshot")]
20    Snapshot,
21
22    /// Follow the changelog of the table, only ingesting changes (new and deleted rows).
23    #[serde(rename = "follow")]
24    Follow,
25
26    /// Take a snapshot of the table before switching to the `follow` mode.
27    #[serde(rename = "snapshot_and_follow")]
28    SnapshotAndFollow,
29}
30
31impl Display for IcebergIngestMode {
32    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33        match self {
34            IcebergIngestMode::Snapshot => f.write_str("snapshot"),
35            IcebergIngestMode::Follow => f.write_str("follow"),
36            IcebergIngestMode::SnapshotAndFollow => f.write_str("snapshot_and_follow"),
37        }
38    }
39}
40
41#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, ToSchema)]
42pub enum IcebergCatalogType {
43    #[serde(rename = "rest")]
44    Rest,
45    #[serde(rename = "glue")]
46    Glue,
47    #[serde(rename = "s3tables")]
48    S3Tables,
49}
50
51/// Iceberg table transaction mode.
52///
53/// Determines how the connector breaks up its input into Feldera transactions.
54///
55/// * `none` - the connector does not break up its input into transactions.
56/// * `snapshot` - ingest the initial snapshot of the table in one or several transactions.
57///
58/// # How the table snapshot is ingested using transactions
59///
60/// When `transaction_mode` is set to `snapshot`, the connector ingests the snapshot in one
61/// or several transactions, depending on `timestamp_column`. If `timestamp_column` is not set,
62/// the whole snapshot is ingested in a single Feldera transaction. If `timestamp_column` is set,
63/// the connector ingests the snapshot in a series of timestamp ranges of width equal to the
64/// `LATENESS` attribute of the column, each range in a separate transaction.
65#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, ToSchema, Default)]
66pub enum IcebergTransactionMode {
67    #[default]
68    #[serde(rename = "none")]
69    None,
70    #[serde(rename = "snapshot")]
71    Snapshot,
72}
73
74/// AWS Glue catalog config.
75#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, ToSchema)]
76pub struct GlueCatalogConfig {
77    /// Location for table metadata.
78    ///
79    /// Example: `"s3://my-data-warehouse/tables/"`
80    #[serde(rename = "glue.warehouse")]
81    pub warehouse: Option<String>,
82
83    /// Configure an alternative endpoint of the Glue service for Glue catalog to access.
84    ///
85    /// Example: `"https://glue.us-east-1.amazonaws.com"`
86    #[serde(rename = "glue.endpoint")]
87    pub endpoint: Option<String>,
88
89    /// Access key id used to access the Glue catalog.
90    #[serde(rename = "glue.access-key-id")]
91    pub access_key_id: Option<String>,
92
93    /// Secret access key used to access the Glue catalog.
94    #[serde(rename = "glue.secret-access-key")]
95    pub secret_access_key: Option<String>,
96
97    /// Profile used to access the Glue catalog.
98    #[serde(rename = "glue.profile-name")]
99    pub profile_name: Option<String>,
100
101    /// Region of the Glue catalog.
102    #[serde(rename = "glue.region")]
103    pub region: Option<String>,
104
105    // Static session token used to access the Glue catalog.
106    #[serde(rename = "glue.session-token")]
107    pub session_token: Option<String>,
108
109    /// The 12-digit ID of the Glue catalog.
110    #[serde(rename = "glue.id")]
111    pub id: Option<String>,
112}
113
114/// Iceberg REST catalog config.
115#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, ToSchema)]
116pub struct RestCatalogConfig {
117    /// URI identifying the REST catalog server.
118    #[serde(rename = "rest.uri")]
119    pub uri: Option<String>,
120
121    /// The default location for managed tables created by the catalog.
122    #[serde(rename = "rest.warehouse")]
123    pub warehouse: Option<String>,
124
125    /// Authentication URL to use for client credentials authentication (default: uri + 'v1/oauth/tokens')
126    #[serde(rename = "rest.oauth2-server-uri")]
127    pub oauth2_server_uri: Option<String>,
128
129    /// Credential to use for OAuth2 credential flow when initializing the catalog.
130    ///
131    /// A key and secret pair separated by ":" (key is optional).
132    #[serde(rename = "rest.credential")]
133    pub credential: Option<String>,
134
135    /// Bearer token value to use for `Authorization` header.
136    #[serde(rename = "rest.token")]
137    pub token: Option<String>,
138
139    // Desired scope of the requested security token (default: catalog).
140    #[serde(rename = "rest.scope")]
141    pub scope: Option<String>,
142
143    /// Customize table storage paths.
144    ///
145    /// When combined with the `warehouse` property, the prefix determines
146    /// how table data is organized within the storage.
147    #[serde(rename = "rest.prefix")]
148    pub prefix: Option<String>,
149
150    /// Additional HTTP request headers added to each catalog REST API call.
151    #[serde(default)]
152    #[serde(rename = "rest.headers")]
153    pub headers: Option<Vec<(String, String)>>,
154
155    /// Logical name of target resource or service.
156    #[serde(rename = "rest.audience")]
157    pub audience: Option<String>,
158
159    /// URI for the target resource or service.
160    #[serde(rename = "rest.resource")]
161    pub resource: Option<String>,
162}
163
164/// Amazon S3 Tables catalog config.
165#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, ToSchema)]
166pub struct S3TablesCatalogConfig {
167    /// ARN of the S3 table bucket that contains the table.
168    ///
169    /// Note that this is the ARN of the table *bucket*, not of an individual table,
170    /// e.g., `"arn:aws:s3tables:us-east-2:123456789012:bucket/my-bucket"`.
171    #[serde(rename = "s3tables.table-bucket-arn")]
172    pub table_bucket_arn: Option<String>,
173
174    /// Custom endpoint URL for the S3 Tables service.
175    ///
176    /// Primarily used to target a local or mock S3 Tables implementation for testing.
177    /// When omitted, the default regional endpoint is used.
178    #[serde(rename = "s3tables.endpoint")]
179    pub endpoint: Option<String>,
180
181    /// Access key id used to access the S3 Tables catalog.
182    #[serde(rename = "s3tables.access-key-id")]
183    pub access_key_id: Option<String>,
184
185    /// Secret access key used to access the S3 Tables catalog.
186    #[serde(rename = "s3tables.secret-access-key")]
187    pub secret_access_key: Option<String>,
188
189    /// Static session token used to access the S3 Tables catalog.
190    #[serde(rename = "s3tables.session-token")]
191    pub session_token: Option<String>,
192
193    /// Profile used to access the S3 Tables catalog.
194    #[serde(rename = "s3tables.profile-name")]
195    pub profile_name: Option<String>,
196
197    /// Region of the S3 Tables catalog.
198    #[serde(rename = "s3tables.region")]
199    pub region: Option<String>,
200}
201
202fn default_num_parsers() -> u32 {
203    4
204}
205
206/// Iceberg input connector configuration.
207#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, ToSchema)]
208pub struct IcebergReaderConfig {
209    /// Table read mode.
210    pub mode: IcebergIngestMode,
211
212    /// Transaction mode.
213    ///
214    /// Determines how the connector breaks up its input into Feldera transactions.
215    /// See [`IcebergTransactionMode`]. Defaults to [`IcebergTransactionMode::None`].
216    #[serde(default)]
217    pub transaction_mode: IcebergTransactionMode,
218
219    /// Table column that serves as an event timestamp.
220    ///
221    /// When this option is specified, and `mode` is one of `snapshot` or `snapshot_and_follow`,
222    /// table rows are ingested in the timestamp order, respecting the
223    /// [`LATENESS`](https://docs.feldera.com/sql/streaming#lateness-expressions)
224    /// property of the column: each ingested row has a timestamp no more than `LATENESS`
225    /// time units earlier than the most recent timestamp of any previously ingested row.
226    /// The ingestion is performed by partitioning the table into timestamp ranges of width
227    /// `LATENESS`. Each range is processed sequentially, in increasing timestamp order.
228    ///
229    /// # Example
230    ///
231    /// Consider a table with timestamp column of type `TIMESTAMP` and lateness attribute
232    /// `INTERVAL 1 DAY`. Assuming that the oldest timestamp in the table is
233    /// `2024-01-01T00:00:00``, the connector will fetch all records with timestamps
234    /// from `2024-01-01`, then all records for `2024-01-02`, `2024-01-03`, etc., until all records
235    /// in the table have been ingested.
236    ///
237    /// # Requirements
238    ///
239    /// * The timestamp column must be of a supported type: integer, `DATE`, or `TIMESTAMP`.
240    /// * The timestamp column must be declared with non-zero `LATENESS`.
241    /// * For efficient ingest, the table must be optimized for timestamp-based
242    ///   queries using partitioning, Z-ordering, or liquid clustering.
243    pub timestamp_column: Option<String>,
244
245    /// Optional row filter.
246    ///
247    /// This option is only valid when `mode` is set to `snapshot` or `snapshot_and_follow`.
248    ///
249    /// When specified, only rows that satisfy the filter condition are included in the
250    /// snapshot.  The condition must be a valid SQL Boolean expression that can be used in
251    /// the `where` clause of the `select * from snapshot where ...` query.
252    ///
253    /// This option can be used to specify the range of event times to include in the snapshot,
254    /// e.g.: `ts BETWEEN '2005-01-01 00:00:00' AND '2010-12-31 23:59:59'`.
255    pub snapshot_filter: Option<String>,
256
257    /// Optional snapshot id.
258    ///
259    /// When this option is set, the connector finds the specified snapshot of the table.
260    /// In `snapshot` and `snapshot_and_follow` modes, it loads this snapshot.
261    /// In `follow` and `snapshot_and_follow` modes, it follows table updates
262    /// **after** this snapshot.
263    ///
264    /// Note: at most one of `snapshot_id` and `datetime` options can be specified.
265    /// When neither of the two options is specified, the latest committed version of the table
266    /// is used.
267    pub snapshot_id: Option<i64>,
268
269    /// Optional timestamp for the snapshot in the ISO-8601/RFC-3339 format, e.g.,
270    /// "2024-12-09T16:09:53+00:00".
271    ///
272    /// When this option is set, the connector finds and opens the snapshot of the table as of the
273    /// specified point in time (based on the server time recorded in the transaction
274    /// log, not the event time encoded in the data).  In `snapshot` and `snapshot_and_follow`
275    /// modes, it retrieves this snapshot.  In `follow` and `snapshot_and_follow` modes, it
276    /// follows transaction log records **after** this snapshot.
277    ///
278    /// Note: at most one of `snapshot_id` and `datetime` options can be specified.
279    /// When neither of the two options is specified, the latest committed version of the table
280    /// is used.
281    pub datetime: Option<String>,
282
283    /// Location of the table metadata JSON file.
284    ///
285    /// This propery is used to access an Iceberg table without a catalog. It is mutually
286    /// exclusive with the `catalog_type` property.
287    pub metadata_location: Option<String>,
288
289    /// Specifies the Iceberg table name in the "namespace.table" format.
290    ///
291    /// This option is applicable when an Iceberg catalog is configured using the `catalog_type` property.
292    pub table_name: Option<String>,
293
294    /// Specifies the catalog type used to access the Iceberg table.
295    ///
296    /// Supported options include "rest", "glue", and "s3tables". This property is mutually
297    /// exclusive with `metadata_location`.
298    pub catalog_type: Option<IcebergCatalogType>,
299
300    /// The number of parallel parsing tasks the connector uses to process data read from the
301    /// table. Increasing this value can enhance performance by allowing more concurrent processing.
302    /// Recommended range: 1-10. The default is 4.
303    #[serde(default = "default_num_parsers")]
304    #[schema(minimum = 1)]
305    pub num_parsers: u32,
306
307    /// Maximum number of retries for reading the table snapshot.
308    ///
309    /// When reading the snapshot fails partway through, for example because an
310    /// object-store read times out or is throttled, the connector retries the
311    /// entire read with exponential backoff. This is in addition to the
312    /// lower-level retries performed by the object-store client.
313    ///
314    /// Defaults to unlimited retries. Set to 0 to disable retries.
315    #[serde(default, skip_serializing_if = "Option::is_none")]
316    pub max_retries: Option<u32>,
317
318    #[serde(flatten)]
319    pub glue_catalog_config: GlueCatalogConfig,
320
321    #[serde(flatten)]
322    pub rest_catalog_config: RestCatalogConfig,
323
324    #[serde(flatten)]
325    pub s3tables_catalog_config: S3TablesCatalogConfig,
326
327    /// Storage options for configuring backend object store.
328    ///
329    /// See the [list of available options in PyIceberg documentation](https://py.iceberg.apache.org/configuration/#fileio).
330    #[serde(flatten)]
331    pub fileio_config: HashMap<String, String>,
332}
333
334impl IcebergReaderConfig {
335    pub fn validate_catalog_config(&self) -> Result<(), String> {
336        self.validate_metadata_location()?;
337        self.validate_table_name()?;
338        self.validate_glue_catalog_config()?;
339        self.validate_rest_catalog_config()?;
340        self.validate_s3tables_catalog_config()?;
341
342        Ok(())
343    }
344
345    /// Reject Glue catalog config properties when 'catalog_type' isn't set to 'glue'.
346    pub fn validate_glue_catalog_config(&self) -> Result<(), String> {
347        if self.catalog_type == Some(IcebergCatalogType::Glue) {
348            if self.glue_catalog_config.warehouse.is_none() {
349                return Err(r#"missing Iceberg warehouse location—set the 'glue.warehouse' property to the location of the Iceberg tables managed by the catalog (e.g., 's3://my-data-warehouse/tables/') when using "catalog_type" = "glue""#.to_string());
350            }
351        } else {
352            ensure_glue_property_not_set(&self.glue_catalog_config.warehouse, "warehouse")?;
353            ensure_glue_property_not_set(&self.glue_catalog_config.endpoint, "uri")?;
354            ensure_glue_property_not_set(&self.glue_catalog_config.access_key_id, "access-key-id")?;
355            ensure_glue_property_not_set(
356                &self.glue_catalog_config.secret_access_key,
357                "secret-access-key",
358            )?;
359            ensure_glue_property_not_set(&self.glue_catalog_config.profile_name, "profile-name")?;
360            ensure_glue_property_not_set(&self.glue_catalog_config.region, "region")?;
361            ensure_glue_property_not_set(&self.glue_catalog_config.session_token, "session-token")?;
362            ensure_glue_property_not_set(&self.glue_catalog_config.id, "id")?;
363        }
364
365        Ok(())
366    }
367
368    /// Reject Rest catalog config when 'catalog_type' isn't set to 'rest'.
369    pub fn validate_rest_catalog_config(&self) -> Result<(), String> {
370        if self.catalog_type == Some(IcebergCatalogType::Rest) {
371            if self.rest_catalog_config.uri.is_none() {
372                return Err(r#"missing Iceberg Rest catalog URI—set the 'rest.uri' property when using "catalog_type" = "rest""#.to_string());
373            }
374        } else {
375            ensure_rest_property_not_set(&self.rest_catalog_config.uri, "uri")?;
376            ensure_rest_property_not_set(&self.rest_catalog_config.warehouse, "warehouse")?;
377            ensure_rest_property_not_set(
378                &self.rest_catalog_config.oauth2_server_uri,
379                "oauth2_server_uri",
380            )?;
381            ensure_rest_property_not_set(&self.rest_catalog_config.credential, "credential")?;
382            ensure_rest_property_not_set(&self.rest_catalog_config.token, "token")?;
383            ensure_rest_property_not_set(&self.rest_catalog_config.scope, "scope")?;
384            ensure_rest_property_not_set(&self.rest_catalog_config.prefix, "prefix")?;
385            ensure_rest_property_not_set(&self.rest_catalog_config.headers, "headers")?;
386            ensure_rest_property_not_set(&self.rest_catalog_config.audience, "audience")?;
387            ensure_rest_property_not_set(&self.rest_catalog_config.resource, "resource")?;
388        }
389
390        Ok(())
391    }
392
393    /// Reject S3 Tables catalog config when 'catalog_type' isn't set to 's3tables'.
394    pub fn validate_s3tables_catalog_config(&self) -> Result<(), String> {
395        if self.catalog_type == Some(IcebergCatalogType::S3Tables) {
396            if self.s3tables_catalog_config.table_bucket_arn.is_none() {
397                return Err(r#"missing S3 table bucket ARN; set the 's3tables.table-bucket-arn' property to the ARN of the S3 table bucket (e.g., 'arn:aws:s3tables:us-east-2:123456789012:bucket/my-bucket') when using "catalog_type" = "s3tables""#.to_string());
398            }
399        } else {
400            ensure_s3tables_property_not_set(
401                &self.s3tables_catalog_config.table_bucket_arn,
402                "table-bucket-arn",
403            )?;
404            ensure_s3tables_property_not_set(&self.s3tables_catalog_config.endpoint, "endpoint")?;
405            ensure_s3tables_property_not_set(
406                &self.s3tables_catalog_config.access_key_id,
407                "access-key-id",
408            )?;
409            ensure_s3tables_property_not_set(
410                &self.s3tables_catalog_config.secret_access_key,
411                "secret-access-key",
412            )?;
413            ensure_s3tables_property_not_set(
414                &self.s3tables_catalog_config.session_token,
415                "session-token",
416            )?;
417            ensure_s3tables_property_not_set(
418                &self.s3tables_catalog_config.profile_name,
419                "profile-name",
420            )?;
421            ensure_s3tables_property_not_set(&self.s3tables_catalog_config.region, "region")?;
422        }
423
424        Ok(())
425    }
426
427    /// Table name must be configured iff 'catalog_type' is set.
428    pub fn validate_table_name(&self) -> Result<(), String> {
429        if self.catalog_type.is_none() && self.table_name.is_some() {
430            Err("unexpected 'table_name' property: the 'table_name' property is valid only when an Iceberg catalog is configured using 'catalog_type'".to_string())
431        } else if self.catalog_type.is_some() && self.table_name.is_none() {
432            Err("missing 'table_name' property—'table_name' must be specified when Iceberg catalog is configured using 'catalog_type'".to_string())
433        } else {
434            Ok(())
435        }
436    }
437
438    /// 'metadata_location' must be configured iff 'catalog_type' is set.
439    pub fn validate_metadata_location(&self) -> Result<(), String> {
440        if self.catalog_type.is_none() && self.metadata_location.is_none() {
441            Err("missing metadata location: you must either specify an Iceberg catalog configuration by setting the 'catalog_type' property or provide a table metadata location directly via the 'metadata_location' property".to_string())
442        } else if self.catalog_type.is_some() && self.metadata_location.is_some() {
443            Err("unexpected 'metadata_location' property: the 'metadata_location' property is not supported when an Iceberg catalog is configured using 'catalog_type'".to_string())
444        } else {
445            Ok(())
446        }
447    }
448}
449
450fn ensure_glue_property_not_set<T>(property: &Option<T>, name: &str) -> Result<(), String> {
451    if property.is_some() {
452        Err(format!(
453            r#"unexpected 'glue.{name}' property—Glue catalog configuration properties are only valid when "catalog_type" = "glue""#
454        ))
455    } else {
456        Ok(())
457    }
458}
459
460fn ensure_rest_property_not_set<T>(property: &Option<T>, name: &str) -> Result<(), String> {
461    if property.is_some() {
462        Err(format!(
463            r#"unexpected 'rest.{name}' property—Rest catalog configuration properties are only valid when "catalog_type" = "rest""#
464        ))
465    } else {
466        Ok(())
467    }
468}
469
470fn ensure_s3tables_property_not_set<T>(property: &Option<T>, name: &str) -> Result<(), String> {
471    if property.is_some() {
472        Err(format!(
473            r#"unexpected 's3tables.{name}' property—S3 Tables catalog configuration properties are only valid when "catalog_type" = "s3tables""#
474        ))
475    } else {
476        Ok(())
477    }
478}
479
480impl IcebergReaderConfig {
481    /// Maximum number of high-level operation retries. Defaults to unlimited.
482    pub fn max_retries(&self) -> u32 {
483        self.max_retries.unwrap_or(u32::MAX)
484    }
485
486    /// `true` if the configuration requires taking an initial snapshot of the table.
487    pub fn snapshot(&self) -> bool {
488        matches!(
489            &self.mode,
490            IcebergIngestMode::Snapshot | IcebergIngestMode::SnapshotAndFollow
491        )
492    }
493
494    /// `true` if the configuration requires following the transaction log of the table
495    /// (possibly after taking an initial snapshot).s
496    pub fn follow(&self) -> bool {
497        matches!(
498            &self.mode,
499            IcebergIngestMode::SnapshotAndFollow | IcebergIngestMode::Follow
500        )
501    }
502}
503
504#[cfg(test)]
505mod test {
506    use super::*;
507    use serde_json::json;
508
509    fn config(value: serde_json::Value) -> IcebergReaderConfig {
510        serde_json::from_value(value).unwrap()
511    }
512
513    #[test]
514    fn s3tables_config_deserializes() {
515        let config = config(json!({
516            "mode": "snapshot",
517            "catalog_type": "s3tables",
518            "table_name": "namespace.table",
519            "s3tables.table-bucket-arn": "arn:aws:s3tables:us-east-2:123456789012:bucket/my-bucket",
520            "s3tables.region": "us-east-2",
521            "s3tables.access-key-id": "key",
522            "s3tables.secret-access-key": "secret",
523            "s3tables.session-token": "token",
524            "s3tables.profile-name": "profile",
525            "s3tables.endpoint": "http://localhost:4566",
526        }));
527
528        // Each prefixed key must land on its struct field, not in the catch-all
529        // `fileio_config` map (which is what happens on a rename mismatch).
530        let s3tables = &config.s3tables_catalog_config;
531        assert_eq!(
532            s3tables.table_bucket_arn.as_deref(),
533            Some("arn:aws:s3tables:us-east-2:123456789012:bucket/my-bucket")
534        );
535        assert_eq!(s3tables.region.as_deref(), Some("us-east-2"));
536        assert_eq!(s3tables.access_key_id.as_deref(), Some("key"));
537        assert_eq!(s3tables.secret_access_key.as_deref(), Some("secret"));
538        assert_eq!(s3tables.session_token.as_deref(), Some("token"));
539        assert_eq!(s3tables.profile_name.as_deref(), Some("profile"));
540        assert_eq!(s3tables.endpoint.as_deref(), Some("http://localhost:4566"));
541        assert!(config.fileio_config.is_empty());
542
543        config.validate_catalog_config().unwrap();
544    }
545
546    #[test]
547    fn s3tables_requires_table_bucket_arn() {
548        let err = config(json!({
549            "mode": "snapshot",
550            "catalog_type": "s3tables",
551            "table_name": "namespace.table",
552        }))
553        .validate_catalog_config()
554        .unwrap_err();
555        assert!(err.contains("s3tables.table-bucket-arn"), "{err}");
556    }
557
558    #[test]
559    fn s3tables_props_rejected_for_other_catalog() {
560        let err = config(json!({
561            "mode": "snapshot",
562            "catalog_type": "glue",
563            "table_name": "namespace.table",
564            "glue.warehouse": "s3://warehouse/",
565            "s3tables.region": "us-east-2",
566        }))
567        .validate_catalog_config()
568        .unwrap_err();
569        assert!(err.contains("s3tables.region"), "{err}");
570    }
571
572    #[test]
573    fn s3tables_props_rejected_without_catalog() {
574        let err = config(json!({
575            "mode": "snapshot",
576            "metadata_location": "s3://warehouse/metadata.json",
577            "s3tables.table-bucket-arn": "arn:aws:s3tables:us-east-2:123456789012:bucket/my-bucket",
578        }))
579        .validate_catalog_config()
580        .unwrap_err();
581        assert!(err.contains("s3tables.table-bucket-arn"), "{err}");
582    }
583
584    #[test]
585    fn num_parsers_and_max_retries_defaults() {
586        // With neither field set, num_parsers defaults to 4 and retries are unlimited.
587        let config: IcebergReaderConfig = serde_json::from_str(
588            r#"{"mode":"snapshot","metadata_location":"file:///tmp/t/metadata.json"}"#,
589        )
590        .unwrap();
591        assert_eq!(config.num_parsers, 4);
592        assert_eq!(config.max_retries, None);
593        assert_eq!(config.max_retries(), u32::MAX);
594    }
595
596    #[test]
597    fn num_parsers_and_max_retries_explicit() {
598        let config: IcebergReaderConfig = serde_json::from_str(
599            r#"{"mode":"snapshot","metadata_location":"file:///tmp/t/metadata.json","num_parsers":8,"max_retries":0}"#,
600        )
601        .unwrap();
602        assert_eq!(config.num_parsers, 8);
603        assert_eq!(config.max_retries, Some(0));
604        // 0 disables retries: the first attempt is the last.
605        assert_eq!(config.max_retries(), 0);
606    }
607
608    #[test]
609    fn transaction_mode_defaults_to_none() {
610        let config: IcebergReaderConfig = serde_json::from_str(
611            r#"{"mode":"snapshot","metadata_location":"file:///tmp/t/metadata.json"}"#,
612        )
613        .unwrap();
614        assert_eq!(config.transaction_mode, IcebergTransactionMode::None);
615    }
616
617    #[test]
618    fn transaction_mode_snapshot_parses() {
619        let config: IcebergReaderConfig = serde_json::from_str(
620            r#"{"mode":"snapshot","metadata_location":"file:///tmp/t/metadata.json","transaction_mode":"snapshot"}"#,
621        )
622        .unwrap();
623        assert_eq!(config.transaction_mode, IcebergTransactionMode::Snapshot);
624    }
625
626    #[test]
627    fn reader_config_roundtrips() {
628        let config: IcebergReaderConfig = serde_json::from_str(
629            r#"{"mode":"snapshot","metadata_location":"file:///tmp/t/metadata.json","num_parsers":2}"#,
630        )
631        .unwrap();
632        let serialized = serde_json::to_string(&config).unwrap();
633        let reparsed: IcebergReaderConfig = serde_json::from_str(&serialized).unwrap();
634        assert_eq!(config, reparsed);
635        assert_eq!(reparsed.num_parsers, 2);
636    }
637}