Skip to content

Commit a3638d6

Browse files
committed
Allow rename and deletion of subfields
1 parent 4bd07a7 commit a3638d6

File tree

11 files changed

+144
-12
lines changed

11 files changed

+144
-12
lines changed

velox/connectors/hive/HiveConnectorUtil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ void configureReaderOptions(
569569
break;
570570
}
571571
default:
572-
useColumnNamesForColumnMapping = false;
572+
break;
573573
}
574574

575575
readerOptions.setUseColumnNamesForColumnMapping(

velox/connectors/hive/SplitReader.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,11 @@ std::vector<TypePtr> SplitReader::adaptColumns(
440440
auto fileTypeIdx = fileType->getChildIdxIfExists(fieldName);
441441
if (!fileTypeIdx.has_value()) {
442442
// Column is missing. Most likely due to schema evolution.
443-
VELOX_CHECK(tableSchema, "Unable to resolve column '{}'", fieldName);
443+
auto schema = tableSchema ? tableSchema : readerOutputType_;
444+
VELOX_CHECK(schema, "Unable to resolve column '{}'", fieldName);
444445
childSpec->setConstantValue(
445446
BaseVector::createNullConstant(
446-
tableSchema->findChild(fieldName),
447+
schema->findChild(fieldName),
447448
1,
448449
connectorQueryCtx_->memoryPool()));
449450
} else {

velox/dwio/common/SelectiveFlatMapColumnReader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ namespace facebook::velox::dwio::common {
2424
class SelectiveFlatMapColumnReader : public SelectiveStructColumnReaderBase {
2525
protected:
2626
SelectiveFlatMapColumnReader(
27+
const dwio::common::ColumnReaderOptions& columnReaderOptions,
2728
const TypePtr& requestedType,
2829
const std::shared_ptr<const dwio::common::TypeWithId>& fileType,
2930
FormatParams& params,
3031
velox::common::ScanSpec& scanSpec)
3132
: SelectiveStructColumnReaderBase(
33+
columnReaderOptions,
3234
requestedType,
3335
fileType,
3436
params,

velox/dwio/common/SelectiveStructColumnReader.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,9 @@ void SelectiveStructColumnReaderBase::read(
425425
}
426426

427427
const auto& childSpecs = scanSpec_->children();
428-
VELOX_CHECK(!childSpecs.empty());
428+
if (!columnReaderOptions_.useColumnNamesForColumnMapping_) {
429+
VELOX_CHECK(!childSpecs.empty());
430+
}
429431
for (size_t i = 0; i < childSpecs.size(); ++i) {
430432
const auto& childSpec = childSpecs[i];
431433

@@ -524,9 +526,12 @@ bool SelectiveStructColumnReaderBase::isChildMissing(
524526
// row type that doesn't exist
525527
// in the output.
526528
fileType_->type()->kind() !=
527-
TypeKind::MAP && // If this is the case it means this is a flat map,
528-
// so it can't have "missing" fields.
529-
childSpec.channel() >= fileType_->size());
529+
TypeKind::MAP // If this is the case it means this is a flat map,
530+
// so it can't have "missing" fields.
531+
) &&
532+
(columnReaderOptions_.useColumnNamesForColumnMapping_
533+
? !asRowType(fileType_->type())->containsChild(childSpec.fieldName())
534+
: childSpec.channel() >= fileType_->size());
530535
}
531536

532537
std::unique_ptr<velox::dwio::common::ColumnLoader>
@@ -538,7 +543,9 @@ SelectiveStructColumnReaderBase::makeColumnLoader(vector_size_t index) {
538543
void SelectiveStructColumnReaderBase::getValues(
539544
const RowSet& rows,
540545
VectorPtr* result) {
541-
VELOX_CHECK(!scanSpec_->children().empty());
546+
if (!columnReaderOptions_.useColumnNamesForColumnMapping_) {
547+
VELOX_CHECK(!scanSpec_->children().empty());
548+
}
542549
VELOX_CHECK_NOT_NULL(
543550
*result, "SelectiveStructColumnReaderBase expects a non-null result");
544551
VELOX_CHECK(

velox/dwio/common/SelectiveStructColumnReader.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#pragma once
1818

19+
#include "velox/dwio/common/Options.h"
1920
#include "velox/dwio/common/SelectiveColumnReaderInternal.h"
2021

2122
namespace facebook::velox::dwio::common {
@@ -113,13 +114,15 @@ class SelectiveStructColumnReaderBase : public SelectiveColumnReader {
113114
static constexpr int32_t kConstantChildSpecSubscript{-1};
114115

115116
SelectiveStructColumnReaderBase(
117+
const dwio::common::ColumnReaderOptions& columnReaderOptions,
116118
const TypePtr& requestedType,
117119
const std::shared_ptr<const dwio::common::TypeWithId>& fileType,
118120
FormatParams& params,
119121
velox::common::ScanSpec& scanSpec,
120122
bool isRoot = false,
121123
bool generateLazyChildren = true)
122124
: SelectiveColumnReader(requestedType, fileType, params, scanSpec),
125+
columnReaderOptions_(columnReaderOptions),
123126
debugString_(
124127
getExceptionContext().message(VeloxException::Type::kSystem)),
125128
isRoot_(isRoot),
@@ -180,6 +183,8 @@ class SelectiveStructColumnReaderBase : public SelectiveColumnReader {
180183
}
181184
}
182185

186+
const dwio::common::ColumnReaderOptions& columnReaderOptions_;
187+
183188
// Context information obtained from ExceptionContext. Stored here
184189
// so that LazyVector readers under this can add this to their
185190
// ExceptionContext. Allows contextualizing reader errors to split

velox/dwio/dwrf/reader/DwrfReader.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,14 @@ DwrfRowReader::DwrfRowReader(
320320
makeProjectedNodes(*getReader().schemaWithId(), *projectedNodes_);
321321
}
322322

323+
// Reader options must be configured before calling 'getUnitLoader()',
324+
// which triggers 'SelectiveDwrfReader::build'.
325+
columnReaderOptions_ = dwio::common::makeColumnReaderOptions(
326+
readerBaseShared()->readerOptions());
323327
unitLoader_ = getUnitLoader();
324328
if (!emptyFile()) {
325329
getReader().loadCache();
326330
}
327-
328-
columnReaderOptions_ = dwio::common::makeColumnReaderOptions(
329-
readerBaseShared()->readerOptions());
330331
}
331332

332333
std::unique_ptr<ColumnReader>& DwrfRowReader::getColumnReader() {

velox/dwio/dwrf/reader/SelectiveFlatMapColumnReader.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ class SelectiveFlatMapAsStructReader : public SelectiveStructColumnReaderBase {
203203
DwrfParams& params,
204204
common::ScanSpec& scanSpec)
205205
: SelectiveStructColumnReaderBase(
206+
columnReaderOptions,
206207
requestedType,
207208
fileType,
208209
params,
@@ -242,6 +243,7 @@ class SelectiveFlatMapAsMapReader : public SelectiveStructColumnReaderBase {
242243
DwrfParams& params,
243244
common::ScanSpec& scanSpec)
244245
: SelectiveStructColumnReaderBase(
246+
columnReaderOptions,
245247
requestedType,
246248
fileType,
247249
params,
@@ -286,6 +288,7 @@ class SelectiveFlatMapReader
286288
DwrfParams& params,
287289
common::ScanSpec& scanSpec)
288290
: dwio::common::SelectiveFlatMapColumnReader(
291+
columnReaderOptions,
289292
requestedType,
290293
fileType,
291294
params,

velox/dwio/dwrf/reader/SelectiveStructColumnReader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ SelectiveStructColumnReader::SelectiveStructColumnReader(
3131
common::ScanSpec& scanSpec,
3232
bool isRoot)
3333
: SelectiveStructColumnReaderBase(
34+
columnReaderOptions,
3435
requestedType,
3536
fileType,
3637
params,

velox/dwio/dwrf/reader/SelectiveStructColumnReader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ class SelectiveStructColumnReaderBase
2525
: public dwio::common::SelectiveStructColumnReaderBase {
2626
public:
2727
SelectiveStructColumnReaderBase(
28+
const dwio::common::ColumnReaderOptions& columnReaderOptions,
2829
const TypePtr& requestedType,
2930
const std::shared_ptr<const dwio::common::TypeWithId>& fileType,
3031
DwrfParams& params,
3132
common::ScanSpec& scanSpec,
3233
bool isRoot = false,
3334
bool generateLazyChildren = true)
3435
: dwio::common::SelectiveStructColumnReaderBase(
36+
columnReaderOptions,
3537
requestedType,
3638
fileType,
3739
params,

velox/dwio/parquet/reader/StructColumnReader.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ StructColumnReader::StructColumnReader(
3232
const std::shared_ptr<const dwio::common::TypeWithId>& fileType,
3333
ParquetParams& params,
3434
common::ScanSpec& scanSpec)
35-
: SelectiveStructColumnReader(requestedType, fileType, params, scanSpec) {
35+
: SelectiveStructColumnReader(
36+
columnReaderOptions,
37+
requestedType,
38+
fileType,
39+
params,
40+
scanSpec) {
3641
auto& childSpecs = scanSpec_->stableChildren();
3742
for (auto i = 0; i < childSpecs.size(); ++i) {
3843
auto childSpec = childSpecs[i];

0 commit comments

Comments
 (0)