Skip to content

Commit 45d255f

Browse files
Shefeek JinnahShefeek Jinnah
authored andcommitted
Fixing formatting issues
1 parent 3ede8e6 commit 45d255f

File tree

2 files changed

+108
-172
lines changed

2 files changed

+108
-172
lines changed

src/metadata_provider_postgres.rs

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@
2222
2323
#![cfg(feature = "metadata-postgres")]
2424

25+
use crate::Result;
2526
use crate::metadata_provider::{
26-
block_on, ColumnWithTable, DuckLakeFileData, DuckLakeTableColumn, DuckLakeTableFile,
27-
FileWithTable, MetadataProvider, SchemaMetadata, SnapshotMetadata, TableMetadata,
28-
TableWithSchema,
27+
ColumnWithTable, DuckLakeFileData, DuckLakeTableColumn, DuckLakeTableFile, FileWithTable,
28+
MetadataProvider, SchemaMetadata, SnapshotMetadata, TableMetadata, TableWithSchema, block_on,
2929
};
30-
use crate::Result;
30+
use sqlx::Row;
3131
use sqlx::postgres::{PgPool, PgPoolOptions};
3232
use sqlx::types::chrono::NaiveDateTime;
33-
use sqlx::Row;
3433

3534
/// Helper macro to bind the same value multiple times
3635
///
@@ -57,8 +56,13 @@ macro_rules! bind_repeat {
5756
$query.bind($value).bind($value).bind($value).bind($value)
5857
};
5958
($query:expr, $value:expr, 6) => {
60-
$query.bind($value).bind($value).bind($value)
61-
.bind($value).bind($value).bind($value)
59+
$query
60+
.bind($value)
61+
.bind($value)
62+
.bind($value)
63+
.bind($value)
64+
.bind($value)
65+
.bind($value)
6266
};
6367
}
6468

@@ -89,7 +93,9 @@ impl PostgresMetadataProvider {
8993
.connect(connection_string)
9094
.await?;
9195

92-
let provider = Self { pool };
96+
let provider = Self {
97+
pool,
98+
};
9399

94100
// Automatically initialize schema - this is idempotent and safe
95101
provider.init_schema().await?;
@@ -208,11 +214,9 @@ impl PostgresMetadataProvider {
208214

209215
// Index for table lookup by schema (WHERE schema_id = ?)
210216
// Improves: list_tables, get_table_by_name, table_exists
211-
sqlx::query(
212-
"CREATE INDEX IF NOT EXISTS idx_table_schema ON ducklake_table(schema_id)",
213-
)
214-
.execute(&self.pool)
215-
.await?;
217+
sqlx::query("CREATE INDEX IF NOT EXISTS idx_table_schema ON ducklake_table(schema_id)")
218+
.execute(&self.pool)
219+
.await?;
216220

217221
// Index for snapshot-based table queries (WHERE snapshot >= begin AND snapshot < end)
218222
// Improves: list_tables, get_table_by_name, table_exists, list_all_tables
@@ -227,7 +231,7 @@ impl PostgresMetadataProvider {
227231
// Prevents ambiguous get_schema_by_name() results
228232
sqlx::query(
229233
"CREATE UNIQUE INDEX IF NOT EXISTS idx_schema_name_active
230-
ON ducklake_schema(schema_name) WHERE end_snapshot IS NULL"
234+
ON ducklake_schema(schema_name) WHERE end_snapshot IS NULL",
231235
)
232236
.execute(&self.pool)
233237
.await?;
@@ -236,7 +240,7 @@ impl PostgresMetadataProvider {
236240
// Prevents ambiguous get_table_by_name() results
237241
sqlx::query(
238242
"CREATE UNIQUE INDEX IF NOT EXISTS idx_table_name_active
239-
ON ducklake_table(schema_id, table_name) WHERE end_snapshot IS NULL"
243+
ON ducklake_table(schema_id, table_name) WHERE end_snapshot IS NULL",
240244
)
241245
.execute(&self.pool)
242246
.await?;
@@ -245,7 +249,7 @@ impl PostgresMetadataProvider {
245249
// Columns are not temporal (no end_snapshot), so enforce globally per table
246250
sqlx::query(
247251
"CREATE UNIQUE INDEX IF NOT EXISTS idx_column_name_unique
248-
ON ducklake_column(table_id, column_name)"
252+
ON ducklake_column(table_id, column_name)",
249253
)
250254
.execute(&self.pool)
251255
.await?;
@@ -257,30 +261,29 @@ impl PostgresMetadataProvider {
257261
impl MetadataProvider for PostgresMetadataProvider {
258262
fn get_current_snapshot(&self) -> Result<i64> {
259263
block_on(async {
260-
let row =
261-
sqlx::query("SELECT COALESCE(MAX(snapshot_id), 0) FROM ducklake_snapshot")
262-
.fetch_one(&self.pool)
263-
.await?;
264+
let row = sqlx::query("SELECT COALESCE(MAX(snapshot_id), 0) FROM ducklake_snapshot")
265+
.fetch_one(&self.pool)
266+
.await?;
264267
Ok(row.try_get(0)?)
265268
})
266269
}
267270

268271
fn get_data_path(&self) -> Result<String> {
269272
block_on(async {
270-
let row = sqlx::query(
271-
"SELECT value FROM ducklake_metadata WHERE key = $1 AND scope = $2",
272-
)
273-
.bind("data_path")
274-
.bind("")
275-
.fetch_optional(&self.pool)
276-
.await?;
273+
let row =
274+
sqlx::query("SELECT value FROM ducklake_metadata WHERE key = $1 AND scope = $2")
275+
.bind("data_path")
276+
.bind("")
277+
.fetch_optional(&self.pool)
278+
.await?;
277279

278280
match row {
279281
Some(r) => Ok(r.try_get(0)?),
280282
None => Err(crate::error::DuckLakeError::InvalidConfig(
281283
"Missing required catalog metadata: 'data_path' not configured. \
282-
The catalog may be uninitialized or corrupted.".to_string()
283-
))
284+
The catalog may be uninitialized or corrupted."
285+
.to_string(),
286+
)),
284287
}
285288
})
286289
}
@@ -299,9 +302,8 @@ impl MetadataProvider for PostgresMetadataProvider {
299302
let snapshot_id: i64 = row.try_get(0)?;
300303
// Format timestamp in Rust for determinism (not SQL CAST)
301304
let timestamp: Option<NaiveDateTime> = row.try_get(1)?;
302-
let timestamp_str = timestamp.map(|ts: NaiveDateTime| {
303-
ts.format("%Y-%m-%d %H:%M:%S%.6f").to_string()
304-
});
305+
let timestamp_str = timestamp
306+
.map(|ts: NaiveDateTime| ts.format("%Y-%m-%d %H:%M:%S%.6f").to_string());
305307

306308
Ok(SnapshotMetadata {
307309
snapshot_id,

0 commit comments

Comments
 (0)