|
| 1 | +// |
| 2 | +// Created by hromozeka on 10.03.25. |
| 3 | +// |
| 4 | + |
| 5 | +#ifndef PARQUET_TYPES_H |
| 6 | +#define PARQUET_TYPES_H |
| 7 | + |
| 8 | + |
| 9 | +#include "duckdb.hpp" |
| 10 | +#include <parquet_types.h> |
| 11 | + |
| 12 | +struct ParquetType { |
| 13 | + /*duckdb_parquet::ConvertedType::type -> replaced to int to support -1 nodata value*/ |
| 14 | + int converted_type; |
| 15 | + /* duckdb_parquet::Type::type -> replaced to int to support -1 for no matter value */ |
| 16 | + int parquet_type; |
| 17 | + const duckdb::LogicalType logical_type; |
| 18 | + ParquetType(int converted_type, int parquet_type, const duckdb::LogicalType &logical_type) |
| 19 | + : converted_type(converted_type), parquet_type(parquet_type), logical_type(logical_type) {} |
| 20 | + virtual bool check_type(const duckdb::vector<duckdb_parquet::SchemaElement> &schema, idx_t idx); |
| 21 | + virtual duckdb::LogicalType get_logical_type(const duckdb_parquet::SchemaElement &schema); |
| 22 | +}; |
| 23 | + |
| 24 | +struct LogicalParquetType : public ParquetType { |
| 25 | + bool (*get_isset)(const duckdb_parquet::SchemaElement& el); |
| 26 | + |
| 27 | + LogicalParquetType(bool (*get_isset) (const duckdb_parquet::SchemaElement& el), |
| 28 | + const duckdb::LogicalType& logical_type) |
| 29 | + : ParquetType(-1, duckdb_parquet::Type::type::INT32, logical_type), get_isset(get_isset) {} |
| 30 | + bool check_type(const duckdb::vector<duckdb_parquet::SchemaElement> &schema, idx_t idx) override; |
| 31 | +}; |
| 32 | + |
| 33 | +struct JSONParquetType : public ParquetType { |
| 34 | + JSONParquetType(): ParquetType(duckdb_parquet::ConvertedType::JSON, -1, duckdb::LogicalType::SQLNULL) {} |
| 35 | + duckdb::LogicalType get_logical_type(const duckdb_parquet::SchemaElement &schema) override; |
| 36 | +}; |
| 37 | + |
| 38 | +struct DecimalParquetType : public ParquetType { |
| 39 | + DecimalParquetType(): ParquetType(-1, duckdb_parquet::Type::type::INT32, duckdb::LogicalType::SQLNULL) {} |
| 40 | + bool check_type(const duckdb::vector<duckdb_parquet::SchemaElement> &schema, idx_t idx) override; |
| 41 | + duckdb::LogicalType get_logical_type(const duckdb_parquet::SchemaElement &schema) override; |
| 42 | +}; |
| 43 | + |
| 44 | +class ParquetTypesManager { |
| 45 | + protected: |
| 46 | + static ParquetTypesManager *instance; |
| 47 | + static std::mutex instance_mutex; |
| 48 | + ParquetTypesManager(); |
| 49 | + static ParquetTypesManager* get_instance(); |
| 50 | + duckdb::LogicalType derive_logical_type(const duckdb_parquet::SchemaElement &s_ele, bool binary_as_string); |
| 51 | + public: |
| 52 | + static duckdb::LogicalType get_logical_type(const duckdb::vector<duckdb_parquet::SchemaElement> &schema, idx_t idx); |
| 53 | +}; |
| 54 | + |
| 55 | +#endif //PARQUET_TYPES_H |
0 commit comments