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

Method DecodeArrow

cpp/src/parquet/decoder.cc:1900–1957  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1898 }
1899
1900 int DecodeArrow(int num_values, int null_count, const uint8_t* valid_bits,
1901 int64_t valid_bits_offset,
1902 typename EncodingTraits<BooleanType>::Accumulator* out) override {
1903 if (null_count == num_values) {
1904 PARQUET_THROW_NOT_OK(out->AppendNulls(null_count));
1905 return 0;
1906 }
1907 constexpr int kBatchSize = 1024;
1908 std::array<bool, kBatchSize> values;
1909 const int num_non_null_values = num_values - null_count;
1910 // Remaining non-null boolean values to read from decoder.
1911 // We decode from `decoder_` with maximum 1024 size batches.
1912 int num_remain_non_null_values = num_non_null_values;
1913 int current_index_in_batch = 0;
1914 int current_batch_size = 0;
1915 auto next_boolean_batch = [&]() {
1916 DCHECK_GT(num_remain_non_null_values, 0);
1917 DCHECK_EQ(current_index_in_batch, current_batch_size);
1918 current_batch_size = std::min(num_remain_non_null_values, kBatchSize);
1919 int decoded_count = decoder_->GetBatch(values.data(), current_batch_size);
1920 if (ARROW_PREDICT_FALSE(decoded_count != current_batch_size)) {
1921 // required values is more than values in decoder.
1922 ParquetException::EofException();
1923 }
1924 num_remain_non_null_values -= current_batch_size;
1925 current_index_in_batch = 0;
1926 };
1927
1928 // Reserve all values including nulls first
1929 PARQUET_THROW_NOT_OK(out->Reserve(num_values));
1930 if (null_count == 0) {
1931 // Fast-path for not having nulls.
1932 do {
1933 next_boolean_batch();
1934 PARQUET_THROW_NOT_OK(
1935 out->AppendValues(values.begin(), values.begin() + current_batch_size));
1936 num_values -= current_batch_size;
1937 // set current_index_in_batch to current_batch_size means
1938 // the whole batch is totally consumed.
1939 current_index_in_batch = current_batch_size;
1940 } while (num_values > 0);
1941 return num_non_null_values;
1942 }
1943 auto next_value = [&]() -> bool {
1944 if (current_index_in_batch == current_batch_size) {
1945 next_boolean_batch();
1946 DCHECK_GT(current_batch_size, 0);
1947 }
1948 DCHECK_LT(current_index_in_batch, current_batch_size);
1949 bool value = values[current_index_in_batch];
1950 ++current_index_in_batch;
1951 return value;
1952 };
1953 VisitNullBitmapInline(
1954 valid_bits, valid_bits_offset, num_values, null_count,
1955 [&]() { out->UnsafeAppend(next_value()); }, [&]() { out->UnsafeAppendNull(); });
1956 return num_non_null_values;
1957 }

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