Skip to content

Commit f65622c

Browse files
authored
feat(native): Populate HiveColumnHandle::columnHandles property (#26525)
Summary: Follow-up to facebookincubator/velox#15348 Differential Revision: D86198314 ## Release Notes ``` == NO RELEASE NOTE == ```
1 parent 005273f commit f65622c

12 files changed

+52
-61
lines changed

presto-native-execution/presto_cpp/main/connectors/HivePrestoToVeloxConnector.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -336,31 +336,32 @@ HivePrestoToVeloxConnector::toVeloxTableHandle(
336336
const protocol::TableHandle& tableHandle,
337337
const VeloxExprConverter& exprConverter,
338338
const TypeParser& typeParser,
339-
velox::connector::ColumnHandleMap& assignments) const {
340-
auto addSynthesizedColumn = [&](const std::string& name,
341-
protocol::hive::ColumnType columnType,
342-
const protocol::ColumnHandle& column) {
343-
if (toHiveColumnType(columnType) ==
344-
velox::connector::hive::HiveColumnHandle::ColumnType::kSynthesized) {
345-
if (assignments.count(name) == 0) {
346-
assignments.emplace(name, toVeloxColumnHandle(&column, typeParser));
347-
}
348-
}
349-
};
339+
const velox::connector::ColumnHandleMap& assignments) const {
350340
auto hiveLayout =
351341
std::dynamic_pointer_cast<const protocol::hive::HiveTableLayoutHandle>(
352342
tableHandle.connectorTableLayout);
353343
VELOX_CHECK_NOT_NULL(
354344
hiveLayout,
355345
"Unexpected layout type {}",
356346
tableHandle.connectorTableLayout->_type);
347+
348+
std::unordered_set<std::string> columnNames;
349+
std::vector<velox::connector::hive::HiveColumnHandlePtr> columnHandles;
357350
for (const auto& entry : hiveLayout->partitionColumns) {
358-
assignments.emplace(entry.name, toVeloxColumnHandle(&entry, typeParser));
351+
if (columnNames.emplace(entry.name).second) {
352+
columnHandles.emplace_back(
353+
std::dynamic_pointer_cast<velox::connector::hive::HiveColumnHandle>(
354+
std::shared_ptr(toVeloxColumnHandle(&entry, typeParser))));
355+
}
359356
}
360357

361358
// Add synthesized columns to the TableScanNode columnHandles as well.
362359
for (const auto& entry : hiveLayout->predicateColumns) {
363-
addSynthesizedColumn(entry.first, entry.second.columnType, entry.second);
360+
if (columnNames.emplace(entry.second.name).second) {
361+
columnHandles.emplace_back(
362+
std::dynamic_pointer_cast<velox::connector::hive::HiveColumnHandle>(
363+
std::shared_ptr(toVeloxColumnHandle(&entry.second, typeParser))));
364+
}
364365
}
365366

366367
auto hiveTableHandle =
@@ -384,6 +385,7 @@ HivePrestoToVeloxConnector::toVeloxTableHandle(
384385
tableName,
385386
hiveLayout->dataColumns,
386387
tableHandle,
388+
columnHandles,
387389
hiveLayout->tableParameters,
388390
exprConverter,
389391
typeParser);

presto-native-execution/presto_cpp/main/connectors/HivePrestoToVeloxConnector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class HivePrestoToVeloxConnector final : public PrestoToVeloxConnector {
4242
const protocol::TableHandle& tableHandle,
4343
const VeloxExprConverter& exprConverter,
4444
const TypeParser& typeParser,
45-
velox::connector::ColumnHandleMap& assignments) const final;
45+
const velox::connector::ColumnHandleMap& assignments) const final;
4646

4747
std::unique_ptr<velox::connector::ConnectorInsertTableHandle>
4848
toVeloxInsertTableHandle(

presto-native-execution/presto_cpp/main/connectors/IcebergPrestoToVeloxConnector.cpp

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ std::unique_ptr<velox::connector::ConnectorTableHandle> toIcebergTableHandle(
5151
const std::string& tableName,
5252
const protocol::List<protocol::Column>& dataColumns,
5353
const protocol::TableHandle& tableHandle,
54-
const protocol::Map<protocol::String, protocol::String>& tableParameters,
54+
const std::vector<velox::connector::hive::HiveColumnHandlePtr>&
55+
columnHandles,
5556
const VeloxExprConverter& exprConverter,
5657
const TypeParser& typeParser) {
5758
velox::common::SubfieldFilters subfieldFilters;
@@ -96,22 +97,15 @@ std::unique_ptr<velox::connector::ConnectorTableHandle> toIcebergTableHandle(
9697
finalDataColumns = ROW(std::move(names), std::move(types));
9798
}
9899

99-
std::unordered_map<std::string, std::string> finalTableParameters = {};
100-
if (!tableParameters.empty()) {
101-
finalTableParameters.reserve(tableParameters.size());
102-
for (const auto& [key, value] : tableParameters) {
103-
finalTableParameters[key] = value;
104-
}
105-
}
106-
107100
return std::make_unique<velox::connector::hive::HiveTableHandle>(
108101
tableHandle.connectorId,
109102
tableName,
110103
isPushdownFilterEnabled,
111104
std::move(subfieldFilters),
112105
remainingFilter,
113106
finalDataColumns,
114-
finalTableParameters);
107+
std::unordered_map<std::string, std::string>{},
108+
columnHandles);
115109
}
116110

117111
} // namespace
@@ -212,18 +206,7 @@ IcebergPrestoToVeloxConnector::toVeloxTableHandle(
212206
const protocol::TableHandle& tableHandle,
213207
const VeloxExprConverter& exprConverter,
214208
const TypeParser& typeParser,
215-
velox::connector::ColumnHandleMap& assignments) const {
216-
auto addSynthesizedColumn = [&](const std::string& name,
217-
protocol::hive::ColumnType columnType,
218-
const protocol::ColumnHandle& column) {
219-
if (toHiveColumnType(columnType) ==
220-
velox::connector::hive::HiveColumnHandle::ColumnType::kSynthesized) {
221-
if (assignments.count(name) == 0) {
222-
assignments.emplace(name, toVeloxColumnHandle(&column, typeParser));
223-
}
224-
}
225-
};
226-
209+
const velox::connector::ColumnHandleMap& assignments) const {
227210
auto icebergLayout = std::dynamic_pointer_cast<
228211
const protocol::iceberg::IcebergTableLayoutHandle>(
229212
tableHandle.connectorTableLayout);
@@ -232,14 +215,25 @@ IcebergPrestoToVeloxConnector::toVeloxTableHandle(
232215
"Unexpected layout type {}",
233216
tableHandle.connectorTableLayout->_type);
234217

218+
std::unordered_set<std::string> columnNames;
219+
std::vector<velox::connector::hive::HiveColumnHandlePtr> columnHandles;
235220
for (const auto& entry : icebergLayout->partitionColumns) {
236-
assignments.emplace(
237-
entry.columnIdentity.name, toVeloxColumnHandle(&entry, typeParser));
221+
if (columnNames.emplace(entry.columnIdentity.name).second) {
222+
columnHandles.emplace_back(
223+
std::dynamic_pointer_cast<
224+
const velox::connector::hive::HiveColumnHandle>(
225+
std::shared_ptr(toVeloxColumnHandle(&entry, typeParser))));
226+
}
238227
}
239228

240229
// Add synthesized columns to the TableScanNode columnHandles as well.
241230
for (const auto& entry : icebergLayout->predicateColumns) {
242-
addSynthesizedColumn(entry.first, entry.second.columnType, entry.second);
231+
if (columnNames.emplace(entry.second.columnIdentity.name).second) {
232+
columnHandles.emplace_back(
233+
std::dynamic_pointer_cast<
234+
const velox::connector::hive::HiveColumnHandle>(
235+
std::shared_ptr(toVeloxColumnHandle(&entry.second, typeParser))));
236+
}
243237
}
244238

245239
auto icebergTableHandle =
@@ -265,7 +259,7 @@ IcebergPrestoToVeloxConnector::toVeloxTableHandle(
265259
tableName,
266260
icebergLayout->dataColumns,
267261
tableHandle,
268-
{},
262+
columnHandles,
269263
exprConverter,
270264
typeParser);
271265
}

presto-native-execution/presto_cpp/main/connectors/IcebergPrestoToVeloxConnector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class IcebergPrestoToVeloxConnector final : public PrestoToVeloxConnector {
3737
const protocol::TableHandle& tableHandle,
3838
const VeloxExprConverter& exprConverter,
3939
const TypeParser& typeParser,
40-
velox::connector::ColumnHandleMap& assignments) const final;
40+
const velox::connector::ColumnHandleMap& assignments) const final;
4141

4242
std::unique_ptr<protocol::ConnectorProtocol> createConnectorProtocol()
4343
const final;

presto-native-execution/presto_cpp/main/connectors/PrestoToVeloxConnector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ TpchPrestoToVeloxConnector::toVeloxTableHandle(
102102
const protocol::TableHandle& tableHandle,
103103
const VeloxExprConverter& exprConverter,
104104
const TypeParser& typeParser,
105-
velox::connector::ColumnHandleMap& assignments) const {
105+
const velox::connector::ColumnHandleMap& assignments) const {
106106
auto tpchLayout =
107107
std::dynamic_pointer_cast<const protocol::tpch::TpchTableLayoutHandle>(
108108
tableHandle.connectorTableLayout);
@@ -154,7 +154,7 @@ TpcdsPrestoToVeloxConnector::toVeloxTableHandle(
154154
const protocol::TableHandle& tableHandle,
155155
const VeloxExprConverter& exprConverter,
156156
const TypeParser& typeParser,
157-
velox::connector::ColumnHandleMap& assignments) const {
157+
const velox::connector::ColumnHandleMap& assignments) const {
158158
auto tpcdsLayout =
159159
std::dynamic_pointer_cast<const protocol::tpcds::TpcdsTableLayoutHandle>(
160160
tableHandle.connectorTableLayout);

presto-native-execution/presto_cpp/main/connectors/PrestoToVeloxConnector.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class PrestoToVeloxConnector {
5959
const protocol::TableHandle& tableHandle,
6060
const VeloxExprConverter& exprConverter,
6161
const TypeParser& typeParser,
62-
velox::connector::ColumnHandleMap& assignments) const = 0;
62+
const velox::connector::ColumnHandleMap& assignments) const = 0;
6363

6464
[[nodiscard]] virtual std::unique_ptr<
6565
velox::connector::ConnectorInsertTableHandle>
@@ -133,7 +133,7 @@ class TpchPrestoToVeloxConnector final : public PrestoToVeloxConnector {
133133
const protocol::TableHandle& tableHandle,
134134
const VeloxExprConverter& exprConverter,
135135
const TypeParser& typeParser,
136-
velox::connector::ColumnHandleMap& assignments) const final;
136+
const velox::connector::ColumnHandleMap& assignments) const final;
137137

138138
std::unique_ptr<protocol::ConnectorProtocol> createConnectorProtocol()
139139
const final;
@@ -157,7 +157,7 @@ class TpcdsPrestoToVeloxConnector final : public PrestoToVeloxConnector {
157157
const protocol::TableHandle& tableHandle,
158158
const VeloxExprConverter& exprConverter,
159159
const TypeParser& typeParser,
160-
velox::connector::ColumnHandleMap& assignments) const final;
160+
const velox::connector::ColumnHandleMap& assignments) const final;
161161

162162
std::unique_ptr<protocol::ConnectorProtocol> createConnectorProtocol()
163163
const final;

presto-native-execution/presto_cpp/main/connectors/PrestoToVeloxConnectorUtils.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ std::unique_ptr<velox::connector::ConnectorTableHandle> toHiveTableHandle(
750750
const std::string& tableName,
751751
const protocol::List<protocol::Column>& dataColumns,
752752
const protocol::TableHandle& tableHandle,
753+
const std::vector<velox::connector::hive::HiveColumnHandlePtr>&
754+
columnHandles,
753755
const protocol::Map<protocol::String, protocol::String>& tableParameters,
754756
const VeloxExprConverter& exprConverter,
755757
const TypeParser& typeParser) {
@@ -788,16 +790,6 @@ std::unique_ptr<velox::connector::ConnectorTableHandle> toHiveTableHandle(
788790
finalDataColumns = ROW(std::move(names), std::move(types));
789791
}
790792

791-
if (tableParameters.empty()) {
792-
return std::make_unique<connector::hive::HiveTableHandle>(
793-
tableHandle.connectorId,
794-
tableName,
795-
isPushdownFilterEnabled,
796-
std::move(subfieldFilters),
797-
remainingFilter,
798-
finalDataColumns);
799-
}
800-
801793
std::unordered_map<std::string, std::string> finalTableParameters = {};
802794
finalTableParameters.reserve(tableParameters.size());
803795
for (const auto& [key, value] : tableParameters) {
@@ -811,7 +803,8 @@ std::unique_ptr<velox::connector::ConnectorTableHandle> toHiveTableHandle(
811803
std::move(subfieldFilters),
812804
remainingFilter,
813805
finalDataColumns,
814-
finalTableParameters);
806+
finalTableParameters,
807+
columnHandles);
815808
}
816809

817810
} // namespace facebook::presto

presto-native-execution/presto_cpp/main/connectors/PrestoToVeloxConnectorUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ std::unique_ptr<velox::connector::ConnectorTableHandle> toHiveTableHandle(
5757
const std::string& tableName,
5858
const protocol::List<protocol::Column>& dataColumns,
5959
const protocol::TableHandle& tableHandle,
60+
const std::vector<velox::connector::hive::HiveColumnHandlePtr>&
61+
columnHandles,
6062
const protocol::Map<protocol::String, protocol::String>& tableParameters,
6163
const VeloxExprConverter& exprConverter,
6264
const TypeParser& typeParser);

presto-native-execution/presto_cpp/main/connectors/SystemConnector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ SystemPrestoToVeloxConnector::toVeloxTableHandle(
377377
const protocol::TableHandle& tableHandle,
378378
const VeloxExprConverter& exprConverter,
379379
const TypeParser& typeParser,
380-
velox::connector::ColumnHandleMap& assignments) const {
380+
const velox::connector::ColumnHandleMap& assignments) const {
381381
auto systemLayout =
382382
std::dynamic_pointer_cast<const protocol::SystemTableLayoutHandle>(
383383
tableHandle.connectorTableLayout);

presto-native-execution/presto_cpp/main/connectors/SystemConnector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class SystemPrestoToVeloxConnector final : public PrestoToVeloxConnector {
192192
const protocol::TableHandle& tableHandle,
193193
const VeloxExprConverter& exprConverter,
194194
const TypeParser& typeParser,
195-
velox::connector::ColumnHandleMap& assignments) const final;
195+
const velox::connector::ColumnHandleMap& assignments) const final;
196196

197197
std::unique_ptr<protocol::ConnectorProtocol> createConnectorProtocol()
198198
const final;

0 commit comments

Comments
 (0)