Skip to content

Commit

Permalink
[BugFix] Fix orc tinyint on aarch64 (#49517)
Browse files Browse the repository at this point in the history
Why I'm doing:
https://developer.arm.com/documentation/den0013/d/Porting/Miscellaneous-C-porting-issues/unsigned-char-and-signed-char
compiler treat char as unsigned on aarch64, negative tinyint will be wrong, and the query result from orc is null.

What I'm doing:
use int8_t not char to cast

Signed-off-by: wyb <[email protected]>
(cherry picked from commit 6de3ab7)
  • Loading branch information
wyb authored and mergify[bot] committed Aug 7, 2024
1 parent 857dd73 commit 4329646
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
4 changes: 3 additions & 1 deletion be/src/formats/orc/apache-orc/c++/src/ColumnReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ void ColumnReader::seekToRowGroup(PositionProviderMap* positions) {
*/
void expandBytesToLongs(int64_t* buffer, uint64_t numValues) {
for (size_t i = numValues - 1; i < numValues; --i) {
buffer[i] = reinterpret_cast<char*>(buffer)[i];
// compiler treat char as unsigned on aarch64, negative tinyint will be wrong,
// so use 'int8_t' not 'char' to cast
buffer[i] = reinterpret_cast<int8_t*>(buffer)[i];
}
}

Expand Down
27 changes: 27 additions & 0 deletions test/sql/test_files/R/orc_tinyint_aarch64
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- name: orc_tinyint_aarch64

create database db_${uuid0};
use db_${uuid0};

shell: ossutil64 mkdir oss://${oss_bucket}/test_files/orc_format/${uuid0} >/dev/null || echo "exit 0" >/dev/null

shell: ossutil64 cp --force ./sql/test_files/orc_format/tinyint.orc oss://${oss_bucket}/test_files/orc_format/${uuid0}/ | grep -Pv "(average|elapsed)"
-- result:
0

Succeed: Total num: 1, size: 247. OK num: 1(upload 1 files).
-- !result

select * from files('path' = 'oss://${oss_bucket}/test_files/orc_format/${uuid0}/*', 'format' = 'orc');
-- result:
-128
-- !result

create table t1 as select * from files('path' = 'oss://${oss_bucket}/test_files/orc_format/${uuid0}/*', 'format' = 'orc');

desc t1;
-- result:
k1 tinyint YES true None
-- !result

shell: ossutil64 rm -rf oss://${oss_bucket}/test_files/orc_format/${uuid0}/ > /dev/null
14 changes: 14 additions & 0 deletions test/sql/test_files/T/orc_tinyint_aarch64
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- name: orc_tinyint_aarch64

create database db_${uuid0};
use db_${uuid0};

shell: ossutil64 mkdir oss://${oss_bucket}/test_files/orc_format/${uuid0} >/dev/null || echo "exit 0" >/dev/null
shell: ossutil64 cp --force ./sql/test_files/orc_format/tinyint.orc oss://${oss_bucket}/test_files/orc_format/${uuid0}/ | grep -Pv "(average|elapsed)"

select * from files('path' = 'oss://${oss_bucket}/test_files/orc_format/${uuid0}/*', 'format' = 'orc');

create table t1 as select * from files('path' = 'oss://${oss_bucket}/test_files/orc_format/${uuid0}/*', 'format' = 'orc');
desc t1;

shell: ossutil64 rm -rf oss://${oss_bucket}/test_files/orc_format/${uuid0}/ > /dev/null
Binary file added test/sql/test_files/orc_format/tinyint.orc
Binary file not shown.

0 comments on commit 4329646

Please sign in to comment.