forked from apache/beam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Managed Iceberg] support BQMS catalog (apache#33511)
* Add BQMS catalog * trigger integration tests * build fix * use shaded jar * shadowClosure * use global timeout for tests * define version in BeamModulePlugin * address comments
- Loading branch information
1 parent
48e18c4
commit e9cba68
Showing
8 changed files
with
410 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* License); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an AS IS BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
plugins { | ||
id 'org.apache.beam.module' | ||
} | ||
|
||
applyJavaNature( | ||
automaticModuleName: 'org.apache.beam.sdk.io.iceberg.bqms', | ||
shadowClosure: {}, | ||
exportJavadoc: false, | ||
publish: false, // it's an intermediate jar for io-expansion-service | ||
validateShadowJar: false | ||
) | ||
|
||
def libDir = "$buildDir/libs" | ||
def bqmsFileName = "iceberg-bqms-catalog-${iceberg_bqms_catalog_version}.jar" | ||
task downloadBqmsJar(type: Copy) { | ||
// TODO: remove this workaround and downlooad normally when the catalog gets open-sourced: | ||
// (https://github.com/apache/iceberg/pull/11039) | ||
def jarUrl = "https://storage.googleapis.com/spark-lib/bigquery/iceberg-bigquery-catalog-${iceberg_bqms_catalog_version}.jar" | ||
def outputDir = file("$libDir") | ||
outputDir.mkdirs() | ||
def destFile = new File(outputDir, bqmsFileName) | ||
|
||
if (!destFile.exists()) { | ||
try { | ||
ant.get(src: jarUrl, dest: destFile) | ||
println "Successfully downloaded BQMS catalog jar: $destFile" | ||
} catch (Exception e) { | ||
println "Could not download $jarUrl: ${e.message}" | ||
} | ||
} | ||
} | ||
|
||
repositories { | ||
flatDir { | ||
dirs "$libDir" | ||
} | ||
} | ||
|
||
compileJava.dependsOn downloadBqmsJar | ||
|
||
dependencies { | ||
implementation files("$libDir/$bqmsFileName") | ||
} | ||
|
||
description = "Apache Beam :: SDKs :: Java :: IO :: Iceberg :: BigQuery Metastore" | ||
ext.summary = "A copy of the BQMS catalog." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...a/io/iceberg/src/test/java/org/apache/beam/sdk/io/iceberg/BigQueryMetastoreCatalogIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.beam.sdk.io.iceberg.catalog; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.iceberg.CatalogUtil; | ||
import org.apache.iceberg.catalog.Catalog; | ||
import org.apache.iceberg.catalog.Namespace; | ||
import org.apache.iceberg.catalog.TableIdentifier; | ||
|
||
public class BigQueryMetastoreCatalogIT extends IcebergCatalogBaseIT { | ||
static final String BQMS_CATALOG = "org.apache.iceberg.gcp.bigquery.BigQueryMetastoreCatalog"; | ||
static final String DATASET = "managed_iceberg_bqms_tests_no_delete"; | ||
static final long SALT = System.nanoTime(); | ||
|
||
@Override | ||
public String tableId() { | ||
return DATASET + "." + testName.getMethodName() + "_" + SALT; | ||
} | ||
|
||
@Override | ||
public Catalog createCatalog() { | ||
return CatalogUtil.loadCatalog( | ||
BQMS_CATALOG, | ||
"bqms_" + catalogName, | ||
ImmutableMap.<String, String>builder() | ||
.put("gcp_project", options.getProject()) | ||
.put("gcp_location", "us-central1") | ||
.put("warehouse", warehouse) | ||
.build(), | ||
new Configuration()); | ||
} | ||
|
||
@Override | ||
public void catalogCleanup() throws IOException { | ||
for (TableIdentifier tableIdentifier : catalog.listTables(Namespace.of(DATASET))) { | ||
// only delete tables that were created in this test run | ||
if (tableIdentifier.name().contains(String.valueOf(SALT))) { | ||
catalog.dropTable(tableIdentifier); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public Map<String, Object> managedIcebergConfig(String tableId) { | ||
return ImmutableMap.<String, Object>builder() | ||
.put("table", tableId) | ||
.put( | ||
"catalog_properties", | ||
ImmutableMap.<String, String>builder() | ||
.put("gcp_project", options.getProject()) | ||
.put("gcp_location", "us-central1") | ||
.put("warehouse", warehouse) | ||
.put("catalog-impl", BQMS_CATALOG) | ||
.build()) | ||
.build(); | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
sdks/java/io/iceberg/src/test/java/org/apache/beam/sdk/io/iceberg/catalog/HiveCatalogIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.beam.sdk.io.iceberg.catalog; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
import org.apache.beam.sdk.io.iceberg.catalog.hiveutils.HiveMetastoreExtension; | ||
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap; | ||
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Maps; | ||
import org.apache.hadoop.hive.conf.HiveConf; | ||
import org.apache.hadoop.hive.metastore.api.Database; | ||
import org.apache.iceberg.CatalogProperties; | ||
import org.apache.iceberg.CatalogUtil; | ||
import org.apache.iceberg.catalog.Catalog; | ||
import org.apache.iceberg.hive.HiveCatalog; | ||
|
||
/** | ||
* Read and write tests using {@link HiveCatalog}. | ||
* | ||
* <p>Spins up a local Hive metastore to manage the Iceberg table. Warehouse path is set to a GCS | ||
* bucket. | ||
*/ | ||
public class HiveCatalogIT extends IcebergCatalogBaseIT { | ||
private static HiveMetastoreExtension hiveMetastoreExtension; | ||
private static final String TEST_DB = "test_db"; | ||
|
||
@Override | ||
public String tableId() { | ||
return String.format("%s.%s", TEST_DB, testName.getMethodName()); | ||
} | ||
|
||
@Override | ||
public void catalogSetup() throws Exception { | ||
hiveMetastoreExtension = new HiveMetastoreExtension(warehouse); | ||
String dbPath = hiveMetastoreExtension.metastore().getDatabasePath(TEST_DB); | ||
Database db = new Database(TEST_DB, "description", dbPath, Maps.newHashMap()); | ||
hiveMetastoreExtension.metastoreClient().createDatabase(db); | ||
} | ||
|
||
@Override | ||
public Catalog createCatalog() { | ||
return CatalogUtil.loadCatalog( | ||
HiveCatalog.class.getName(), | ||
"hive_" + catalogName, | ||
ImmutableMap.of( | ||
CatalogProperties.CLIENT_POOL_CACHE_EVICTION_INTERVAL_MS, | ||
String.valueOf(TimeUnit.SECONDS.toMillis(10))), | ||
hiveMetastoreExtension.hiveConf()); | ||
} | ||
|
||
@Override | ||
public void catalogCleanup() throws Exception { | ||
if (hiveMetastoreExtension != null) { | ||
hiveMetastoreExtension.cleanup(); | ||
} | ||
} | ||
|
||
@Override | ||
public Map<String, Object> managedIcebergConfig(String tableId) { | ||
String metastoreUri = hiveMetastoreExtension.hiveConf().getVar(HiveConf.ConfVars.METASTOREURIS); | ||
|
||
Map<String, String> confProperties = | ||
ImmutableMap.<String, String>builder() | ||
.put(HiveConf.ConfVars.METASTOREURIS.varname, metastoreUri) | ||
.build(); | ||
|
||
return ImmutableMap.<String, Object>builder() | ||
.put("table", tableId) | ||
.put("name", "hive_" + catalogName) | ||
.put("config_properties", confProperties) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.