Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GLUTEN-6681] [CH]fix array(decimal32) in CH columnar to row #6722

Merged
merged 6 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,9 @@ class GlutenClickhouseFunctionSuite extends GlutenClickHouseTPCHAbstractSuite {
spark.sql("drop table t2")
}

test("array decimal32") {
compareResultsAgainstVanillaSpark("SELECT array(1.0, 2.0)", true, { _ => }, false)
compareResultsAgainstVanillaSpark("SELECT map(1.0, '2', 3.0, '4')", true, { _ => }, false)
}

}
11 changes: 8 additions & 3 deletions cpp-ch/local-engine/Parser/CHColumnToSparkRow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,12 +586,11 @@ int64_t BackingDataLengthCalculator::getArrayElementSize(const DataTypePtr & nes
else if (nested_which.isUInt16() || nested_which.isInt16() || nested_which.isDate())
return 2;
else if (
nested_which.isUInt32() || nested_which.isInt32() || nested_which.isFloat32() || nested_which.isDate32()
|| nested_which.isDecimal32())
nested_which.isUInt32() || nested_which.isInt32() || nested_which.isFloat32() || nested_which.isDate32())
return 4;
else if (
nested_which.isUInt64() || nested_which.isInt64() || nested_which.isFloat64() || nested_which.isDateTime64()
|| nested_which.isDecimal64())
|| nested_which.isDecimal32() || nested_which.isDecimal64())
return 8;
else
return 8;
Expand Down Expand Up @@ -702,6 +701,12 @@ int64_t VariableLengthDataWriter::writeArray(size_t row_idx, const DB::Array & a
auto v = elem.get<Float64>();
writer.unsafeWrite(reinterpret_cast<const char *>(&v), buffer_address + offset + start + 8 + len_null_bitmap + i * elem_size);
}
else if (writer.getWhichDataType().isDecimal32())
taiyang-li marked this conversation as resolved.
Show resolved Hide resolved
{
// We can not use get<char>() directly here to process Decimal32 field,
// because it will get 4 byte data, but Decimal32 is 8 byte in Spark, which will cause error conversion.
writer.write(elem, buffer_address + offset + start + 8 + len_null_bitmap + i * elem_size);
taiyang-li marked this conversation as resolved.
Show resolved Hide resolved
}
else
writer.unsafeWrite(
reinterpret_cast<const char *>(&elem.get<char>()),
Expand Down
Loading