Skip to content

Commit 16c0f50

Browse files
[Feature] Support custom catalog name for Iceberg JDBC catalog (#75966)
Signed-off-by: chrisyguo <511955993@qq.com>
1 parent 86051d9 commit 16c0f50

6 files changed

Lines changed: 142 additions & 2 deletions

File tree

docs/en/data_source/catalog/iceberg/iceberg_catalog.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,11 @@ The following table describes the parameter you need to configure in `MetastoreP
433433
- Required: No
434434
- Description: Whether to create the tables `iceberg_namespace_properties` and `iceberg_tables` for storing metadata in the database specified by `iceberg.catalog.uri`. The default value is `false`. Specify `true` if these two tables have not yet been created in the database specified by `iceberg.catalog.uri`.
435435

436+
- `iceberg.catalog.jdbc.catalog-name`
437+
- Required: No
438+
- Description: Explicitly specifies the value of the `catalog_name` column in the Iceberg JDBC metadata tables (`iceberg_tables` and `iceberg_namespace_properties`). When not set, the name of the StarRocks-side catalog (the `<catalog_name>` provided after `CREATE EXTERNAL CATALOG`) is used, which preserves backward compatibility.
439+
- When you need to attach StarRocks to an Iceberg JDBC catalog that has already been created by other engines (such as Spark or Flink) and share the same metadata, you must set this parameter to the catalog name used by the other engine. Otherwise the underlying `WHERE catalog_name = ?` query cannot match the existing metadata, and StarRocks will not be able to see any databases or tables.
440+
436441
The following example creates an Iceberg catalog named `iceberg_jdbc` and uses JDBC as metastore:
437442

438443
```SQL
@@ -452,6 +457,25 @@ PROPERTIES
452457
```
453458
If using MySQL or other custom JDBC drivers, the corresponding JAR files need to be placed in the `fe/lib` and `be/lib/jni-packages` directories.
454459

460+
The following example shows how to attach StarRocks to an Iceberg JDBC catalog that has already been created by another engine (for example Spark) whose underlying `catalog_name` is `"spark_ice"`. In this case, the StarRocks-side catalog name `sr_side_view` may differ from the underlying `catalog_name`, as long as you explicitly specify `iceberg.catalog.jdbc.catalog-name`:
461+
462+
```SQL
463+
CREATE EXTERNAL CATALOG sr_side_view
464+
PROPERTIES
465+
(
466+
"type" = "iceberg",
467+
"iceberg.catalog.type" = "jdbc",
468+
"iceberg.catalog.warehouse" = "s3://my_bucket/warehouse_location",
469+
"iceberg.catalog.uri" = "jdbc:mysql://ip:port/db_name",
470+
"iceberg.catalog.jdbc.user" = "username",
471+
"iceberg.catalog.jdbc.password" = "password",
472+
"iceberg.catalog.jdbc.catalog-name" = "spark_ice",
473+
"aws.s3.endpoint" = "<s3_endpoint>",
474+
"aws.s3.access_key" = "<iam_user_access_key>",
475+
"aws.s3.secret_key" = "<iam_user_secret_key>"
476+
);
477+
```
478+
455479
</TabItem>
456480

457481
</Tabs>

docs/ja/data_source/catalog/iceberg/iceberg_catalog.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,11 @@ SHOW DATABASES FROM r2;
432432
- 必須:いいえ
433433
- 説明:`iceberg.catalog.uri` で指定されたデータベースにメタデータを格納するためのテーブル `iceberg_namespace_properties` および `iceberg_tables` を作成するかどうか。デフォルト値は `false` です。`iceberg.catalog.uri` で指定されたデータベースにこれらの 2 つのテーブルがまだ作成されていない場合は `true` を指定してください。
434434

435+
- `iceberg.catalog.jdbc.catalog-name`
436+
- 必須:いいえ
437+
- 説明:Iceberg JDBC のメタデータテーブル(`iceberg_tables` および `iceberg_namespace_properties`)の `catalog_name` 列の値を明示的に指定します。未設定の場合は、StarRocks 側のカタログ名(`CREATE EXTERNAL CATALOG` の後に指定した `<catalog_name>`)が使用され、後方互換性が維持されます。
438+
- StarRocks を、他のエンジン(例:Spark、Flink)で既に作成された Iceberg JDBC Catalog に接続し、同じメタデータを共有したい場合には、このパラメーターに相手側で使用しているカタログ名を設定する必要があります。設定しない場合、内部で発行される `WHERE catalog_name = ?` クエリが既存のメタデータにマッチせず、StarRocks 側から一切のデータベースやテーブルが見えなくなります。
439+
435440
次の例は、Iceberg catalog `iceberg_jdbc` を作成し、メタストアとして JDBC を使用します。
436441

437442
```SQL
@@ -452,6 +457,25 @@ PROPERTIES
452457

453458
MySQL やその他のカスタム JDBC ドライバを使用する場合、対応する JAR ファイルを `fe/lib` ディレクトリおよび `be/lib/jni-packages` ディレクトリに配置する必要があります。
454459

460+
次の例は、他のエンジン(例:Spark)で既に作成され、内部の `catalog_name``"spark_ice"` になっている Iceberg JDBC Catalog に StarRocks を接続する方法を示しています。この場合、StarRocks 側のカタログ名 `sr_side_view` は内部の `catalog_name` と異なっていても構いません。`iceberg.catalog.jdbc.catalog-name` を明示的に指定するだけで接続できます。
461+
462+
```SQL
463+
CREATE EXTERNAL CATALOG sr_side_view
464+
PROPERTIES
465+
(
466+
"type" = "iceberg",
467+
"iceberg.catalog.type" = "jdbc",
468+
"iceberg.catalog.warehouse" = "s3://my_bucket/warehouse_location",
469+
"iceberg.catalog.uri" = "jdbc:mysql://ip:port/db_name",
470+
"iceberg.catalog.jdbc.user" = "username",
471+
"iceberg.catalog.jdbc.password" = "password",
472+
"iceberg.catalog.jdbc.catalog-name" = "spark_ice",
473+
"aws.s3.endpoint" = "<s3_endpoint>",
474+
"aws.s3.access_key" = "<iam_user_access_key>",
475+
"aws.s3.secret_key" = "<iam_user_secret_key>"
476+
);
477+
```
478+
455479
</TabItem>
456480

457481
</Tabs>

docs/zh/data_source/catalog/iceberg/iceberg_catalog.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,14 @@ SHOW DATABASES FROM r2;
472472

473473
描述:是否在 `iceberg.catalog.uri` 指定的数据库中创建用于存储元数据的表 `iceberg_namespace_properties``iceberg_tables`,默认值为`false`。当`iceberg.catalog.uri` 指定的数据库中尚未创建上述两张表时需要指定为`true`
474474

475+
##### iceberg.catalog.jdbc.catalog-name
476+
477+
必需:否
478+
479+
描述:显式指定 Iceberg JDBC 底层元数据表(`iceberg_tables``iceberg_namespace_properties`)中 `catalog_name` 字段的值。未设置时,默认使用 StarRocks 侧的 Catalog 名(即 `CREATE EXTERNAL CATALOG` 后的 `<catalog_name>`),保持向后兼容。
480+
481+
当您需要在 StarRocks 中接入由其他引擎(例如 Spark、Flink)已经建立的 Iceberg JDBC Catalog、并复用同一份元数据时,需要将该参数设置为对方使用的 catalog name,否则底层查询 SQL `WHERE catalog_name = ?` 将无法命中已有元数据,导致 StarRocks 侧看不到任何库表。
482+
475483
以下示例创建了一个名为 `iceberg_jdbc` 的 Iceberg catalog,并使用 JDBC 作为元存储:
476484

477485
```SQL
@@ -489,7 +497,27 @@ PROPERTIES
489497
"aws.s3.secret_key" = "<iam_user_secret_key>"
490498
);
491499
```
492-
若使用MySQL或其他自定义的JDBC驱动程序,需要将相应的JAR包放置于 `fe/lib``be/lib/jni-packages` 目录下。
500+
501+
若使用 MySQL 或其他自定义的 JDBC 驱动程序,需要将相应的 JAR 包放置于 `fe/lib``be/lib/jni-packages` 目录下。
502+
503+
以下示例演示了如何接入由其他引擎(例如 Spark)已经建立、底层 `catalog_name = "spark_ice"` 的 Iceberg JDBC Catalog。此时 StarRocks 侧 Catalog 名 `sr_side_view` 可以与底层 `catalog_name` 不同,只需通过 `iceberg.catalog.jdbc.catalog-name` 显式指定即可:
504+
505+
```SQL
506+
CREATE EXTERNAL CATALOG sr_side_view
507+
PROPERTIES
508+
(
509+
"type" = "iceberg",
510+
"iceberg.catalog.type" = "jdbc",
511+
"iceberg.catalog.warehouse" = "s3://my_bucket/warehouse_location",
512+
"iceberg.catalog.uri" = "jdbc:mysql://ip:port/db_name",
513+
"iceberg.catalog.jdbc.user" = "username",
514+
"iceberg.catalog.jdbc.password" = "password",
515+
"iceberg.catalog.jdbc.catalog-name" = "spark_ice",
516+
"aws.s3.endpoint" = "<s3_endpoint>",
517+
"aws.s3.access_key" = "<iam_user_access_key>",
518+
"aws.s3.secret_key" = "<iam_user_secret_key>"
519+
);
520+
```
493521

494522
</TabItem>
495523

fe/fe-core/src/main/java/com/starrocks/connector/iceberg/IcebergCatalogProperties.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class IcebergCatalogProperties {
3333
public static final String HIVE_METASTORE_TIMEOUT = "hive.metastore.timeout";
3434
public static final String ICEBERG_CUSTOM_PROPERTIES_PREFIX = "iceberg.catalog.";
3535
public static final String ICEBERG_JDBC_PASSWORD = "jdbc.password";
36+
public static final String ICEBERG_JDBC_CATALOG_NAME = "jdbc.catalog-name";
3637
public static final String ENABLE_ICEBERG_METADATA_CACHE = "enable_iceberg_metadata_cache";
3738
public static final String ENABLE_ICEBERG_TABLE_CACHE = "enable_iceberg_table_cache";
3839
public static final String ICEBERG_META_CACHE_TTL = "iceberg_meta_cache_ttl_sec"; // implicit for user

fe/fe-core/src/main/java/com/starrocks/connector/iceberg/jdbc/IcebergJdbcCatalog.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
import static com.starrocks.connector.ConnectorTableId.CONNECTOR_ID_GENERATOR;
5454
import static com.starrocks.connector.iceberg.IcebergCatalogProperties.ICEBERG_CUSTOM_PROPERTIES_PREFIX;
55+
import static com.starrocks.connector.iceberg.IcebergCatalogProperties.ICEBERG_JDBC_CATALOG_NAME;
5556
import static com.starrocks.connector.iceberg.IcebergMetadata.LOCATION_PROPERTY;
5657
import static org.apache.iceberg.CatalogProperties.WAREHOUSE_LOCATION;
5758

@@ -93,8 +94,11 @@ public IcebergJdbcCatalog(String name, Configuration conf, Map<String, String> p
9394
ICEBERG_CUSTOM_PROPERTIES_PREFIX + WAREHOUSE_LOCATION));
9495
}
9596

96-
this.delegate = (JdbcCatalog) CatalogUtil.loadCatalog(JdbcCatalog.class.getName(), name, copiedProperties, conf);
97+
String jdbcCatalogName = copiedProperties.getOrDefault(ICEBERG_JDBC_CATALOG_NAME, name);
98+
copiedProperties.remove(ICEBERG_JDBC_CATALOG_NAME);
9799

100+
this.delegate = (JdbcCatalog) CatalogUtil.loadCatalog(
101+
JdbcCatalog.class.getName(), jdbcCatalogName, copiedProperties, conf);
98102
}
99103

100104

fe/fe-core/src/test/java/com/starrocks/connector/iceberg/IcebergJdbcCatalogTest.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.Arrays;
4444
import java.util.HashMap;
4545
import java.util.List;
46+
import java.util.Map;
4647

4748
import static com.starrocks.connector.iceberg.IcebergCatalogProperties.ICEBERG_CUSTOM_PROPERTIES_PREFIX;
4849
import static com.starrocks.connector.iceberg.IcebergMetadata.LOCATION_PROPERTY;
@@ -284,4 +285,62 @@ public void testDeleteUncommittedDataFiles(@Mocked JdbcCatalog jdbcCatalog, @Moc
284285
Arrays.asList("/tmp/iceberg/db/table/part-00000", "/tmp/iceberg/db/table/part-00001"));
285286
}
286287

288+
@Test
289+
public void testJdbcCatalogNameDefaultToStarRocksCatalogName(@Mocked JdbcCatalog jdbcCatalog) {
290+
final String[] capturedName = new String[1];
291+
final Map<String, String>[] capturedProps = new Map[1];
292+
293+
new Expectations() {
294+
{
295+
jdbcCatalog.initialize(anyString, (Map<String, String>) any);
296+
result = new mockit.Delegate<Void>() {
297+
@SuppressWarnings("unused")
298+
void initialize(String name, Map<String, String> props) {
299+
capturedName[0] = name;
300+
capturedProps[0] = props;
301+
}
302+
};
303+
minTimes = 0;
304+
}
305+
};
306+
307+
new IcebergJdbcCatalog("sr_catalog", new Configuration(),
308+
ImmutableMap.of("iceberg.catalog.warehouse", LOCATION,
309+
"iceberg.catalog.uri", URI));
310+
311+
assertEquals("sr_catalog", capturedName[0]);
312+
Assertions.assertNotNull(capturedProps[0]);
313+
Assertions.assertFalse(capturedProps[0].containsKey("jdbc.catalog-name"));
314+
}
315+
316+
@Test
317+
public void testJdbcCatalogNameOverride(@Mocked JdbcCatalog jdbcCatalog) {
318+
final String[] capturedName = new String[1];
319+
final Map<String, String>[] capturedProps = new Map[1];
320+
321+
new Expectations() {
322+
{
323+
jdbcCatalog.initialize(anyString, (Map<String, String>) any);
324+
result = new mockit.Delegate<Void>() {
325+
@SuppressWarnings("unused")
326+
void initialize(String name, java.util.Map<String, String> props) {
327+
capturedName[0] = name;
328+
capturedProps[0] = props;
329+
}
330+
};
331+
minTimes = 0;
332+
}
333+
};
334+
335+
new IcebergJdbcCatalog("sr_side_view", new Configuration(),
336+
ImmutableMap.of(
337+
"iceberg.catalog.warehouse", LOCATION,
338+
"iceberg.catalog.uri", URI,
339+
"iceberg.catalog.jdbc.catalog-name", "spark_ice"));
340+
341+
assertEquals("spark_ice", capturedName[0]);
342+
Assertions.assertNotNull(capturedProps[0]);
343+
Assertions.assertFalse(capturedProps[0].containsKey("jdbc.catalog-name"));
344+
}
345+
287346
}

0 commit comments

Comments
 (0)