A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix(frontend): use load_catalog for pyiceberg when no catalog options set (#10409)
Myles Scolnickd24fab414bbf
diff --git a/frontend/src/components/editor/connections/database/__tests__/__snapshots__/as-code.test.ts.snap b/frontend/src/components/editor/connections/database/__tests__/__snapshots__/as-code.test.ts.snapindex 35c98af1a8..64b3298186 100644--- a/frontend/src/components/editor/connections/database/__tests__/__snapshots__/as-code.test.ts.snap+++ b/frontend/src/components/editor/connections/database/__tests__/__snapshots__/as-code.test.ts.snap@@ -89,6 +89,12 @@ DATABASE_URL = "data.duckdb"engine = duckdb.connect(DATABASE_URL, read_only=True)"`;+exports[`generateDatabaseCode > basic connections > iceberg configured catalog 1`] = `+"from pyiceberg.catalog import load_catalog++catalog = load_catalog("my_catalog")"+`;+exports[`generateDatabaseCode > basic connections > iceberg dynamodb 1`] = `"from pyiceberg.catalog.dynamodb import DynamoDBCatalogdiff --git a/frontend/src/components/editor/connections/database/__tests__/as-code.test.ts b/frontend/src/components/editor/connections/database/__tests__/as-code.test.tsindex 5f768b8198..08b85359a7 100644--- a/frontend/src/components/editor/connections/database/__tests__/as-code.test.ts+++ b/frontend/src/components/editor/connections/database/__tests__/as-code.test.ts@@ -166,6 +166,17 @@ describe("generateDatabaseCode", () => {},};+ const icebergConfiguredCatalogConnection: DatabaseConnection = {+ type: "iceberg",+ name: "my_catalog",+ catalog: {+ type: "REST",+ uri: undefined,+ warehouse: undefined,+ token: undefined,+ },+ };+const icebergSqlConnection: DatabaseConnection = {type: "iceberg",name: "my_catalog",@@ -310,6 +321,11 @@ describe("generateDatabaseCode", () => {["chdb", chdbConnection, "chdb"],["timeplus", timeplusConnection, "sqlalchemy"],["trino", trinoConnection, "sqlmodel"],+ [+ "iceberg configured catalog",+ icebergConfiguredCatalogConnection,+ "pyiceberg",+ ],["iceberg rest", icebergRestConnection, "pyiceberg"],["iceberg sql", icebergSqlConnection, "pyiceberg"],["iceberg hive", icebergHiveConnection, "pyiceberg"],diff --git a/frontend/src/components/editor/connections/database/as-code.ts b/frontend/src/components/editor/connections/database/as-code.tsindex 5ca36335f7..f136a28f23 100644--- a/frontend/src/components/editor/connections/database/as-code.ts+++ b/frontend/src/components/editor/connections/database/as-code.ts@@ -603,7 +603,22 @@ class TrinoGenerator extends CodeGenerator<"trino"> {}class PyIcebergGenerator extends CodeGenerator<"iceberg"> {+ private getCatalogOptions(): Record<+ string,+ string | number | boolean | undefined+ > {+ return Object.fromEntries(+ Object.entries(this.connection.catalog).filter(+ ([key, value]) => value != null && value !== "" && key !== "type",+ ),+ );+ }+generateImports(): string[] {+ if (Object.keys(this.getCatalogOptions()).length === 0) {+ return ["from pyiceberg.catalog import load_catalog"];+ }+switch (this.connection.catalog.type) {case "REST":return ["from pyiceberg.catalog.rest import RestCatalog"];@@ -621,15 +636,12 @@ class PyIcebergGenerator extends CodeGenerator<"iceberg"> {}generateConnectionCode(): string {- let options: Record<string, string | number | boolean | undefined> = {- ...this.connection.catalog,- };- // Remove k='type' and v=nullish values- options = Object.fromEntries(- Object.entries(options).filter(- ([k, v]) => v != null && v !== "" && k !== "type",- ),- );+ const name = `"${this.connection.name}"`;+ const options = this.getCatalogOptions();+ if (Object.keys(options).length === 0) {+ return `catalog = load_catalog(${name})`;+ }+// Convert to secrets if they are secretsfor (const [k, v] of Object.entries(options)) {if (isSecret(v)) {@@ -645,8 +657,6 @@ class PyIcebergGenerator extends CodeGenerator<"iceberg"> {(line) => `${indent}${line}`,);- const name = `"${this.connection.name}"`;-switch (this.connection.catalog.type) {case "REST":return dedent(`