Skip to content

ORC-1386: [C++] Support schema evolution from numeric to string group/decimal/timestamp - #1500

Closed
ffacs wants to merge 7 commits into
apache:mainfrom
ffacs:ORC-1386
Closed

ffacs wants to merge 7 commits into
apache:mainfrom
ffacs:ORC-1386

Conversation

@ffacs

@ffacs ffacs commented May 16, 2023

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

support conversion from numeric to string group/decimal/timestamp

Why are the changes needed?

To support schema evolution in c++

How was this patch tested?

UT passed

@github-actions github-actions Bot added the CPP label May 16, 2023
@dongjoon-hyun dongjoon-hyun added this to the 2.0.0 milestone May 16, 2023
Comment thread c++/src/Timezone.cc Resolved
Comment thread c++/src/ConvertColumnReader.cc Resolved
Comment thread c++/src/ConvertColumnReader.cc Resolved
Comment thread c++/src/ConvertColumnReader.cc Outdated
size_t size = 0;
strBuffer.resize(numValues);
const auto& srcBatch = *SafeCastBatchTo<const BooleanVectorBatch*>(data.get());
std::string trueValue = "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.

Does it follow the Java implementation?

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 it follow the Java implementation?

public static class StringGroupFromBooleanTreeReader extends StringGroupFromAnyIntegerTreeReader {
private static final byte[] TRUE_BYTES = "TRUE".getBytes(StandardCharsets.US_ASCII);
private static final byte[] FALSE_BYTES = "FALSE".getBytes(StandardCharsets.US_ASCII);
StringGroupFromBooleanTreeReader(int columnId, TypeDescription fileType,
TypeDescription readerType,
Context context) throws IOException {
super(columnId, fileType, readerType, context);
}
@Override
public void setConvertVectorElement(int elementNum) {
byte[] bytes = (longColVector.vector[elementNum] != 0 ? TRUE_BYTES : FALSE_BYTES);
assignStringGroupVectorEntry(bytesColVector, elementNum, readerType, bytes);
}
}

protected void assignStringGroupVectorEntry(BytesColumnVector bytesColVector,
int elementNum,
TypeDescription readerType,
byte[] bytes,
int start,
int length) {
switch (readerType.getCategory()) {
case STRING:
bytesColVector.setVal(elementNum, bytes, start, length);
break;
case CHAR:
int charAdjustedDownLen =
StringExpr.rightTrimAndTruncate(bytes, start, length, readerType.getMaxLength());
bytesColVector.setVal(elementNum, bytes, start, charAdjustedDownLen);
break;
case VARCHAR:
int varcharAdjustedDownLen =
StringExpr.truncate(bytes, start, length, readerType.getMaxLength());
bytesColVector.setVal(elementNum, bytes, start, varcharAdjustedDownLen);
break;
default:
throw new RuntimeException("Unexpected type kind " + readerType.getCategory().name());
}
}

I think so, but i am not good at java, please take a look

Comment thread c++/src/ConvertColumnReader.cc Outdated
trueValue.resize(readType.getMaximumLength(), ' ');
falseValue.resize(readType.getMaximumLength(), ' ');
} else if (readType.getKind() == VARCHAR) {
trueValue = trueValue.substr(0, std::min(static_cast<uint64_t>(4), readType.getMaximumLength()));

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 not sure if it should throw if truncation happens.

Comment thread c++/src/ConvertColumnReader.cc Resolved
Comment thread c++/src/ConvertColumnReader.cc Outdated
void convertDoubleToDecimal(ReadTypeBatch& dstBatch, uint64_t idx, srcType value) {
std::string strValue = std::to_string(value);
int32_t fromScale = 0;
int32_t fromPrecision = static_cast<int32_t>(strValue.length());

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.

What if value is a negative number?

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

@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.

In addition to the above comment, could you make CI happy, @ffacs ?

/Users/runner/work/orc/orc/c++/src/ConvertColumnReader.cc:189:9: error: 'ConvertToStringVariantColumnReader' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit [-Werror,-Wweak-vtables]
  class ConvertToStringVariantColumnReader : public ConvertColumnReader {
        ^
/Users/runner/work/orc/orc/c++/src/ConvertColumnReader.cc:392:9: error: 'ConvertToTimestampColumnReader' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit [-Werror,-Wweak-vtables]
  class ConvertToTimestampColumnReader : public ConvertColumnReader {
        ^
2 errors generated.
make[2]: *** [c++/src/CMakeFiles/orc.dir/ConvertColumnReader.cc.o] Error 1
make[1]: *** [c++/src/CMakeFiles/orc.dir/all] Error 2
make: *** [all] Error 2

@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.

The implementation looks good to me. Left some comments mostly for tests.

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++/src/ConvertColumnReader.cc Resolved
Comment thread c++/src/Int128.cc Resolved
Comment thread c++/src/ConvertColumnReader.cc Resolved
Comment thread c++/src/Int128.cc Resolved
Comment thread c++/src/Int128.cc Resolved
Comment thread c++/src/Int128.cc Resolved
Comment thread c++/src/Int128.cc Resolved
Comment thread c++/test/TestInt128.cc Resolved
@wgtmac

wgtmac commented Jun 13, 2023

Copy link
Copy Markdown
Member

Thanks @ffacs! Overall looks good.

Could you please make all the CIs pass?

@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!

@wgtmac wgtmac closed this in b6d595b Jun 18, 2023
}
case LONG: {
switch (_readType.getKind()) {
CASE_CREATE_READER(BOOLEAN, LongToBoolean);

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 need this semicolon removal in branch-1.9 too.

@dongjoon-hyun

Copy link
Copy Markdown
Member

Let me bring this to branch-1.9 too~

dongjoon-hyun pushed a commit that referenced this pull request Jun 22, 2023
…/decimal/timestamp

### What changes were proposed in this pull request?
support conversion from numeric to string group/decimal/timestamp

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

### How was this patch tested?
UT passed

Closes #1500 from ffacs/ORC-1386.

Lead-authored-by: ffacs <ffacs520@gmail.com>
Co-authored-by: ffacs <ffacs@ffacs.top>
Signed-off-by: Gang Wu <ustcwg@gmail.com>
(cherry picked from commit b6d595b)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
@wgtmac

wgtmac commented Jun 22, 2023

Copy link
Copy Markdown
Member

Thanks @dongjoon-hyun!

@ffacs
ffacs deleted the ORC-1386 branch July 29, 2023 08:28
cxzl25 pushed a commit to cxzl25/orc that referenced this pull request Jan 11, 2024
…/decimal/timestamp

### What changes were proposed in this pull request?
support conversion from numeric to string group/decimal/timestamp

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

### How was this patch tested?
UT passed

Closes apache#1500 from ffacs/ORC-1386.

Lead-authored-by: ffacs <ffacs520@gmail.com>
Co-authored-by: ffacs <ffacs@ffacs.top>
Signed-off-by: Gang Wu <ustcwg@gmail.com>
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.

3 participants