Skip to content
Open
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
Expand Up @@ -23,12 +23,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.hadoop.hive.common.StringInternUtils;
import org.apache.hadoop.hive.ql.exec.SerializationUtilities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -53,7 +50,6 @@ public class ProjectionPusher {

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

private final Map<Path, PartitionDesc> pathToPartitionInfo = new LinkedHashMap<>();
/**
* MapWork is the Hive object which describes input files,
* columns projections, and filters.
Expand All @@ -69,12 +65,6 @@ private void updateMrWork(final JobConf job) {
final String plan = HiveConf.getVar(job, HiveConf.ConfVars.PLAN);
if (mapWork == null && plan != null && plan.length() > 0) {
mapWork = Utilities.getMapWork(job);
pathToPartitionInfo.clear();
for (final Map.Entry<Path, PartitionDesc> entry : mapWork.getPathToPartitionInfo().entrySet()) {
// key contains scheme (such as pfile://) and we want only the path portion fix in HIVE-6366
pathToPartitionInfo.put(StringInternUtils.internUriStringsInPath(
Path.getPathWithoutSchemeAndAuthority(entry.getKey())), entry.getValue());
}
}
}

Expand Down Expand Up @@ -192,8 +182,11 @@ public JobConf pushProjectionsAndFilters(JobConf jobConf, Path path)
throws IOException {
updateMrWork(jobConf); // TODO: refactor this in HIVE-6366
final JobConf cloneJobConf = new JobConf(jobConf);
final PartitionDesc part = HiveFileFormatUtils.getFromPathRecursively(
pathToPartitionInfo, path, null, false, true);
// The plan's paths and the split's can differ in scheme and authority, such as pfile:// (HIVE-6366). The lookup
// tries each parent of the path with and without them, and strips the plan's paths only when that finds none:
// stripping them up front costs every split a pass over all the partitions of the scan.
final PartitionDesc part = mapWork == null ? null :
HiveFileFormatUtils.getFromPathRecursively(mapWork.getPathToPartitionInfo(), path, null, true, true);

try {
if ((part != null) && (part.getTableDesc() != null)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
import org.apache.hadoop.mapred.InputSplit;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.RecordReader;
import org.apache.parquet.HadoopReadOptions;
import org.apache.parquet.ParquetReadOptions;
import org.apache.parquet.column.ColumnDescriptor;
import org.apache.parquet.column.page.PageReadStore;
import org.apache.parquet.format.converter.ParquetMetadataConverter.MetadataFilter;
Expand Down Expand Up @@ -304,23 +306,29 @@ private Path wrapPathForCache(Path path, Object fileKey, JobConf configuration,

private ParquetMetadata readSplitFooter(JobConf configuration, final Path file,
Object cacheKey, MetadataFilter filter, CacheTag tag) throws IOException {
InputFile inputFile;
if (cacheKey == null || metadataCache == null) {
// Non-LLAP case
FileSystem fs = file.getFileSystem(configuration);
FileStatus stat = fs.getFileStatus(file);
return readFooterFromFile(file, fs, stat, filter);
inputFile = fileInput(file, fs, stat);
} else {
// Fallback path outside the native encoded reader: no per-fragment counters here, so the
// footer lookup doesn't contribute to META_HIT / META_MISS in the LLAP IO summary.
MemoryBufferOrBuffers footerData = LlapProxy.getIo().parquet()
.getFooterBuffersFromCache(file, configuration, tag, cacheKey, null);
return ParquetFileReader.readFooter(new ParquetFooterInputFromCache(footerData), filter);
inputFile = new ParquetFooterInputFromCache(footerData);
}
// The options Parquet builds for a Hadoop file, from the job's configuration: given an InputFile alone,
// readFooter builds them from a new Configuration, which parses the Hadoop XML resources for every split.
ParquetReadOptions options = HadoopReadOptions.builder(configuration, file).withMetadataFilter(filter).build();
try (SeekableInputStream stream = inputFile.newStream()) {
return ParquetFileReader.readFooter(inputFile, options, stream);
}
}

private ParquetMetadata readFooterFromFile(final Path file, final FileSystem fs,
final FileStatus stat, MetadataFilter filter) throws IOException {
InputFile inputFile = new InputFile() {
private static InputFile fileInput(final Path file, final FileSystem fs, final FileStatus stat) {
return new InputFile() {
@Override
public SeekableInputStream newStream() throws IOException {
return HadoopStreams.wrap(fs.open(file));
Expand All @@ -330,7 +338,6 @@ public long getLength() {
return stat.getLen();
}
};
return ParquetFileReader.readFooter(inputFile, filter);
}

public static CacheTag cacheTagOfParquetFile(Path path, Configuration cacheConf, JobConf jobConf) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* 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.hadoop.hive.ql.io.parquet;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import java.util.Properties;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.ql.exec.Utilities;
import org.apache.hadoop.hive.ql.plan.MapWork;
import org.apache.hadoop.hive.ql.plan.PartitionDesc;
import org.apache.hadoop.hive.ql.plan.TableDesc;
import org.apache.hadoop.mapred.JobConf;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
* The partition of a split's directory, found in the plan whatever scheme either path carries: its table's
* properties are what the pusher copies into the split's configuration.
*/
public class TestProjectionPusher {

private static final String MARKER = "test.projection.pusher.partition";

private JobConf conf;

@Before
public void setUp() {
conf = new JobConf();
HiveConf.setVar(conf, HiveConf.ConfVars.PLAN, "//tmp");
MapWork mapWork = new MapWork();
mapWork.addPathToPartitionInfo(new Path("pfile:/warehouse/t/p=1"), partition("p1"));
mapWork.addPathToPartitionInfo(new Path("pfile:/warehouse/t/p=2"), partition("p2"));
Utilities.setMapWork(conf, mapWork);
}

@After
public void tearDown() {
Utilities.clearWork(conf);
}

@Test
public void testSameScheme() throws Exception {
assertEquals("p2", partitionOf(new Path("pfile:/warehouse/t/p=2")));
}

@Test
public void testNoScheme() throws Exception {
assertEquals("p1", partitionOf(new Path("/warehouse/t/p=1")));
assertEquals("p1", partitionOf(new Path("/warehouse/t/p=1/sub")));
}

@Test
public void testOtherScheme() throws Exception {
assertEquals("p2", partitionOf(new Path("file:/warehouse/t/p=2")));
}

@Test
public void testOutsideThePlan() throws Exception {
assertNull(partitionOf(new Path("pfile:/warehouse/other")));
}

@Test
public void testNoPlan() throws Exception {
Utilities.clearWork(conf);
conf.unset(HiveConf.ConfVars.PLAN.varname);
assertNull(partitionOf(new Path("pfile:/warehouse/t/p=1")));
}

private String partitionOf(Path dir) throws Exception {
return new ProjectionPusher().pushProjectionsAndFilters(conf, dir).get(MARKER);
}

private static PartitionDesc partition(String name) {
Properties properties = new Properties();
properties.setProperty(MARKER, name);
TableDesc table = new TableDesc();
table.setProperties(properties);
PartitionDesc partition = new PartitionDesc();
partition.setTableDesc(table);
return partition;
}
}
Loading