Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,66 @@ project(':iceberg-hive-metastore') {
}
}

project(':iceberg-hivelink') {
dependencies {
compile project(':iceberg-hive-metastore')

compileOnly "org.apache.avro:avro"
compileOnly("org.apache.hadoop:hadoop-client") {
exclude group: 'org.apache.avro', module: 'avro'
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
}

compileOnly("org.apache.hive:hive-metastore") {
exclude group: 'org.apache.avro', module: 'avro'
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
exclude group: 'org.pentaho' // missing dependency
exclude group: 'org.apache.hbase'
exclude group: 'org.apache.logging.log4j'
exclude group: 'co.cask.tephra'
exclude group: 'com.google.code.findbugs', module: 'jsr305'
exclude group: 'org.eclipse.jetty.aggregate', module: 'jetty-all'
exclude group: 'org.eclipse.jetty.orbit', module: 'javax.servlet'
exclude group: 'org.apache.parquet', module: 'parquet-hadoop-bundle'
exclude group: 'com.tdunning', module: 'json'
exclude group: 'javax.transaction', module: 'transaction-api'
exclude group: 'com.zaxxer', module: 'HikariCP'
}

// By default, hive-exec is a fat/uber jar and it exports a guava library
// that's really old. We use the core classifier to be able to override our guava
// version. Luckily, hive-exec seems to work okay so far with this version of guava
// See: https://github.com/apache/hive/blob/master/ql/pom.xml#L911 for more context.
testCompile("org.apache.hive:hive-exec::core") {
exclude group: 'org.apache.avro', module: 'avro'
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
exclude group: 'org.pentaho' // missing dependency
exclude group: 'org.apache.hive', module: 'hive-llap-tez'
exclude group: 'org.apache.logging.log4j'
exclude group: 'com.google.protobuf', module: 'protobuf-java'
exclude group: 'org.apache.calcite'
exclude group: 'org.apache.calcite.avatica'
exclude group: 'com.google.code.findbugs', module: 'jsr305'
}

testCompile("org.apache.hive:hive-metastore") {
exclude group: 'org.apache.avro', module: 'avro'
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
exclude group: 'org.pentaho' // missing dependency
exclude group: 'org.apache.hbase'
exclude group: 'org.apache.logging.log4j'
exclude group: 'co.cask.tephra'
exclude group: 'com.google.code.findbugs', module: 'jsr305'
exclude group: 'org.eclipse.jetty.aggregate', module: 'jetty-all'
exclude group: 'org.eclipse.jetty.orbit', module: 'javax.servlet'
exclude group: 'org.apache.parquet', module: 'parquet-hadoop-bundle'
exclude group: 'com.tdunning', module: 'json'
exclude group: 'javax.transaction', module: 'transaction-api'
exclude group: 'com.zaxxer', module: 'HikariCP'
}
}
}

project(':iceberg-mr') {
configurations {
testCompile {
Expand Down Expand Up @@ -812,6 +872,7 @@ if (jdkVersion == '8') {
compile project(':iceberg-arrow')
compile project(':iceberg-hive-metastore')
compile project(':iceberg-spark')
compile project(':iceberg-hivelink')

compileOnly "org.apache.avro:avro"
compileOnly("org.apache.spark:spark-hive_2.11") {
Expand Down Expand Up @@ -921,6 +982,7 @@ project(':iceberg-spark3') {
compile project(':iceberg-arrow')
compile project(':iceberg-hive-metastore')
compile project(':iceberg-spark')
compile project(':iceberg-hivelink')

compileOnly "org.apache.avro:avro"
compileOnly("org.apache.spark:spark-hive_2.12") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.github.benmanes.caffeine.cache.Caffeine;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.iceberg.hive.legacy.LegacyHiveCatalog;

public final class HiveCatalogs {

Expand All @@ -35,20 +34,12 @@ private HiveCatalogs() {
private static final Cache<String, HiveMetadataPreservingCatalog> HIVE_METADATA_PRESERVING_CATALOG_CACHE =
Caffeine.newBuilder().build();

private static final Cache<String, HiveCatalog> LEGACY_CATALOG_CACHE = Caffeine.newBuilder().build();

public static HiveCatalog loadCatalog(Configuration conf) {
// metastore URI can be null in local mode
String metastoreUri = conf.get(HiveConf.ConfVars.METASTOREURIS.varname, "");
return CATALOG_CACHE.get(metastoreUri, uri -> new HiveCatalog(conf));
}

public static HiveCatalog loadLegacyCatalog(Configuration conf) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a backward incompatible change? Do you have a plan on how to roll it out with Spark?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a backward incompatible change. It is not used directly from spark but from a wrapper layer. We can change the wrapper layer to accommodate this change.

// metastore URI can be null in local mode
String metastoreUri = conf.get(HiveConf.ConfVars.METASTOREURIS.varname, "");
return LEGACY_CATALOG_CACHE.get(metastoreUri, uri -> new LegacyHiveCatalog(conf));
}

/**
* @deprecated Use {@link #loadHiveMetadataPreservingCatalog(Configuration)} instead
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.iceberg.hive.legacy;
package org.apache.iceberg.hivelink;

import org.apache.iceberg.FileFormat;
import org.apache.iceberg.StructLike;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.iceberg.hive.legacy;
package org.apache.iceberg.hivelink;

import java.io.IOException;
import java.io.UncheckedIOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.iceberg.hive.legacy;
package org.apache.iceberg.hivelink;

import java.time.Instant;
import java.time.OffsetDateTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.iceberg.hive.legacy;
package org.apache.iceberg.hivelink;

import java.util.List;
import org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.iceberg.hive.legacy;
package org.apache.iceberg.hivelink;

import java.util.List;
import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.iceberg.hive.legacy;
package org.apache.iceberg.hivelink;

import java.util.List;
import org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
* under the License.
*/

package org.apache.iceberg.hive.legacy;
package org.apache.iceberg.hivelink;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import java.util.Map;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.iceberg.PartitionSpec;
import org.apache.iceberg.Schema;
import org.apache.iceberg.Table;
Expand All @@ -41,10 +44,20 @@ public class LegacyHiveCatalog extends HiveCatalog {

private static final Logger LOG = LoggerFactory.getLogger(LegacyHiveCatalog.class);

// hivelink refactoring: this is moved from HiveCatalogs
private static final Cache<String, HiveCatalog> LEGACY_CATALOG_CACHE = Caffeine.newBuilder().build();

public LegacyHiveCatalog(Configuration conf) {
super(conf);
}

// hivelink refactoring: this is moved from HiveCatalogs
public static HiveCatalog loadLegacyCatalog(Configuration conf) {
// metastore URI can be null in local mode
String metastoreUri = conf.get(HiveConf.ConfVars.METASTOREURIS.varname, "");
return LEGACY_CATALOG_CACHE.get(metastoreUri, uri -> new LegacyHiveCatalog(conf));
}

@Override
@SuppressWarnings("CatchBlockLogException")
public Table loadTable(TableIdentifier identifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.iceberg.hive.legacy;
package org.apache.iceberg.hivelink;

import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.iceberg.hive.legacy;
package org.apache.iceberg.hivelink;

import java.time.LocalDate;
import java.time.LocalDateTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.iceberg.hive.legacy;
package org.apache.iceberg.hivelink;

import org.apache.iceberg.BaseFileScanTask;
import org.apache.iceberg.DataTableScan;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.iceberg.hive.legacy;
package org.apache.iceberg.hivelink;

import java.util.HashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.iceberg.hive.legacy;
package org.apache.iceberg.hivelink;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -52,7 +52,7 @@
class MergeHiveSchemaWithAvro extends HiveSchemaWithPartnerVisitor<Schema, Schema.Field, Schema, Schema.Field> {

static Schema visit(StructTypeInfo typeInfo, Schema schema) {
return HiveSchemaWithPartnerVisitor.visit(typeInfo, schema, new MergeHiveSchemaWithAvro(),
return visit(typeInfo, schema, new MergeHiveSchemaWithAvro(),
AvroPartnerAccessor.INSTANCE);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.iceberg.hivelink;

import java.util.HashMap;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
import org.apache.hadoop.hive.metastore.api.Database;
import org.apache.iceberg.hive.HiveCatalog;
import org.junit.AfterClass;
import org.junit.BeforeClass;


/**
* hivelink refactoring:
* This class is copied from iceberg-hive-metastore module test code
*/
public abstract class HiveMetastoreTest {

protected static final String DB_NAME = "hivedb";

protected static HiveMetaStoreClient metastoreClient;
protected static HiveCatalog catalog;
protected static HiveConf hiveConf;
protected static TestHiveMetastore metastore;

@BeforeClass
public static void startMetastore() throws Exception {
HiveMetastoreTest.metastore = new TestHiveMetastore();
metastore.start();
HiveMetastoreTest.hiveConf = metastore.hiveConf();
HiveMetastoreTest.metastoreClient = new HiveMetaStoreClient(hiveConf);
String dbPath = metastore.getDatabasePath(DB_NAME);
Database db = new Database(DB_NAME, "description", dbPath, new HashMap<>());
metastoreClient.createDatabase(db);
HiveMetastoreTest.catalog = new HiveCatalog(hiveConf);
}

@AfterClass
public static void stopMetastore() {
catalog.close();
HiveMetastoreTest.catalog = null;

metastoreClient.close();
HiveMetastoreTest.metastoreClient = null;

metastore.stop();
HiveMetastoreTest.metastore = null;
}
}
Loading