Skip to content

Commit dcaf502

Browse files
fix: Add is_nullable field support to MySQL metadata provider
1 parent f2c2176 commit dcaf502

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

src/metadata_provider_mysql.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl MetadataProvider for MySqlMetadataProvider {
139139
fn get_table_structure(&self, table_id: i64) -> Result<Vec<DuckLakeTableColumn>> {
140140
block_on(async {
141141
let rows = sqlx::query(
142-
"SELECT column_id, column_name, column_type
142+
"SELECT column_id, column_name, column_type, nulls_allowed
143143
FROM ducklake_column
144144
WHERE table_id = ?
145145
ORDER BY column_order",
@@ -150,10 +150,12 @@ impl MetadataProvider for MySqlMetadataProvider {
150150

151151
rows.into_iter()
152152
.map(|row| {
153+
let nulls_allowed: Option<bool> = row.try_get(3)?;
153154
Ok(DuckLakeTableColumn {
154155
column_id: row.try_get(0)?,
155156
column_name: row.try_get(1)?,
156157
column_type: row.try_get(2)?,
158+
is_nullable: nulls_allowed.unwrap_or(true),
157159
})
158160
})
159161
.collect()
@@ -356,7 +358,7 @@ impl MetadataProvider for MySqlMetadataProvider {
356358
fn list_all_columns(&self, snapshot_id: i64) -> Result<Vec<ColumnWithTable>> {
357359
block_on(async {
358360
let rows = sqlx::query(
359-
"SELECT s.schema_name, t.table_name, c.column_id, c.column_name, c.column_type
361+
"SELECT s.schema_name, t.table_name, c.column_id, c.column_name, c.column_type, c.nulls_allowed
360362
FROM ducklake_schema s
361363
JOIN ducklake_table t ON s.schema_id = t.schema_id
362364
JOIN ducklake_column c ON t.table_id = c.table_id
@@ -377,10 +379,12 @@ impl MetadataProvider for MySqlMetadataProvider {
377379
.map(|row| {
378380
let schema_name: String = row.try_get(0)?;
379381
let table_name: String = row.try_get(1)?;
382+
let nulls_allowed: Option<bool> = row.try_get(5)?;
380383
let column = DuckLakeTableColumn {
381384
column_id: row.try_get(2)?,
382385
column_name: row.try_get(3)?,
383386
column_type: row.try_get(4)?,
387+
is_nullable: nulls_allowed.unwrap_or(true),
384388
};
385389
Ok(ColumnWithTable {
386390
schema_name,

tests/mysql_metadata_provider_test.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ async fn init_schema(pool: &MySqlPool) -> anyhow::Result<()> {
7777
column_name VARCHAR(255) NOT NULL,
7878
column_type VARCHAR(255) NOT NULL,
7979
column_order INTEGER NOT NULL,
80+
nulls_allowed BOOLEAN,
8081
FOREIGN KEY (table_id) REFERENCES ducklake_table(table_id)
8182
)",
8283
)
@@ -254,38 +255,41 @@ async fn populate_test_data(provider: &MySqlMetadataProvider) -> anyhow::Result<
254255

255256
// Insert columns for users table
256257
sqlx::query(
257-
"INSERT INTO ducklake_column (column_id, table_id, column_name, column_type, column_order)
258-
VALUES (?, ?, ?, ?, ?)",
258+
"INSERT INTO ducklake_column (column_id, table_id, column_name, column_type, column_order, nulls_allowed)
259+
VALUES (?, ?, ?, ?, ?, ?)",
259260
)
260261
.bind(1i64)
261262
.bind(1i64)
262263
.bind("id")
263264
.bind("INT")
264265
.bind(0i32)
266+
.bind(false)
265267
.execute(pool)
266268
.await?;
267269

268270
sqlx::query(
269-
"INSERT INTO ducklake_column (column_id, table_id, column_name, column_type, column_order)
270-
VALUES (?, ?, ?, ?, ?)",
271+
"INSERT INTO ducklake_column (column_id, table_id, column_name, column_type, column_order, nulls_allowed)
272+
VALUES (?, ?, ?, ?, ?, ?)",
271273
)
272274
.bind(2i64)
273275
.bind(1i64)
274276
.bind("name")
275277
.bind("VARCHAR")
276278
.bind(1i32)
279+
.bind(true)
277280
.execute(pool)
278281
.await?;
279282

280283
sqlx::query(
281-
"INSERT INTO ducklake_column (column_id, table_id, column_name, column_type, column_order)
282-
VALUES (?, ?, ?, ?, ?)",
284+
"INSERT INTO ducklake_column (column_id, table_id, column_name, column_type, column_order, nulls_allowed)
285+
VALUES (?, ?, ?, ?, ?, ?)",
283286
)
284287
.bind(3i64)
285288
.bind(1i64)
286289
.bind("email")
287290
.bind("VARCHAR")
288291
.bind(2i32)
292+
.bind(true)
289293
.execute(pool)
290294
.await?;
291295

@@ -422,14 +426,15 @@ async fn populate_from_duckdb_catalog(
422426

423427
for (order, column) in columns.iter().enumerate() {
424428
sqlx::query(
425-
"INSERT INTO ducklake_column (column_id, table_id, column_name, column_type, column_order)
426-
VALUES (?, ?, ?, ?, ?)"
429+
"INSERT INTO ducklake_column (column_id, table_id, column_name, column_type, column_order, nulls_allowed)
430+
VALUES (?, ?, ?, ?, ?, ?)"
427431
)
428432
.bind(column.column_id)
429433
.bind(table.table_id)
430434
.bind(&column.column_name)
431435
.bind(&column.column_type)
432436
.bind(order as i32)
437+
.bind(column.is_nullable)
433438
.execute(pool)
434439
.await?;
435440
}

0 commit comments

Comments
 (0)