JDBC Catalog

Iceberg supports using a table in a relational database to manage Iceberg tables through JDBC. The database that JDBC connects to must support atomic transaction to allow the JDBC catalog implementation to properly support atomic Iceberg table commits and read serializable isolation.

Configurations

Because each database and database service provider might require different configurations, the JDBC catalog allows arbitrary configurations through:

Property Default Description
uri the JDBC connection string
jdbc. any key value pairs to configure the JDBC connection

Examples

Spark

You can start a Spark session with a MySQL JDBC connection using the following configurations:

  1. spark-sql --packages org.apache.iceberg:iceberg-spark-runtime-3.5_2.12:{{ icebergVersion }} \
  2. --conf spark.sql.catalog.my_catalog=org.apache.iceberg.spark.SparkCatalog \
  3. --conf spark.sql.catalog.my_catalog.warehouse=s3://my-bucket/my/key/prefix \
  4. --conf spark.sql.catalog.my_catalog.type=jdbc \
  5. --conf spark.sql.catalog.my_catalog.uri=jdbc:mysql://test.1234567890.us-west-2.rds.amazonaws.com:3306/default \
  6. --conf spark.sql.catalog.my_catalog.jdbc.verifyServerCertificate=true \
  7. --conf spark.sql.catalog.my_catalog.jdbc.useSSL=true \
  8. --conf spark.sql.catalog.my_catalog.jdbc.user=admin \
  9. --conf spark.sql.catalog.my_catalog.jdbc.password=pass

Java API

  1. Class.forName("com.mysql.cj.jdbc.Driver"); // ensure JDBC driver is at runtime classpath
  2. Map<String, String> properties = new HashMap<>();
  3. properties.put(CatalogProperties.CATALOG_IMPL, JdbcCatalog.class.getName());
  4. properties.put(CatalogProperties.URI, "jdbc:mysql://localhost:3306/test");
  5. properties.put(JdbcCatalog.PROPERTY_PREFIX + "user", "admin");
  6. properties.put(JdbcCatalog.PROPERTY_PREFIX + "password", "pass");
  7. properties.put(CatalogProperties.WAREHOUSE_LOCATION, "s3://warehouse/path");
  8. Configuration hadoopConf = new Configuration(); // configs if you use HadoopFileIO
  9. JdbcCatalog catalog = CatalogUtil.buildIcebergCatalog("test_jdbc_catalog", properties, hadoopConf);