Reading Parquet files
#include "arrow/parquet/arrow/reader.h"{...arrow::Status st;arrow::MemoryPool* pool = default_memory_pool();std::shared_ptr<arrow::io::RandomAccessFile> input = ...;Open Parquet file readerstd::unique_ptr<parquet::arrow::FileReader> arrow_reader;st = parquet::arrow::OpenFile(input, pool, &arrow_reader);if (!st.ok()) {Handle error instantiating file reader...}Read entire file as a single Arrow tablestd::shared_ptr<arrow::Table> table;st = arrow_reader->ReadTable(&table);if (!st.ok()) {Handle error reading Parquet data...}}
The StreamReader allows for Parquet files to be read using standard C++ input operators which ensures type-safety. StreamReader允许使用标准C++输入运算符读取Parquet文件,从而确保类型安全。Please note that types must match the schema exactly i.e. if the schema field is an unsigned 16-bit integer then you must supply a uint16_t type. 请注意,类型必须与模式完全匹配,即如果模式字段是无符号16位整数,则必须提供uint16_t类型。Exceptions are used to signal errors. A ParquetException is thrown in the following circumstances: Attempt to read field by supplying the incorrect type\Attempt to read beyond end of row\Attempt to read beyond end of file. 异常用于发出错误信号。在以下情况下会引发ParquetException:通过提供错误类型尝试读取字段\尝试读取超出行结尾\尝试读取超过文件结尾。
#include "arrow/io/file.h"#include "parquet/stream_reader.h"{std::shared_ptr<arrow::io::ReadableFile> infile;PARQUET_ASSIGN_OR_THROW( infile, arrow::io::ReadableFile::Open("test.parquet"));parquet::StreamReader os{parquet::ParquetFileReader::Open(infile)};std::string article; float price; uint32_t quantity;while ( !os.eof() ) {os >> article >> price >> quantity >> parquet::EndRow;...}}
Writing Parquet files
The arrow::WriteTable() function writes an entire ::arrow::Table to an output file. arrow::WriteTable()函数的作用是将整个::arrow::Table写入输出文件。
#include "parquet/arrow/writer.h"{std::shared_ptr<arrow::io::FileOutputStream> outfile;PARQUET_ASSIGN_OR_THROW( outfile, arrow::io::FileOutputStream::Open("test.parquet"));PARQUET_THROW_NOT_OK(parquet::arrow::WriteTable(table, arrow::default_memory_pool(), outfile, 3));}
The StreamWriter allows for Parquet files to be written using standard C++ output operators. This type-safe approach also ensures that rows are written without omitting fields and allows for new row groups to be created automatically (after certain volume of data) or explicitly by using the EndRowGroup stream modifier. Exceptions are used to signal errors. A ParquetException is thrown in the following circumstances: Attempt to write a field using an incorrect type\Attempt to write too many fields in a row\Attempt to skip a required field. StreamWriter允许使用标准C++输出运算符写Parquet文件。这种类型安全的方法还可以确保在不省略字段的情况下写入行,并允许自动(在一定数量的数据之后)或使用EndRowGroup流修饰符显式地创建新的行组。异常用于发出错误信号。在以下情况下会引发ParquetException:尝试使用错误类型写入字段\尝试在行中写入过多字段\尝试跳过所需字段。
#include "arrow/io/file.h"#include "parquet/stream_writer.h"{std::shared_ptr<arrow::io::FileOutputStream> outfile;PARQUET_ASSIGN_OR_THROW( outfile, arrow::io::FileOutputStream::Open("test.parquet"));parquet::WriterProperties::Builder builder;std::shared_ptr<parquet::schema::GroupNode> schema;// Set up builder with required compression type etc.// Define schema.// ...parquet::StreamWriter os{ parquet::ParquetFileWriter::Open(outfile, schema, builder.build())};// Loop over some data structure which provides the required// fields to be written and write each row.for (const auto& a : getArticles()){os << a.name() << a.price() << a.quantity() << parquet::EndRow;}}

Parquet格式是一种用于复杂数据的节省空间的柱状存储格式。Parquet C++实现是Apache Arrow项目的一部分,并得益于与Arrow C++类和工具的紧密集成。The Parquet format is a space-efficient columnar storage format for complex data. The Parquet C++ implementation is part of the Apache Arrow project and benefits from tight integration with the Arrow C++ classes and facilities.
Supported Parquet features
Parquet格式有许多功能,Parquet C++支持其中的一个子集。The Parquet format has many features, and Parquet C++ supports a subset of them.
Page types
Unsupported page type: INDEX_PAGE. When reading a Parquet file, pages of this type are ignored. 不支持的页面类型:INDEX_page。读取Parquet文件时,将忽略此类型的页面。

Compression
Unsupported compression codec: LZO.

(1) On the read side, Parquet C++ is able to decompress both the regular LZ4 block format and the ad-hoc Hadoop LZ4 format used by the reference Parquet implementation. On the write side, Parquet C++ always generates the ad-hoc Hadoop LZ4 format.
Encodings

(1) Only supported for encoding definition and repetition levels, not values.
(2) On the write path, RLE_DICTIONARY is only enabled if Parquet format version 2.4 or greater is selected in WriterProperties::version().
Types
Physical types

(1) Can be mapped to other Arrow types, depending on the logical type (see below). 根据逻辑类型,可以映射到其他arrow类型(见下文)。
(2) On the write side, ArrowWriterProperties::support_deprecated_int96_timestamps() must be enabled.
(3) On the write side, an Arrow LargeBinary can also mapped to BYTE_ARRAY. 在写端,Arrow LargeBinary也可以映射到BYTE_ARRAY。
Logical types
Specific logical types can override the default Arrow type mapping for a given physical type. 特定逻辑类型可以覆盖给定物理类型的默认箭头类型映射。

欢迎关注微信公众号肥叔菌PostgreSQL数据库专栏:
PostgreSQL数据库守护进程——Postmaster总体流程
PostgreSQL数据库守护进程——读取控制文件
PostgreSQL数据库守护进程——RemovePgTempFiles删除临时文件
PostgreSQL数据库守护进程——RemovePromoteSignalFiles
PostgreSQL数据库信号处理——kill backend
PostgreSQL数据库PMsignal——后端进程\Postmaster信号通信
PostgreSQL数据库后端进程——inter-process latch
PostgreSQL数据库后端进程——监视postmaster death
PostgreSQL数据库后台进程——一等公民
PostgreSQL数据库后台进程——后台一等公民进程保活
PostgreSQL数据库头胎——后台一等公民进程StartupDataBase启动
PostgreSQL数据库头胎——后台一等公民进程StartupDataBase信号通知
PostgreSQL数据库头胎——StarupXLOG函数恢复模式和目标
PostgreSQL数据库状态pmState——PM_STARTUP状态
PostgreSQL数据库复制——Setting Up Asynchronous Replication
PostgreSQL数据库复制——后台一等公民进程WalReceiver启动函数
PostgreSQL数据库复制——后台一等公民进程WalReceiver获知连接
PostgreSQL数据库复制——后台一等公民进程WalReceiver&startup交互
PostgreSQL数据库复制——后台一等公民进程WalReceiver ready_to_display
PostgreSQL数据库复制——后台一等公民进程WalReceiver提取信息
PostgreSQL数据库复制——后台一等公民进程WalReceiver收发逻辑
PostgreSQL数据库复制——后台一等公民进程WalReceiver pg_stat_wal_receiver视图
PostgreSQL数据库复制——walsender后端启动
PostgreSQL数据库守护进程——后台二等公民进程第一波启动maybe_start_bgworkers
PostgreSQL数据库参数——简述GUC
PostgreSQL数据库网络层——libpq连接参数
PostgreSQL数据库动态共享内存管理器——dynamic shared memory segment
PostgreSQL数据库WAL——资源管理器RMGR
PostgreSQL数据库WAL——备机回放checkpoint WAL
PostgreSQL数据库事务系统——phenomena
PostgreSQL数据库统计信息——analyze命令
PostgreSQL数据库统计信息——analyze大致流程
PostgreSQL数据库统计信息——analyze执行函数
PostgreSQL数据库统计信息——查找继承子表find_all_inheritors
PostgreSQL数据库统计信息——analyze流程对不同表的处理
PostgreSQL数据库统计信息——examine_attribute单列预分析
PostgreSQL数据库统计信息——acquire_sample_rows采样函数
PostgreSQL数据库统计信息——acquire_inherited_sample_rows采样函数
PostgreSQL数据库统计信息——计算统计数据
PostgreSQL数据库统计信息——compute_scalar_stats计算统计数
PostgreSQL数据库统计信息——analyze统计信息收集
PostgreSQL数据库统计信息——统计信息系统表
PostgreSQL守护进程(Postmaster)——辅助进程PgStat主流程
PostgreSQL守护进程(Postmaster)——辅助进程PgStat统计消息
PostgreSQL数据库查询监控技术——pg_stat_activity简介
PostgreSQL查询引擎——编译调试
PostgreSQL查询引擎——create table xxx(...)基础建表流程
PostgreSQL查询引擎——create table xxx(...)基础建表transformCreateStmt
PostgreSQL查询引擎——select * from where = transform流程
PostgreSQL数据库查询执行——T_VariableSetStmt
PostgreSQL数据库查询执行——T_TransactionStmt
PostgreSQL数据库查询执行——Parallel Query
PostgreSQL数据库查询执行——SeqScan节点执行
PostgreSQL数据库查询执行——Using GDB To Trace Into a Parallel Worker Spawned By Postmaster During a Large Query
PostgreSQL数据库查询执行——Parallel SeqScan节点执行
PostgreSQL数据库可插拔存储引擎——pg_am系统表
PostgreSQL数据库可插拔存储引擎——Table Access Manager
PostgreSQL数据库可插拔存储引擎——GetTableAmRoutine函数
PostgreSQL数据库可插拔存储引擎——Table scan callbacks
PostgreSQL数据库HeapAM——TupleTableSlot类型
PostgreSQL数据库HeapAM——HeapAM Scan
PostgreSQL数据库HeapAM——HeapAM Parallel table scan
PostgreSQL数据库HeapAM——synchronized scan machinery
PostgreSQL数据库缓冲区管理器——概述
PostgreSQL数据库缓冲区管理器——本地缓冲区管理
PostgreSQL数据库缓冲区管理器——Shared Buffer Pool初始化
PostgreSQL数据库存储介质管理器——SMGR
PostgreSQL数据库存储介质管理器——磁盘管理器
PostgreSQL数据库目录——目录操作封装
PostgreSQL虚拟文件描述符VFD机制——FD LRU池
PostgreSQL虚拟文件描述符VFD机制——FD LRU池其他函数
PostgreSQL数据库FDW——The Internals of PostgreSQL
PostgreSQL数据库FDW——WIP PostgreSQL Sharding
PostgreSQL数据库FDW——Parquet S3 Foreign Data Wrapper
PostgreSQL数据库FDW——Parquet S3 ParquetReader类
PostgreSQL数据库FDW——Parquet S3 ReaderCacheEntry
PostgreSQL数据库FDW——Parquet S3 ParallelCoordinator
PostgreSQL数据库FDW——Parquet S3 DefaultParquetReader类
PostgreSQL数据库FDW——Parquet S3 CachingParquetReader类
PostgreSQL数据库FDW——Parquet S3 ParquetS3FdwExecutionState类
PostgreSQL数据库FDW——Parquet S3 MultifileMergeExecutionStateBaseS3类
PostgreSQL数据库FDW——Parquet S3 读取parquet文件用例
PostgreSQL数据库使用——between and以及日期的使用
PostgreSQL数据库使用——iRedMail定时备份数据库脚本
PostgreSQL数据库使用——iRedMail初始化数据库脚本
PostgreSQL数据库使用——iRedMail创建用户脚本
PostgreSQL数据库插件——定时任务pg_cron
PostgreSQL数据库故障分析——invalid byte sequence for encoding
ETCD、Zookeeper和Consul 分布式数据库的魔法银弹
PostgreSQL数据库高可用——patroni介绍[翻译]
PostgreSQL数据库高可用——patroni配置[翻译]
PostgreSQL数据库高可用——patroni REST API[翻译]
PostgreSQL数据库高可用——将独立集群转换为Patroni集群[翻译]
PostgreSQL数据库高可用——patroni源码学习
PostgreSQL数据库高可用——patroni源码学习——abstract_main
PostgreSQL数据库高可用——patroni源码AbstractPatroniDaemon类
PostgreSQL数据库高可用——patroni源码Patroni子类简介
PostgreSQL数据库高可用——patroni源码PatroniLogger类
PostgreSQL数据库高可用——patroni RestApiServer
PostgreSQL数据库高可用——patroni源码DCS类
PostgreSQL数据库高可用——patroni源码AbstractEtcd类
PostgreSQL数据库高可用——patroni源码EtcdClient类
PostgreSQL数据库高可用——patroni源码Etcd
PostgreSQL数据库高可用——patroni源码学习——Ha类概述
PostgreSQL数据库高可用——Patroni AsyncExecutor类
PostgreSQL数据库高可用——Patroni PostmasterProcess类
PostgreSQL数据库备份恢复迁移——Barman Before you start[翻译]
PostgreSQL数据库备份恢复迁移——Barman Introduction[翻译]
Postgres-XL数据库GTM——概念
Postgres-XL数据库GTM——事务管理
Postgres-XL数据库GTM——GTM and Global Transaction Management[翻译]
Postgres-XL数据库GTM——Master & Standby启动流程
Postgres-XL数据库GTM——Master & Standby子线程
Postgres-XL数据库GTM——Node管理器
Greenplum数据库统计信息——analyze命令 Greenplum数据库统计信息——分布式采样 Greenplum数据库统计信息——auto-analyze特性 Greenplum数据库Hash分布——计算哈希值和映射segment Greenplum数据库Hash分布——GUC gp_use_legacy_hashops Greenplum数据库数据分片策略Hash分布——执行器行为 Greenplum数据库过滤投影——ExecScan执行逻辑 Greenplum数据库外部表——Scan执行节点 Greenplum数据库外部表——fileam封装 Greenplum数据库外部表——external_getnext获取元组 Greenplum数据库外部表——url_curl创建销毁 Greenplum数据库外部协议——Define EXTPROTOCOL Greenplum数据库外部协议——GPHDFS实现协议 Greenplum数据库外部协议——GPHDFS gphdfs_fopen HashData数据库外部表——GPHDFS实现简介 Greenplum数据库高可用——FTS进程 Greenplum数据库高可用——FTS进程ftsConnect Greenplum数据库高可用——FTS进程触发轮询 Greenplum数据库高可用——FTS进程ftsPoll\Send\Receive Greenplum数据库高可用——FTS Pull模型 Greenplum数据库高可用——FTS HandleFtsWalRepProbe函数 Greenplum数据库高可用——FTS HandleFtsWalRepSyncRepOff函数 Greenplum数据库高可用——FTS HandleFtsWalRepPromote函数 Greenplum数据库高可用——FTS processRetry函数 Greenplum数据库高可用——FTS processResponse函数 Greenplum数据库高可用——FTS updateConfiguration更新系统表 Greenplum Python专用库gppylib学习——logging模块 Greenplum Python专用库gppylib学习——GpArray
Greenplum Python专用库gppylib学习——base.py
Greenplum Python工具库gpload学习——gpload类
Greenplum数据库源码分析——Standby Master操作工具分析
Greenplum数据库故障分析——利用GDB调试多线程core文件
Greenplum数据库故障分析——semop(id=,num=11) failed:invalid argument
Greenplum数据库故障分析——能对数据库base文件夹进行软连接嘛
Greenplum数据库故障分析——UDP Packet Lost(packet reassembles failed)
Greenplum数据库故障分析——版本升级后gpstart -a为何返回失败
Greenplum数据库故障分析——can not listen port
HAWQ数据库技术解析——内部架构
HAWQ数据库技术解析(一)——HAWQ简介[转载]
Apache Arrow User Guide——Reading and writing Parquet files




