Skip to content

ORC-1385: [C++] Support schema evolution of numeric types - #1454

Merged
wgtmac merged 6 commits into
apache:mainfrom
ffacs:dev
Apr 14, 2023
Merged

wgtmac merged 6 commits into
apache:mainfrom
ffacs:dev

Conversation

@ffacs

@ffacs ffacs commented Mar 27, 2023

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

support schema evolution converting between types within {boolean, tinyint, smallint, int, bigint, float, double}

Why are the changes needed?

To support shecma evolution in c++

How was this patch tested?

UT passed

@github-actions github-actions Bot added the CPP label Mar 27, 2023
@wgtmac wgtmac changed the title ORC-1385 [C++] Support schema evolution from numeric to numeric ORC-1385: [C++] Support schema evolution of numeric types Mar 28, 2023
Comment thread c++/include/orc/Reader.hh Resolved
Comment thread c++/src/ColumnReader.hh Resolved
Comment thread c++/src/ConvertColumnReader.hh Resolved
Comment thread c++/src/ConvertColumnReader.cc Resolved
Comment thread c++/src/ConvertColumnReader.cc Resolved
Comment thread c++/src/ConvertColumnReader.cc Resolved
Comment thread c++/src/ConvertColumnReader.cc Resolved
Comment thread c++/include/orc/Reader.hh Outdated
std::shared_ptr<Type>& getReadType() const;

/**
* Set should reader throw a exception on conversion between different data types overflow

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Set should reader throw a exception on conversion between different data types overflow
* Set whether reader throws or returns null when value overflows for schema evolution.

Comment thread c++/include/orc/Reader.hh Outdated
RowReaderOptions& throwOnSchemaEvolutionOverflow(bool shouldThrow);

/**
* Get should reader throw a exception on conversion between different data types overflow

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Get should reader throw a exception on conversion between different data types overflow
* Whether reader throws or returns null when value overflows for schema evolution.

Comment thread c++/include/orc/Vector.hh Outdated

// whether the vector is not a numeric vector
// or it's created with the option useTightNumericVector
bool isTight = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible not to add this? The reader can get this information by the provided ReaderOption

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, what if the ColumnVectorBatch is created by another reader which was createed without the useTightNumericVector option?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the current ColumnReader have same issue?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the current ColumnReader have same issue?

Yes, I think there is.

@wgtmac wgtmac Apr 3, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to fix that as well.

What about adding a new function to ColumnVectorBatch like int32_t fixed_type_size() const to return the width in bytes for fixed length type? For variable length type or nested type we can return -1.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What probably need to fix that as well.

What about adding a new function to ColumnVectorBatch like int32_t fixed_type_size() const to return the width in bytes for fixed length type? For variable length type or nested type we can return -1.

I think what we are going to do is handle incorrect usage by users (such as passing a vector that was created by other readers). However, we don’t know what causes the failure of casting. The vector may have been created by another reader with a different read type from the current reader, or it may have been created by another reader with a different useTightNumericVector option. fixed_type_size() may not help us infer what the user did wrong, but with isTight, we could suggest that the user check their options.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that sounds good.

However, isTight here is a little bit confusing since it applies to only numeric types. We need to be careful to add any field to the public api. And it should also be used with its type together.

In the ColumnReader, we always check the result of dynamic_cast of the vector batch. Is it enough if we can use dynamic_cast and check if it is not null in the ConvertColumnReader?

@ffacs ffacs Apr 3, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that sounds good.

However, isTight here is a little bit confusing since it applies to only numeric types. We need to be careful to add any field to the public api. And it should also be used with its type together.

In the ColumnReader, we always check the result of dynamic_cast of the vector batch. Is it enough if we can use dynamic_cast and check if it is not null in the ConvertColumnReader?

I think that's OK, so we will only verify the ReaderOption and check the result of dynamic_cast in ConvertColumnReader.

Comment thread c++/src/ColumnReader.cc Resolved
Comment thread c++/src/ColumnReader.cc Resolved
rowBatch.numElements = data->numElements;
rowBatch.hasNulls = data->hasNulls;
if (!rowBatch.hasNulls) {
memset(rowBatch.notNull.data(), 1, data->notNull.size());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is not required

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is not required

orc/c++/src/MemoryPool.cc

Lines 120 to 127 in 070c1a5

template <>
void DataBuffer<char>::resize(uint64_t newSize) {
reserve(newSize);
if (newSize > currentSize) {
memset(buf + currentSize, 0, newSize - currentSize);
}
currentSize = newSize;
}

When there are no nulls and we are going to set null when an overflow in conversion occurs, the notNull of other elements should be 1, but they are 0 after resizing, so the memset is needed.

Comment thread c++/src/ConvertColumnReader.cc Outdated
if (!canFitInLong(static_cast<double>(srcValue)) ||
!downCastToInteger(destValue, longValue)) {
handleOverflow<FileType, ReadType>(destBatch, idx, shouldThrow);
return;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is redundant.

Comment thread c++/src/Reader.cc Resolved
Comment thread c++/src/Reader.cc Resolved
Comment thread c++/src/Reader.cc Resolved

@wgtmac wgtmac left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM.

Comment thread c++/src/ColumnReader.cc

public:
StructColumnReader(const Type& type, StripeStreams& stipe, bool useTightNumericVector = false);
StructColumnReader(const Type& type, StripeStreams& stipe, bool useTightNumericVector = false,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking if we can use a new ColumnReaderOptions to include useTightNumericVector and throwOnSchemaEvolutionOverflow in case we will add more options. But that can be a separate patch since this is not public.

Comment thread c++/src/Reader.cc Resolved
Comment thread c++/src/Reader.cc Resolved
Comment thread c++/src/Reader.cc Resolved
Comment thread c++/src/Reader.cc Resolved
Comment thread c++/src/ConvertColumnReader.cc Resolved
Comment thread c++/src/ConvertColumnReader.cc Resolved
Comment thread c++/src/ConvertColumnReader.cc Resolved
Comment thread c++/src/ConvertColumnReader.cc Resolved

@wgtmac wgtmac left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

Comment thread c++/src/SchemaEvolution.cc Outdated
* limitations under the License.
*/

#include <iostream>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch does not seem to depend on the header file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Comment thread c++/src/Reader.hh Outdated
bool getIsDecimalAsLong() const;
int32_t getForcedScaleOnHive11Decimal() const;

const SchemaEvolution& getSchemaEvolution() const {

@coderex2522 coderex2522 Apr 11, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to consider unifying the return type(const SchemaEvolution*) of the getSchemaEvolution() function in class StripeStreams and class RowReaderImpl.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@coderex2522 coderex2522 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 LGTM. Thanks @ffacs

@wgtmac
wgtmac merged commit 511c8c1 into apache:main Apr 14, 2023
@dongjoon-hyun dongjoon-hyun added this to the 1.9.0 milestone Apr 26, 2023

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, All.

This code seems to cause a build failure on Clang-Ubuntu environment. Not only old Clang 10.0.0 on Ubuntu 20.04 but also Clang 14.0.0 on Ubuntu 22.04 complains about this patch. Could you take a look at this?

@dongjoon-hyun

Copy link
Copy Markdown
Member

Could you double check this compilation issue, @ffacs , @wgtmac , @coderex2522 ?

switch (fileType.getKind()) {
case BOOLEAN: {
switch (_readType.getKind()) {
CASE_CREATE_READER(BYTE, BooleanToByte);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, ; is required in this line?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fixed via #1500 (comment)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you get the failure? Via docker test?

@ffacs
ffacs deleted the dev branch July 29, 2023 08:28
cxzl25 pushed a commit to cxzl25/orc that referenced this pull request Jan 11, 2024
### What changes were proposed in this pull request?
support schema evolution converting between types within {boolean, tinyint, smallint, int, bigint, float, double}

### Why are the changes needed?
To support schema evolution in c++

### How was this patch tested?
UT passed

This closes apache#1454
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants