dannycjones commented on code in PR #3032:
URL: https://github.com/apache/iceberg-rust/pull/3032#discussion_r3830581623
##########
crates/catalog/sql/src/catalog.rs:
##########
@@ -343,6 +417,46 @@ impl SqlCatalog {
.await
.map_err(from_sqlx_error)?;
+ // Probe for the `iceberg_type` column to detect whether the catalog
table is already a schema version v1 (which supports views).
+ let is_v1 = match sqlx::query(&format!(
+ "SELECT {CATALOG_FIELD_RECORD_TYPE} FROM {CATALOG_TABLE_NAME}
LIMIT 0"
+ ))
+ .execute(&pool)
+ .await
+ {
+ Ok(_) => true,
+ // The database rejected the query: the `iceberg_type` column (or
table) is absent,
+ // so this is a genuine V0 schema.
+ Err(sqlx::Error::Database(_)) => false,
Review Comment:
I had a deeper look. AI helped me find that sqlx actually abstracts this
behind a `describe` method, and provides an agnostic way to get a list of
columns from a `SELECT`.
I've updated a PR that uses this, so it'll propagate errors if it couldn't
get a list of columns, otherwise we check the list for the presence of the
`iceberg_type` column.
--
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]