duckdb 0.3.2-dev816.0 → 0.3.2-dev843.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/duckdb.cpp +164 -20
- package/src/duckdb.hpp +8 -6
- package/src/parquet-amalgamation.cpp +29162 -28117
- package/src/parquet-amalgamation.hpp +57 -68
|
@@ -7232,8 +7232,14 @@ using duckdb_parquet::format::SchemaElement;
|
|
|
7232
7232
|
|
|
7233
7233
|
struct LogicalType;
|
|
7234
7234
|
|
|
7235
|
-
|
|
7236
|
-
|
|
7235
|
+
struct ParquetStatisticsUtils {
|
|
7236
|
+
|
|
7237
|
+
static unique_ptr<BaseStatistics> TransformColumnStatistics(const SchemaElement &s_ele, const LogicalType &type,
|
|
7238
|
+
const ColumnChunk &column_chunk);
|
|
7239
|
+
|
|
7240
|
+
static Value ConvertValue(const LogicalType &type, const duckdb_parquet::format::SchemaElement &schema_ele,
|
|
7241
|
+
const std::string &stats);
|
|
7242
|
+
};
|
|
7237
7243
|
|
|
7238
7244
|
} // namespace duckdb
|
|
7239
7245
|
|
|
@@ -7264,80 +7270,38 @@ typedef std::bitset<STANDARD_VECTOR_SIZE> parquet_filter_t;
|
|
|
7264
7270
|
|
|
7265
7271
|
class ColumnReader {
|
|
7266
7272
|
public:
|
|
7267
|
-
static unique_ptr<ColumnReader> CreateReader(ParquetReader &reader, const LogicalType &type_p,
|
|
7268
|
-
const SchemaElement &schema_p, idx_t schema_idx_p, idx_t max_define,
|
|
7269
|
-
idx_t max_repeat);
|
|
7270
|
-
|
|
7271
7273
|
ColumnReader(ParquetReader &reader, LogicalType type_p, const SchemaElement &schema_p, idx_t file_idx_p,
|
|
7272
7274
|
idx_t max_define_p, idx_t max_repeat_p);
|
|
7273
|
-
|
|
7274
|
-
virtual void InitializeRead(const std::vector<ColumnChunk> &columns, TProtocol &protocol_p) {
|
|
7275
|
-
D_ASSERT(file_idx < columns.size());
|
|
7276
|
-
chunk = &columns[file_idx];
|
|
7277
|
-
protocol = &protocol_p;
|
|
7278
|
-
D_ASSERT(chunk);
|
|
7279
|
-
D_ASSERT(chunk->__isset.meta_data);
|
|
7280
|
-
|
|
7281
|
-
if (chunk->__isset.file_path) {
|
|
7282
|
-
throw std::runtime_error("Only inlined data files are supported (no references)");
|
|
7283
|
-
}
|
|
7284
|
-
|
|
7285
|
-
// ugh. sometimes there is an extra offset for the dict. sometimes it's wrong.
|
|
7286
|
-
chunk_read_offset = chunk->meta_data.data_page_offset;
|
|
7287
|
-
if (chunk->meta_data.__isset.dictionary_page_offset && chunk->meta_data.dictionary_page_offset >= 4) {
|
|
7288
|
-
// this assumes the data pages follow the dict pages directly.
|
|
7289
|
-
chunk_read_offset = chunk->meta_data.dictionary_page_offset;
|
|
7290
|
-
}
|
|
7291
|
-
group_rows_available = chunk->meta_data.num_values;
|
|
7292
|
-
}
|
|
7293
7275
|
virtual ~ColumnReader();
|
|
7294
7276
|
|
|
7277
|
+
public:
|
|
7278
|
+
static unique_ptr<ColumnReader> CreateReader(ParquetReader &reader, const LogicalType &type_p,
|
|
7279
|
+
const SchemaElement &schema_p, idx_t schema_idx_p, idx_t max_define,
|
|
7280
|
+
idx_t max_repeat);
|
|
7281
|
+
virtual void InitializeRead(const std::vector<ColumnChunk> &columns, TProtocol &protocol_p);
|
|
7295
7282
|
virtual idx_t Read(uint64_t num_values, parquet_filter_t &filter, uint8_t *define_out, uint8_t *repeat_out,
|
|
7296
7283
|
Vector &result_out);
|
|
7297
7284
|
|
|
7298
7285
|
virtual void Skip(idx_t num_values);
|
|
7299
7286
|
|
|
7300
|
-
const LogicalType &Type()
|
|
7301
|
-
|
|
7302
|
-
}
|
|
7303
|
-
|
|
7304
|
-
const SchemaElement &Schema() {
|
|
7305
|
-
return schema;
|
|
7306
|
-
}
|
|
7287
|
+
const LogicalType &Type();
|
|
7288
|
+
const SchemaElement &Schema();
|
|
7307
7289
|
|
|
7308
|
-
virtual idx_t GroupRowsAvailable()
|
|
7309
|
-
return group_rows_available;
|
|
7310
|
-
}
|
|
7290
|
+
virtual idx_t GroupRowsAvailable();
|
|
7311
7291
|
|
|
7312
|
-
unique_ptr<BaseStatistics> Stats(const std::vector<ColumnChunk> &columns)
|
|
7313
|
-
if (Type().id() == LogicalTypeId::LIST || Type().id() == LogicalTypeId::STRUCT ||
|
|
7314
|
-
Type().id() == LogicalTypeId::MAP) {
|
|
7315
|
-
return nullptr;
|
|
7316
|
-
}
|
|
7317
|
-
return ParquetTransformColumnStatistics(Schema(), Type(), columns[file_idx]);
|
|
7318
|
-
}
|
|
7292
|
+
unique_ptr<BaseStatistics> Stats(const std::vector<ColumnChunk> &columns);
|
|
7319
7293
|
|
|
7320
7294
|
protected:
|
|
7321
7295
|
// readers that use the default Read() need to implement those
|
|
7322
7296
|
virtual void Plain(shared_ptr<ByteBuffer> plain_data, uint8_t *defines, idx_t num_values, parquet_filter_t &filter,
|
|
7323
|
-
idx_t result_offset, Vector &result)
|
|
7324
|
-
|
|
7325
|
-
}
|
|
7326
|
-
|
|
7327
|
-
virtual void Dictionary(shared_ptr<ByteBuffer> dictionary_data, idx_t num_entries) {
|
|
7328
|
-
throw NotImplementedException("Dictionary");
|
|
7329
|
-
}
|
|
7330
|
-
|
|
7297
|
+
idx_t result_offset, Vector &result);
|
|
7298
|
+
virtual void Dictionary(shared_ptr<ByteBuffer> dictionary_data, idx_t num_entries);
|
|
7331
7299
|
virtual void Offsets(uint32_t *offsets, uint8_t *defines, idx_t num_values, parquet_filter_t &filter,
|
|
7332
|
-
idx_t result_offset, Vector &result)
|
|
7333
|
-
throw NotImplementedException("Offsets");
|
|
7334
|
-
}
|
|
7300
|
+
idx_t result_offset, Vector &result);
|
|
7335
7301
|
|
|
7336
7302
|
// these are nops for most types, but not for strings
|
|
7337
|
-
virtual void DictReference(Vector &result)
|
|
7338
|
-
|
|
7339
|
-
virtual void PlainReference(shared_ptr<ByteBuffer>, Vector &result) {
|
|
7340
|
-
}
|
|
7303
|
+
virtual void DictReference(Vector &result);
|
|
7304
|
+
virtual void PlainReference(shared_ptr<ByteBuffer>, Vector &result);
|
|
7341
7305
|
|
|
7342
7306
|
bool HasDefines() {
|
|
7343
7307
|
return max_define > 0;
|
|
@@ -7509,6 +7473,7 @@ public:
|
|
|
7509
7473
|
|
|
7510
7474
|
static unique_ptr<BaseStatistics> ReadStatistics(ParquetReader &reader, LogicalType &type, column_t column_index,
|
|
7511
7475
|
const duckdb_parquet::format::FileMetaData *file_meta_data);
|
|
7476
|
+
static LogicalType DeriveLogicalType(const SchemaElement &s_ele, bool binary_as_string);
|
|
7512
7477
|
|
|
7513
7478
|
private:
|
|
7514
7479
|
void InitializeSchema(const vector<LogicalType> &expected_types_p, const string &initial_filename_p);
|
|
@@ -7570,6 +7535,7 @@ namespace duckdb {
|
|
|
7570
7535
|
class BufferedSerializer;
|
|
7571
7536
|
class ParquetWriter;
|
|
7572
7537
|
class ColumnWriterPageState;
|
|
7538
|
+
class StandardColumnWriterState;
|
|
7573
7539
|
|
|
7574
7540
|
class ColumnWriterState {
|
|
7575
7541
|
public:
|
|
@@ -7580,30 +7546,44 @@ public:
|
|
|
7580
7546
|
vector<bool> is_empty;
|
|
7581
7547
|
};
|
|
7582
7548
|
|
|
7549
|
+
class ColumnWriterStatistics {
|
|
7550
|
+
public:
|
|
7551
|
+
virtual ~ColumnWriterStatistics();
|
|
7552
|
+
|
|
7553
|
+
virtual string GetMin();
|
|
7554
|
+
virtual string GetMax();
|
|
7555
|
+
virtual string GetMinValue();
|
|
7556
|
+
virtual string GetMaxValue();
|
|
7557
|
+
};
|
|
7558
|
+
|
|
7583
7559
|
class ColumnWriter {
|
|
7584
7560
|
//! We limit the uncompressed page size to 100MB
|
|
7585
7561
|
// The max size in Parquet is 2GB, but we choose a more conservative limit
|
|
7586
7562
|
static constexpr const idx_t MAX_UNCOMPRESSED_PAGE_SIZE = 100000000;
|
|
7587
7563
|
|
|
7588
7564
|
public:
|
|
7589
|
-
ColumnWriter(ParquetWriter &writer, idx_t schema_idx,
|
|
7565
|
+
ColumnWriter(ParquetWriter &writer, idx_t schema_idx, vector<string> schema_path, idx_t max_repeat,
|
|
7566
|
+
idx_t max_define, bool can_have_nulls);
|
|
7590
7567
|
virtual ~ColumnWriter();
|
|
7591
7568
|
|
|
7592
7569
|
ParquetWriter &writer;
|
|
7593
7570
|
idx_t schema_idx;
|
|
7571
|
+
vector<string> schema_path;
|
|
7594
7572
|
idx_t max_repeat;
|
|
7595
7573
|
idx_t max_define;
|
|
7596
7574
|
bool can_have_nulls;
|
|
7575
|
+
// collected stats
|
|
7576
|
+
idx_t null_count;
|
|
7597
7577
|
|
|
7598
7578
|
public:
|
|
7599
7579
|
//! Create the column writer for a specific type recursively
|
|
7600
7580
|
static unique_ptr<ColumnWriter> CreateWriterRecursive(vector<duckdb_parquet::format::SchemaElement> &schemas,
|
|
7601
7581
|
ParquetWriter &writer, const LogicalType &type,
|
|
7602
|
-
const string &name,
|
|
7603
|
-
idx_t
|
|
7582
|
+
const string &name, vector<string> schema_path,
|
|
7583
|
+
idx_t max_repeat = 0, idx_t max_define = 1,
|
|
7584
|
+
bool can_have_nulls = true);
|
|
7604
7585
|
|
|
7605
|
-
virtual unique_ptr<ColumnWriterState> InitializeWriteState(duckdb_parquet::format::RowGroup &row_group
|
|
7606
|
-
vector<string> schema_path);
|
|
7586
|
+
virtual unique_ptr<ColumnWriterState> InitializeWriteState(duckdb_parquet::format::RowGroup &row_group);
|
|
7607
7587
|
virtual void Prepare(ColumnWriterState &state, ColumnWriterState *parent, Vector &vector, idx_t count);
|
|
7608
7588
|
|
|
7609
7589
|
virtual void BeginWrite(ColumnWriterState &state);
|
|
@@ -7618,14 +7598,22 @@ protected:
|
|
|
7618
7598
|
void WriteLevels(Serializer &temp_writer, const vector<uint16_t> &levels, idx_t max_value, idx_t start_offset,
|
|
7619
7599
|
idx_t count);
|
|
7620
7600
|
|
|
7601
|
+
virtual duckdb_parquet::format::Encoding::type GetEncoding();
|
|
7602
|
+
|
|
7621
7603
|
void NextPage(ColumnWriterState &state_p);
|
|
7622
7604
|
void FlushPage(ColumnWriterState &state_p);
|
|
7605
|
+
void WriteDictionary(ColumnWriterState &state_p, unique_ptr<BufferedSerializer> temp_writer, idx_t row_count);
|
|
7606
|
+
|
|
7607
|
+
virtual void FlushDictionary(ColumnWriterState &state, ColumnWriterStatistics *stats);
|
|
7623
7608
|
|
|
7609
|
+
//! Initializes the state used to track statistics during writing. Only used for scalar types.
|
|
7610
|
+
virtual unique_ptr<ColumnWriterStatistics> InitializeStatsState();
|
|
7624
7611
|
//! Retrieves the row size of a vector at the specified location. Only used for scalar types.
|
|
7625
|
-
virtual idx_t GetRowSize(Vector &vector, idx_t index)
|
|
7612
|
+
virtual idx_t GetRowSize(Vector &vector, idx_t index);
|
|
7626
7613
|
//! Writes a (subset of a) vector to the specified serializer. Only used for scalar types.
|
|
7627
|
-
virtual void WriteVector(Serializer &temp_writer,
|
|
7628
|
-
idx_t chunk_start, idx_t chunk_end)
|
|
7614
|
+
virtual void WriteVector(Serializer &temp_writer, ColumnWriterStatistics *stats, ColumnWriterPageState *page_state,
|
|
7615
|
+
Vector &vector, idx_t chunk_start, idx_t chunk_end);
|
|
7616
|
+
|
|
7629
7617
|
//! Initialize the writer for a specific page. Only used for scalar types.
|
|
7630
7618
|
virtual unique_ptr<ColumnWriterPageState> InitializePageState();
|
|
7631
7619
|
//! Flushes the writer for a specific page. Only used for scalar types.
|
|
@@ -7633,6 +7621,8 @@ protected:
|
|
|
7633
7621
|
|
|
7634
7622
|
void CompressPage(BufferedSerializer &temp_writer, size_t &compressed_size, data_ptr_t &compressed_data,
|
|
7635
7623
|
unique_ptr<data_t[]> &compressed_buf);
|
|
7624
|
+
|
|
7625
|
+
void SetParquetStatistics(StandardColumnWriterState &state, duckdb_parquet::format::ColumnChunk &column);
|
|
7636
7626
|
};
|
|
7637
7627
|
|
|
7638
7628
|
} // namespace duckdb
|
|
@@ -7657,8 +7647,7 @@ public:
|
|
|
7657
7647
|
void Finalize();
|
|
7658
7648
|
|
|
7659
7649
|
static duckdb_parquet::format::Type::type DuckDBTypeToParquetType(const LogicalType &duckdb_type);
|
|
7660
|
-
static
|
|
7661
|
-
duckdb_parquet::format::ConvertedType::type &result);
|
|
7650
|
+
static void SetSchemaProperties(const LogicalType &duckdb_type, duckdb_parquet::format::SchemaElement &schema_ele);
|
|
7662
7651
|
|
|
7663
7652
|
private:
|
|
7664
7653
|
string file_name;
|