Skip to content

Commit e8521c7

Browse files
xyliganSerejaMatveev Sergei
andauthored
Bool support for columnshard (#26865)
Co-authored-by: Matveev Sergei <[email protected]>
1 parent 09f5353 commit e8521c7

File tree

16 files changed

+238
-69
lines changed

16 files changed

+238
-69
lines changed

ydb/core/formats/arrow/arrow_batch_builder.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ arrow::Status AppendCell(arrow::NumericBuilder<T>& builder, const TCell& cell) {
2929
return builder.Append(cell.AsValue<ui8>());
3030
}
3131

32+
[[maybe_unused]] arrow::Status AppendCell(arrow::UInt8Builder& builder, const TCell& cell) {
33+
if (cell.IsNull()) {
34+
return builder.AppendNull();
35+
}
36+
37+
return builder.Append(cell.AsValue<ui8>());
38+
}
39+
3240
[[maybe_unused]] arrow::Status AppendCell(arrow::BinaryBuilder& builder, const TCell& cell) {
3341
if (cell.IsNull()) {
3442
return builder.AppendNull();

ydb/core/formats/arrow/arrow_helpers.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ std::shared_ptr<arrow::DataType> CreateEmptyArrowImpl() {
3535
return std::make_shared<TType>();
3636
}
3737

38+
template <>
39+
std::shared_ptr<arrow::DataType> CreateEmptyArrowImpl<arrow::BooleanType>() {
40+
return arrow::uint8();
41+
}
42+
3843
template <>
3944
std::shared_ptr<arrow::DataType> CreateEmptyArrowImpl<arrow::Decimal128Type>() {
4045
return arrow::fixed_size_binary(NScheme::FSB_SIZE);
@@ -62,6 +67,7 @@ arrow::Result<std::shared_ptr<arrow::DataType>> GetArrowType(NScheme::TTypeInfo
6267
result = CreateEmptyArrowImpl<TType>();
6368
return true;
6469
});
70+
6571
if (success) {
6672
return result;
6773
}
@@ -72,6 +78,8 @@ arrow::Result<std::shared_ptr<arrow::DataType>> GetArrowType(NScheme::TTypeInfo
7278
arrow::Result<std::shared_ptr<arrow::DataType>> GetCSVArrowType(NScheme::TTypeInfo typeId) {
7379
std::shared_ptr<arrow::DataType> result;
7480
switch (typeId.GetTypeId()) {
81+
case NScheme::NTypeIds::Bool:
82+
return std::make_shared<arrow::UInt8Type>();
7583
case NScheme::NTypeIds::Datetime:
7684
case NScheme::NTypeIds::Datetime64:
7785
return std::make_shared<arrow::TimestampType>(arrow::TimeUnit::SECOND);

ydb/core/formats/arrow/switch/switch_type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ template <typename TFunc>
2525
[[nodiscard]] bool SwitchYqlTypeToArrowType(const NScheme::TTypeInfo& typeInfo, TFunc&& callback) {
2626
switch (typeInfo.GetTypeId()) {
2727
case NScheme::NTypeIds::Bool:
28-
return callback(TTypeWrapper<arrow::BooleanType>());
28+
return callback(TTypeWrapper<arrow::UInt8Type>());
2929
case NScheme::NTypeIds::Int8:
3030
return callback(TTypeWrapper<arrow::Int8Type>());
3131
case NScheme::NTypeIds::Uint8:

ydb/core/formats/arrow/ut/ut_arrow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ struct TDataRow {
117117

118118
static std::shared_ptr<arrow::Schema> MakeArrowSchema() {
119119
std::vector<std::shared_ptr<arrow::Field>> fields = {
120-
arrow::field("bool", arrow::boolean()),
120+
arrow::field("bool", arrow::uint8()),
121121
arrow::field("i8", arrow::int8()),
122122
arrow::field("i16", arrow::int16()),
123123
arrow::field("i32", arrow::int32()),

ydb/core/grpc_services/rpc_load_rows.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ namespace {
3131
// TODO: no mapping for DATE, DATETIME, TZ_*, YSON, JSON, UUID, JSON_DOCUMENT, DYNUMBER
3232
bool ConvertArrowToYdbPrimitive(const arrow::DataType& type, Ydb::Type& toType, const NScheme::TTypeInfo* tableColumnType = nullptr) {
3333
switch (type.id()) {
34-
case arrow::Type::BOOL:
35-
toType.set_type_id(Ydb::Type::BOOL);
36-
return true;
3734
case arrow::Type::UINT8:
3835
toType.set_type_id(Ydb::Type::UINT8);
3936
return true;
@@ -86,6 +83,7 @@ bool ConvertArrowToYdbPrimitive(const arrow::DataType& type, Ydb::Type& toType,
8683

8784
break;
8885
}
86+
case arrow::Type::BOOL:
8987
case arrow::Type::NA:
9088
case arrow::Type::HALF_FLOAT:
9189
case arrow::Type::DATE32:

ydb/core/io_formats/arrow/scheme/scheme.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ arrow::Result<TArrowCSV> TArrowCSVScheme::Create(const TVector<std::pair<TString
2424
if (type.GetTypeId() == NScheme::NTypeIds::Decimal) {
2525
columnInfo.Precision = type.GetDecimalType().GetPrecision();
2626
columnInfo.Scale = type.GetDecimalType().GetScale();
27+
} else if (type.GetTypeId() == NScheme::NTypeIds::Bool) {
28+
columnInfo.IsBool = true;
2729
}
2830

2931
convertedColumns.emplace_back(columnInfo);

ydb/core/kqp/ut/common/columnshard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ namespace NKqp {
344344
std::shared_ptr<arrow::Field> TTestHelper::TColumnTableBase::BuildField(const TString name, const NScheme::TTypeInfo& typeInfo, bool nullable) const {
345345
switch (typeInfo.GetTypeId()) {
346346
case NScheme::NTypeIds::Bool:
347-
return arrow::field(name, arrow::boolean(), nullable);
347+
return arrow::field(name, arrow::uint8(), nullable);
348348
case NScheme::NTypeIds::Int8:
349349
return arrow::field(name, arrow::int8(), nullable);
350350
case NScheme::NTypeIds::Int16:

ydb/core/kqp/ut/olap/bool_test_enums.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ enum EQueryMode {
99
};
1010

1111
enum ETableKind {
12-
COLUMN_SHARD,
13-
DATA_SHARD
12+
COLUMNSHARD,
13+
DATASHARD
1414
};
1515

1616
enum ELoadKind {

0 commit comments

Comments
 (0)