blob: 1775e83a2f05421253b41f905fbab276cef5aa3c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include "contrib/libs/apache/arrow_next/cpp/src/arrow/util/dict_util.h"
#include "contrib/libs/apache/arrow_next/cpp/src/arrow/array/array_dict.h"
#include "contrib/libs/apache/arrow_next/cpp/src/arrow/util/bit_util.h"
#include "contrib/libs/apache/arrow_next/cpp/src/arrow/util/checked_cast.h"
namespace arrow20 {
namespace dict_util {
namespace {
template <typename IndexArrowType>
int64_t LogicalNullCount(const ArraySpan& span) {
const auto* indices_null_bit_map = span.buffers[0].data;
const auto& dictionary_span = span.dictionary();
const auto* dictionary_null_bit_map = dictionary_span.buffers[0].data;
using CType = typename IndexArrowType::c_type;
const CType* indices_data = span.GetValues<CType>(1);
int64_t null_count = 0;
for (int64_t i = 0; i < span.length; i++) {
if (indices_null_bit_map != nullptr &&
!bit_util::GetBit(indices_null_bit_map, i + span.offset)) {
null_count++;
continue;
}
CType current_index = indices_data[i];
if (!bit_util::GetBit(dictionary_null_bit_map,
current_index + dictionary_span.offset)) {
null_count++;
}
}
return null_count;
}
} // namespace
int64_t LogicalNullCount(const ArraySpan& span) {
if (span.dictionary().GetNullCount() == 0 || span.length == 0) {
return span.GetNullCount();
}
const auto& dict_array_type = internal::checked_cast<const DictionaryType&>(*span.type);
switch (dict_array_type.index_type()->id()) {
case Type::UINT8:
return LogicalNullCount<UInt8Type>(span);
case Type::INT8:
return LogicalNullCount<Int8Type>(span);
case Type::UINT16:
return LogicalNullCount<UInt16Type>(span);
case Type::INT16:
return LogicalNullCount<Int16Type>(span);
case Type::UINT32:
return LogicalNullCount<UInt32Type>(span);
case Type::INT32:
return LogicalNullCount<Int32Type>(span);
case Type::UINT64:
return LogicalNullCount<UInt64Type>(span);
default:
return LogicalNullCount<Int64Type>(span);
}
}
} // namespace dict_util
} // namespace arrow20
|