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
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* 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.mr.hive;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.apache.iceberg.FileFormat;
import org.apache.iceberg.Schema;
import org.apache.iceberg.data.Record;
import org.apache.iceberg.mr.TestHelper;
import org.apache.iceberg.types.Types;
import org.junit.rules.TemporaryFolder;

import static org.apache.iceberg.types.Types.NestedField.optional;

public class HiveIcebergStorageHandlerTestUtils {
static final FileFormat[] FILE_FORMATS =
new FileFormat[] {FileFormat.AVRO, FileFormat.ORC, FileFormat.PARQUET};

static final Schema CUSTOMER_SCHEMA = new Schema(
optional(1, "customer_id", Types.LongType.get()),
optional(2, "first_name", Types.StringType.get()),
optional(3, "last_name", Types.StringType.get())
);

static final List<Record> CUSTOMER_RECORDS = TestHelper.RecordsBuilder.newInstance(CUSTOMER_SCHEMA)
.add(0L, "Alice", "Brown")
.add(1L, "Bob", "Green")
.add(2L, "Trudy", "Pink")
.build();

private HiveIcebergStorageHandlerTestUtils() {
// Empty constructor for the utility class
}

static TestHiveShell shell() {
TestHiveShell shell = new TestHiveShell();
shell.setHiveConfValue("hive.notification.event.poll.interval", "-1");
shell.setHiveConfValue("hive.tez.exec.print.summary", "true");
shell.start();
return shell;
}

static TestTables testTables(TestHiveShell shell, TestTables.TestTableType testTableType, TemporaryFolder temp)
throws IOException {

return testTableType.instance(shell.metastore().hiveConf(), temp);
}

static void init(TestHiveShell shell, TestTables testTables, TemporaryFolder temp, String engine) {
shell.openSession();

for (Map.Entry<String, String> property : testTables.properties().entrySet()) {
shell.setHiveSessionValue(property.getKey(), property.getValue());
}

shell.setHiveSessionValue("hive.execution.engine", engine);
shell.setHiveSessionValue("hive.jar.directory", temp.getRoot().getAbsolutePath());
shell.setHiveSessionValue("tez.staging-dir", temp.getRoot().getAbsolutePath());

// temporarily disabling vectorization in Tez, since it doesn't work with projection pruning (fix: TEZ-4248)
// TODO: remove this once TEZ-4248 has been released and the Tez dependencies updated here
if (engine.equals("tez")) {
shell.setHiveSessionValue("hive.vectorized.execution.enabled", "false");
}

}

static void close(TestHiveShell shell) throws Exception {
shell.closeSession();
shell.metastore().reset();
// HiveServer2 thread pools are using thread local Hive -> HMSClient objects. These are not cleaned up when the
// HiveServer2 is stopped. Only Finalizer closes the HMS connections.
System.gc();
}
}
Loading