问题描述
我有一个实木复合地板文件,其中包含许多类型为converted_type (legacy): TIMESTAMP_MICROS
的列。我想检查标志isAjustedToUTC
是否为真。我可以这样:
import pyarrow.parquet as pq
import re
arrow = pq.ParquetFile("/Parquet/File/Path/filename.parquet")
timestamp_string = str(arrow.Metadata.row_group(0).column(79).statistics.logical_type)
re.search("isAdjustedToUTC=(.*),timeUnit",timestamp_string).group(1)
这给了我true
或false
作为字符串。是否有另一种无需使用正则表达式来检索isAdjustedToUTC
的值的方法?
解决方法
据我所知这是不可能的。 logical_type
的类型为pyarrow._parquet.ParquetLogicalType
,不会直接公开其基础成员。
唯一可用的字段是:
dir(logical_type)
>> ['__class__','__delattr__','__dir__','__doc__','__eq__','__format__','__ge__','__getattribute__','__gt__','__hash__','__init__','__init_subclass__','__le__','__lt__','__ne__','__new__','__pyx_vtable__','__reduce__','__reduce_ex__','__repr__','__setattr__','__setstate__','__sizeof__','__str__','__subclasshook__','to_json','type']
您可以使用to_json
函数,但是它与您建议的选项一样脏:
import json
json.loads(logical_type.to_json())['isAdjustedToUTC']
>> true