Skip to content

Commit 5a86bf0

Browse files
authored
Merge branch 'facebookincubator:main' into simoneves/15793_support_decimal_types_in_cudf_gpu_operators
2 parents d12110f + 4f7ea08 commit 5a86bf0

31 files changed

+736
-230
lines changed

velox/common/base/tests/GTestUtils.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,22 @@
117117
} \
118118
}
119119

120+
#define VELOX_ASSERT_EQ_TYPES(actual, expected) \
121+
{ \
122+
auto _actualType = (actual); \
123+
auto _expectedType = (expected); \
124+
if (_expectedType != nullptr) { \
125+
ASSERT_TRUE(_actualType != nullptr) \
126+
<< "Expected: " << _expectedType->toString() << ", got null"; \
127+
ASSERT_EQ(*_actualType, *_expectedType) \
128+
<< "Expected: " << _expectedType->toString() << ", got " \
129+
<< _actualType->toString(); \
130+
} else { \
131+
ASSERT_EQ(_actualType, nullptr) \
132+
<< "Expected null, got " << _actualType->toString(); \
133+
} \
134+
}
135+
120136
#ifndef NDEBUG
121137
#define DEBUG_ONLY_TEST(test_fixture, test_name) TEST(test_fixture, test_name)
122138
#define DEBUG_ONLY_TEST_F(test_fixture, test_name) \
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "velox/connectors/hive/BufferedInputBuilder.h"
18+
#include "velox/connectors/hive/HiveConnectorUtil.h"
19+
20+
namespace facebook::velox::connector::hive {
21+
22+
class DefaultBufferInputBuilder : public BufferedInputBuilder {
23+
public:
24+
std::unique_ptr<dwio::common::BufferedInput> create(
25+
const FileHandle& fileHandle,
26+
const dwio::common::ReaderOptions& readerOpts,
27+
const ConnectorQueryCtx* connectorQueryCtx,
28+
std::shared_ptr<io::IoStatistics> ioStats,
29+
std::shared_ptr<filesystems::File::IoStats> fsStats,
30+
folly::Executor* executor,
31+
const folly::F14FastMap<std::string, std::string>& fileReadOps) override {
32+
return createBufferedInput(
33+
fileHandle,
34+
readerOpts,
35+
connectorQueryCtx,
36+
ioStats,
37+
fsStats,
38+
executor,
39+
fileReadOps);
40+
}
41+
};
42+
43+
// static
44+
std::shared_ptr<BufferedInputBuilder> BufferedInputBuilder::builder_ =
45+
std::make_shared<DefaultBufferInputBuilder>();
46+
47+
} // namespace facebook::velox::connector::hive
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
#include <folly/Executor.h>
19+
20+
#include "velox/connectors/Connector.h"
21+
#include "velox/connectors/hive/FileHandle.h"
22+
#include "velox/dwio/common/BufferedInput.h"
23+
#include "velox/dwio/common/Reader.h"
24+
25+
namespace facebook::velox::connector::hive {
26+
27+
/// Registering a different implementation of BufferedInput is allowed using
28+
/// 'registerBuilder' API.
29+
class BufferedInputBuilder {
30+
public:
31+
virtual ~BufferedInputBuilder() = default;
32+
33+
static const std::shared_ptr<BufferedInputBuilder>& getInstance() {
34+
VELOX_CHECK_NOT_NULL(builder_, "Builder is not registered");
35+
return builder_;
36+
}
37+
38+
static void registerBuilder(std::shared_ptr<BufferedInputBuilder> builder) {
39+
VELOX_CHECK_NOT_NULL(builder);
40+
builder_ = std::move(builder);
41+
}
42+
43+
virtual std::unique_ptr<dwio::common::BufferedInput> create(
44+
const FileHandle& fileHandle,
45+
const dwio::common::ReaderOptions& readerOpts,
46+
const ConnectorQueryCtx* connectorQueryCtx,
47+
std::shared_ptr<io::IoStatistics> ioStats,
48+
std::shared_ptr<filesystems::File::IoStats> fsStats,
49+
folly::Executor* executor,
50+
const folly::F14FastMap<std::string, std::string>& fileReadOps = {}) = 0;
51+
52+
private:
53+
static std::shared_ptr<BufferedInputBuilder> builder_;
54+
};
55+
56+
} // namespace facebook::velox::connector::hive

velox/connectors/hive/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ add_subdirectory(iceberg)
2020
velox_add_library(
2121
velox_hive_connector
2222
OBJECT
23+
BufferedInputBuilder.cpp
2324
FileHandle.cpp
2425
HiveConfig.cpp
2526
HiveConnector.cpp

velox/connectors/hive/SplitReader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "velox/connectors/hive/SplitReader.h"
1818

1919
#include "velox/common/caching/CacheTTLController.h"
20+
#include "velox/connectors/hive/BufferedInputBuilder.h"
2021
#include "velox/connectors/hive/HiveConfig.h"
2122
#include "velox/connectors/hive/HiveConnectorSplit.h"
2223
#include "velox/connectors/hive/HiveConnectorUtil.h"
@@ -330,7 +331,7 @@ void SplitReader::createReader(
330331
if (auto* cacheTTLController = cache::CacheTTLController::getInstance()) {
331332
cacheTTLController->addOpenFileInfo(fileHandleCachePtr->uuid.id());
332333
}
333-
auto baseFileInput = createBufferedInput(
334+
auto baseFileInput = BufferedInputBuilder::getInstance()->create(
334335
*fileHandleCachePtr,
335336
baseReaderOpts_,
336337
connectorQueryCtx_,

velox/connectors/hive/iceberg/PositionalDeleteFileReader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "velox/connectors/hive/iceberg/PositionalDeleteFileReader.h"
1818

19+
#include "velox/connectors/hive/BufferedInputBuilder.h"
1920
#include "velox/connectors/hive/HiveConnectorUtil.h"
2021
#include "velox/connectors/hive/TableHandle.h"
2122
#include "velox/connectors/hive/iceberg/IcebergDeleteFile.h"
@@ -97,7 +98,7 @@ PositionalDeleteFileReader::PositionalDeleteFileReader(
9798
.filename = deleteFile_.filePath,
9899
.tokenProvider = connectorQueryCtx_->fsTokenProvider()};
99100
auto deleteFileHandleCachePtr = fileHandleFactory_->generate(fileHandleKey);
100-
auto deleteFileInput = createBufferedInput(
101+
auto deleteFileInput = BufferedInputBuilder::getInstance()->create(
101102
*deleteFileHandleCachePtr,
102103
deleteReaderOpts,
103104
connectorQueryCtx,

velox/duckdb/conversion/DuckConversion.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ TypePtr toVeloxType(LogicalType type, bool fileColumnNamesReadAsLowerCase) {
192192
if (auto customType = getCustomType(name, {})) {
193193
return customType;
194194
}
195+
if (name == "OPAQUE<void>") {
196+
return OPAQUE<void>();
197+
}
195198
[[fallthrough]];
196199
}
197200
default:

velox/dwio/common/tests/TestBufferedInput.cpp

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include <gmock/gmock.h>
1818
#include <gtest/gtest.h>
19+
#include "velox/common/base/tests/GTestUtils.h"
20+
#include "velox/connectors/hive/BufferedInputBuilder.h"
1921
#include "velox/dwio/common/BufferedInput.h"
2022

2123
using namespace facebook::velox::dwio::common;
@@ -144,7 +146,6 @@ class TestBufferedInput : public testing::Test {
144146

145147
const std::shared_ptr<MemoryPool> pool_ = memoryManager()->addLeafPool();
146148
};
147-
} // namespace
148149

149150
TEST_F(TestBufferedInput, ZeroLengthStream) {
150151
auto readFile =
@@ -391,3 +392,45 @@ TEST_F(TestBufferedInput, VReadSortingWithLabels) {
391392
EXPECT_EQ(next.value(), r.second);
392393
}
393394
}
395+
396+
class CustomBufferedInputBuilder
397+
: public facebook::velox::connector::hive::BufferedInputBuilder {
398+
public:
399+
std::unique_ptr<facebook::velox::dwio::common::BufferedInput> create(
400+
const facebook::velox::FileHandle& fileHandle,
401+
const facebook::velox::dwio::common::ReaderOptions& readerOpts,
402+
const facebook::velox::connector::ConnectorQueryCtx* connectorQueryCtx,
403+
std::shared_ptr<facebook::velox::io::IoStatistics> ioStats,
404+
std::shared_ptr<facebook::velox::filesystems::File::IoStats> fsStats,
405+
folly::Executor* executor,
406+
const folly::F14FastMap<std::string, std::string>& fileReadOps = {})
407+
override {
408+
VELOX_NYI("Not implemented in CustomBufferedInputBuilder");
409+
}
410+
};
411+
412+
class CustomBufferedInputTest : public testing::Test {
413+
protected:
414+
static void SetUpTestCase() {
415+
MemoryManager::testingSetInstance(MemoryManager::Options{});
416+
facebook::velox::connector::hive::BufferedInputBuilder::registerBuilder(
417+
std::make_shared<CustomBufferedInputBuilder>());
418+
}
419+
420+
const std::shared_ptr<MemoryPool> pool_ = memoryManager()->addLeafPool();
421+
};
422+
423+
} // namespace
424+
425+
TEST_F(CustomBufferedInputTest, basic) {
426+
facebook::velox::FileHandle fileHandle;
427+
facebook::velox::dwio::common::ReaderOptions readerOpts(pool_.get());
428+
auto ioStats = std::make_shared<facebook::velox::io::IoStatistics>();
429+
auto fsStats =
430+
std::make_shared<facebook::velox::filesystems::File::IoStats>();
431+
432+
VELOX_ASSERT_THROW(
433+
facebook::velox::connector::hive::BufferedInputBuilder::getInstance()
434+
->create(fileHandle, readerOpts, nullptr, ioStats, fsStats, nullptr),
435+
"Not implemented in CustomBufferedInputBuilder");
436+
}

0 commit comments

Comments
 (0)