Coverage Report

Created: 2025-11-01 07:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/duckdb/extension/parquet/include/parquet_decimal_utils.hpp
Line
Count
Source
1
//===----------------------------------------------------------------------===//
2
//                         DuckDB
3
//
4
// parquet_decimal_utils.hpp
5
//
6
//
7
//===----------------------------------------------------------------------===//
8
9
#pragma once
10
11
#include "column_reader.hpp"
12
#include "reader/templated_column_reader.hpp"
13
14
namespace duckdb {
15
16
class ParquetDecimalUtils {
17
public:
18
  template <class PHYSICAL_TYPE>
19
0
  static PHYSICAL_TYPE ReadDecimalValue(const_data_ptr_t pointer, idx_t size, const ParquetColumnSchema &) {
20
0
    PHYSICAL_TYPE res = 0;
21
22
0
    auto res_ptr = (uint8_t *)&res;
23
0
    bool positive = (*pointer & 0x80) == 0;
24
25
    // numbers are stored as two's complement so some muckery is required
26
0
    for (idx_t i = 0; i < MinValue<idx_t>(size, sizeof(PHYSICAL_TYPE)); i++) {
27
0
      auto byte = *(pointer + (size - i - 1));
28
0
      res_ptr[i] = positive ? byte : byte ^ 0xFF;
29
0
    }
30
    // Verify that there are only 0s here
31
0
    if (size > sizeof(PHYSICAL_TYPE)) {
32
0
      for (idx_t i = sizeof(PHYSICAL_TYPE); i < size; i++) {
33
0
        auto byte = *(pointer + (size - i - 1));
34
0
        if (!positive) {
35
0
          byte ^= 0xFF;
36
0
        }
37
0
        if (byte != 0) {
38
0
          throw InvalidInputException("Invalid decimal encoding in Parquet file");
39
0
        }
40
0
      }
41
0
    }
42
0
    if (!positive) {
43
0
      res += 1;
44
0
      return -res;
45
0
    }
46
0
    return res;
47
0
  }
Unexecuted instantiation: short duckdb::ParquetDecimalUtils::ReadDecimalValue<short>(unsigned char const*, unsigned long, duckdb::ParquetColumnSchema const&)
Unexecuted instantiation: int duckdb::ParquetDecimalUtils::ReadDecimalValue<int>(unsigned char const*, unsigned long, duckdb::ParquetColumnSchema const&)
Unexecuted instantiation: long duckdb::ParquetDecimalUtils::ReadDecimalValue<long>(unsigned char const*, unsigned long, duckdb::ParquetColumnSchema const&)
Unexecuted instantiation: duckdb::hugeint_t duckdb::ParquetDecimalUtils::ReadDecimalValue<duckdb::hugeint_t>(unsigned char const*, unsigned long, duckdb::ParquetColumnSchema const&)
48
49
  static unique_ptr<ColumnReader> CreateReader(ParquetReader &reader, const ParquetColumnSchema &schema);
50
};
51
52
template <>
53
double ParquetDecimalUtils::ReadDecimalValue(const_data_ptr_t pointer, idx_t size, const ParquetColumnSchema &schema);
54
55
} // namespace duckdb