Skip to content

Commit

Permalink
Introducing IcebergSplitReader
Browse files Browse the repository at this point in the history
In this commit we introduces IcebergSplitReader which supports reading
Iceberg splits with positional delete files.
  • Loading branch information
yingsu00 committed Nov 15, 2023
1 parent 87130f4 commit f44ad01
Show file tree
Hide file tree
Showing 22 changed files with 1,029 additions and 48 deletions.
10 changes: 2 additions & 8 deletions velox/common/testutil/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,5 @@ add_executable(velox_test_util_test TestValueTest.cpp SpillConfigTest.cpp)
gtest_add_tests(velox_test_util_test "" AUTO)

target_link_libraries(
velox_test_util_test
PRIVATE
velox_test_util
velox_exception
velox_spill_config
velox_exec
gtest
gtest_main)
velox_test_util_test PRIVATE velox_test_util velox_exception
velox_spill_config velox_exec gtest gtest_main)
28 changes: 15 additions & 13 deletions velox/connectors/hive/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
# limitations under the License.

add_library(velox_hive_config OBJECT HiveConfig.cpp)

target_link_libraries(velox_hive_config velox_exception)

add_subdirectory(iceberg)

add_library(
velox_hive_connector OBJECT
FileHandle.cpp
Expand All @@ -30,18 +31,19 @@ add_library(

target_link_libraries(
velox_hive_connector
velox_common_io
velox_connector
velox_dwio_catalog_fbhive
velox_dwio_dwrf_reader
velox_dwio_dwrf_writer
velox_dwio_parquet_reader
velox_dwio_parquet_writer
velox_file
velox_hive_partition_function
velox_s3fs
velox_hdfs
velox_gcs)
PUBLIC velox_hive_iceberg_splitreader
PRIVATE velox_common_io
velox_connector
velox_dwio_catalog_fbhive
velox_dwio_dwrf_reader
velox_dwio_dwrf_writer
velox_dwio_parquet_reader
velox_dwio_parquet_writer
velox_file
velox_hive_partition_function
velox_s3fs
velox_hdfs
velox_gcs)

add_library(velox_hive_partition_function HivePartitionFunction.cpp)

Expand Down
8 changes: 4 additions & 4 deletions velox/connectors/hive/FileHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@

#pragma once

#include <cstdint>
#include <memory>
#include <string>

#include "velox/common/caching/CachedFactory.h"
#include "velox/common/caching/FileIds.h"
#include "velox/common/file/File.h"
#include "velox/dwio/common/InputStream.h"

//#include <cstdint>
//#include <memory>
//#include <string>

namespace facebook::velox {

class Config;
Expand Down
1 change: 0 additions & 1 deletion velox/connectors/hive/HiveConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ std::unique_ptr<DataSource> HiveConnector::createDataSource(
std::string,
std::shared_ptr<connector::ColumnHandle>>& columnHandles,
ConnectorQueryCtx* connectorQueryCtx) {

return std::make_unique<HiveDataSource>(
outputType,
tableHandle,
Expand Down
3 changes: 1 addition & 2 deletions velox/connectors/hive/HiveDataSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ std::unique_ptr<SplitReader> HiveDataSource::createSplitReader() {
readerOutputType_,
&partitionKeys_,
fileHandleFactory_,
executor_,
connectorQueryCtx_,
executor_,
ioStats_);
}

Expand All @@ -497,7 +497,6 @@ void HiveDataSource::addSplit(std::shared_ptr<ConnectorSplit> split) {
if (splitReader_) {
splitReader_.reset();
}

splitReader_ = createSplitReader();
splitReader_->prepareSplit(metadataFilter_, runtimeStats_);
}
Expand Down
6 changes: 3 additions & 3 deletions velox/connectors/hive/HiveDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ class HiveDataSource : public DataSource {
SelectivityVector filterRows_;
exec::FilterEvalCtx filterEvalCtx_;

FileHandleFactory* fileHandleFactory_;
const ConnectorQueryCtx* const connectorQueryCtx_;
folly::Executor* executor_;
FileHandleFactory* const fileHandleFactory_;
ConnectorQueryCtx* const connectorQueryCtx_;
folly::Executor* const executor_;
};

} // namespace facebook::velox::connector::hive
44 changes: 30 additions & 14 deletions velox/connectors/hive/SplitReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
#include "velox/connectors/hive/HiveConfig.h"
#include "velox/connectors/hive/HiveConnectorSplit.h"
#include "velox/connectors/hive/TableHandle.h"
#include "velox/connectors/hive/iceberg/IcebergSplitReader.h"
#include "velox/dwio/common/CachedBufferedInput.h"
#include "velox/dwio/common/DirectBufferedInput.h"
#include "velox/dwio/common/Options.h"
#include "velox/dwio/common/ReaderFactory.h"

#include <folly/Conv.h>
#include <gtest/gtest.h>
// #include <gtest/gtest.h>

#include <string>
#include <unordered_map>
Expand Down Expand Up @@ -145,19 +146,34 @@ std::unique_ptr<SplitReader> SplitReader::create(
std::unordered_map<std::string, std::shared_ptr<HiveColumnHandle>>*
partitionKeys,
FileHandleFactory* fileHandleFactory,
ConnectorQueryCtx* connectorQueryCtx,
folly::Executor* executor,
const ConnectorQueryCtx* connectorQueryCtx,
std::shared_ptr<io::IoStatistics> ioStats) {
return std::make_unique<SplitReader>(
hiveSplit,
hiveTableHandle,
scanSpec,
readerOutputType,
partitionKeys,
fileHandleFactory,
executor,
connectorQueryCtx,
ioStats);
// Create the SplitReader based on hiveSplit->customSplitInfo["table_format"]
if (hiveSplit->customSplitInfo["table_format"] == "hive_iceberg") {
return std::make_unique<iceberg::IcebergSplitReader>(
hiveSplit,
hiveTableHandle,
scanSpec,
readerOutputType,
partitionKeys,
fileHandleFactory,

connectorQueryCtx,
executor,
ioStats);
} else {
return std::make_unique<SplitReader>(
hiveSplit,
hiveTableHandle,
scanSpec,
readerOutputType,
partitionKeys,
fileHandleFactory,
connectorQueryCtx,
executor,
ioStats);
}
}

SplitReader::SplitReader(
Expand All @@ -168,17 +184,17 @@ SplitReader::SplitReader(
std::unordered_map<std::string, std::shared_ptr<HiveColumnHandle>>*
partitionKeys,
FileHandleFactory* fileHandleFactory,
ConnectorQueryCtx* connectorQueryCtx,
folly::Executor* executor,
const ConnectorQueryCtx* connectorQueryCtx,
std::shared_ptr<io::IoStatistics> ioStats)
: hiveSplit_(hiveSplit),
hiveTableHandle_(hiveTableHandle),
scanSpec_(scanSpec),
readerOutputType_(readerOutputType),
partitionKeys_(partitionKeys),
fileHandleFactory_(fileHandleFactory),
executor_(executor),
connectorQueryCtx_(connectorQueryCtx),
executor_(executor),
ioStats_(ioStats),
baseReaderOpts_(connectorQueryCtx->memoryPool()) {}

Expand Down
6 changes: 3 additions & 3 deletions velox/connectors/hive/SplitReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class SplitReader {
std::unordered_map<std::string, std::shared_ptr<HiveColumnHandle>>*
partitionKeys,
FileHandleFactory* fileHandleFactory,
ConnectorQueryCtx* connectorQueryCtx,
folly::Executor* executor,
const ConnectorQueryCtx* connectorQueryCtx,
std::shared_ptr<io::IoStatistics> ioStats);

SplitReader(
Expand All @@ -63,8 +63,8 @@ class SplitReader {
std::unordered_map<std::string, std::shared_ptr<HiveColumnHandle>>*
partitionKeys,
FileHandleFactory* fileHandleFactory,
ConnectorQueryCtx* connectorQueryCtx,
folly::Executor* executor,
const ConnectorQueryCtx* connectorQueryCtx,
std::shared_ptr<io::IoStatistics> ioStats);

virtual ~SplitReader() = default;
Expand Down Expand Up @@ -122,8 +122,8 @@ class SplitReader {
std::unique_ptr<dwio::common::Reader> baseReader_;
std::unique_ptr<dwio::common::RowReader> baseRowReader_;
FileHandleFactory* const fileHandleFactory_;
ConnectorQueryCtx* const connectorQueryCtx_;
folly::Executor* const executor_;
const ConnectorQueryCtx* const connectorQueryCtx_;
std::shared_ptr<io::IoStatistics> ioStats_;

private:
Expand Down
27 changes: 27 additions & 0 deletions velox/connectors/hive/iceberg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# Licensed 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.

add_library(velox_hive_iceberg_splitreader
IcebergSplitReader.cpp IcebergSplit.cpp DeleteFileReader.cpp)

target_link_libraries(
velox_hive_iceberg_splitreader
Folly::folly
gflags::gflags
glog::glog
gtest
gtest_main
xsimd)

add_subdirectory(tests)
Loading

0 comments on commit f44ad01

Please sign in to comment.