一.概述
schema演进一般用于表的列变换(如增加/删除/调整列位置)和修改列类型的场景下查询能正常使用。本文主要介绍Presto中是如何支持Parquet文件的Schema演进的。
要在presto中支持schema演进,需要开启parquet_use_column_names。
在presto中,存在着三种shcema:分别是:
表schema:表的schema指的就是create table时候指定的schema结构。
partition schema:partition schema指的是创建分区时候的表schema接口,partition schema创建后不随着表的schema变化而变换。
parquet文件schema:parquet文件本身也有一个schema,在parquet文件内部,按照parquet的标准组织着,不随查询引擎变换而变换。
二. presto支持schema演进的整体方案
三. 代码走读
-
创建table schema到partition schema映射关系:
HiveSplitManager::getPartitionMetadata
getTableToPartitionMapping
getTableToPartitionMappingByColumnNames
columnCoercions.put
2. 使用parition schema读parquet文件:
ParquetPageSourceFactory ::createPageSource
trinoTypes.add(column.getBaseType()); //这里的column类型是上边Mapping过后的column,也就是说partition类型
new ParquetPageSource(..., trinoTypes.build(),...)
new ParquetReader
columnReaders[columnIO.getId()] = PrimitiveColumnReader.createReader(column, timeZone); //根据partition类型创建reader