MCPcopy Create free account
hub / github.com/apache/arrow / DecodeArrow

Method DecodeArrow

cpp/src/parquet/decoder.cc:1949–2006  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1947 }
1948
1949 int DecodeArrow(int num_values, int null_count, const uint8_t* valid_bits,
1950 int64_t valid_bits_offset,
1951 typename EncodingTraits<BooleanType>::Accumulator* out) override {
1952 if (null_count == num_values) {
1953 PARQUET_THROW_NOT_OK(out->AppendNulls(null_count));
1954 return 0;
1955 }
1956 constexpr int kBatchSize = 1024;
1957 std::array<bool, kBatchSize> values;
1958 const int num_non_null_values = num_values - null_count;
1959 // Remaining non-null boolean values to read from decoder.
1960 // We decode from `decoder_` with maximum 1024 size batches.
1961 int num_remain_non_null_values = num_non_null_values;
1962 int current_index_in_batch = 0;
1963 int current_batch_size = 0;
1964 auto next_boolean_batch = [&]() {
1965 DCHECK_GT(num_remain_non_null_values, 0);
1966 DCHECK_EQ(current_index_in_batch, current_batch_size);
1967 current_batch_size = std::min(num_remain_non_null_values, kBatchSize);
1968 int decoded_count = decoder_->GetBatch(values.data(), current_batch_size);
1969 if (ARROW_PREDICT_FALSE(decoded_count != current_batch_size)) {
1970 // required values is more than values in decoder.
1971 ParquetException::EofException();
1972 }
1973 num_remain_non_null_values -= current_batch_size;
1974 current_index_in_batch = 0;
1975 };
1976
1977 // Reserve all values including nulls first
1978 PARQUET_THROW_NOT_OK(out->Reserve(num_values));
1979 if (null_count == 0) {
1980 // Fast-path for not having nulls.
1981 do {
1982 next_boolean_batch();
1983 PARQUET_THROW_NOT_OK(
1984 out->AppendValues(values.begin(), values.begin() + current_batch_size));
1985 num_values -= current_batch_size;
1986 // set current_index_in_batch to current_batch_size means
1987 // the whole batch is totally consumed.
1988 current_index_in_batch = current_batch_size;
1989 } while (num_values > 0);
1990 return num_non_null_values;
1991 }
1992 auto next_value = [&]() -> bool {
1993 if (current_index_in_batch == current_batch_size) {
1994 next_boolean_batch();
1995 DCHECK_GT(current_batch_size, 0);
1996 }
1997 DCHECK_LT(current_index_in_batch, current_batch_size);
1998 bool value = values[current_index_in_batch];
1999 ++current_index_in_batch;
2000 return value;
2001 };
2002 VisitNullBitmapInline(
2003 valid_bits, valid_bits_offset, num_values, null_count,
2004 [&]() { out->UnsafeAppend(next_value()); }, [&]() { out->UnsafeAppendNull(); });
2005 return num_non_null_values;
2006 }

Callers

nothing calls this directly

Calls 10

VisitNullBitmapInlineFunction · 0.85
NYIFunction · 0.85
AppendNullsMethod · 0.45
GetBatchMethod · 0.45
dataMethod · 0.45
ReserveMethod · 0.45
AppendValuesMethod · 0.45
beginMethod · 0.45
UnsafeAppendMethod · 0.45
UnsafeAppendNullMethod · 0.45

Tested by

no test coverage detected