Я записываю фрейм данных в паркет, используя pyarrow в python.
import pyarrow as pa
import pyarrow.parquet as pq
import pandas as pd
df = pd.DataFrame(
{
"numbers": [1, 2, 3],
"colors": ["red", "white", "blue"],
"dates":['2019-12-16', '2019-12-16', '2019-12-16'],
"codes": [None, None, None]
}
)
table = pa.Table.from_pandas(df)
pq.write_table(table, "filename")
Файл паркета при чтении в Java (или в Sublime Text, настроенном с помощью инструментов паркет):
{"numbers":1,"codes":"R1"}
{"numbers":2,"codes":"G1"}
{"numbers":3,"codes":"B1"}
Код, который я использую для чтения паркета, таков:
class Parquet {
private List<SimpleGroup> data;
private List<Type> schema;
public Parquet(List<SimpleGroup> data, List<Type> schema) {
this.data = data;
this.schema = schema;
}
public List<SimpleGroup> getData() {
return data;
}
public List<Type> getSchema() {
return schema;
}
}
public static Parquet getParquetData(String filePath) throws IOException {
List<SimpleGroup> simpleGroups = new ArrayList<>();
ParquetFileReader reader = ParquetFileReader.open(HadoopInputFile.fromPath(new Path(filePath), new Configuration()));
MessageType schema = reader.getFooter().getFileMetaData().getSchema();
List<Type> fields = schema.getFields();
PageReadStore pages;
while ((pages = reader.readNextRowGroup()) != null) {
long rows = pages.getRowCount();
MessageColumnIO columnIO = new ColumnIOFactory().getColumnIO(schema);
RecordReader recordReader = columnIO.getRecordReader(pages, new GroupRecordConverter(schema));
for (int i = 0; i < rows; i++) {
SimpleGroup simpleGroup = (SimpleGroup) recordReader.read();
simpleGroups.add(simpleGroup);
}
}
reader.close();
return new Parquet(simpleGroups, fields);
}
}
Во время отладки я обнаружил, что хотя схема имеет все столбцы, в данных мы видим только ненулевые столбцы.
Кто-нибудь видел такое поведение? Есть ли какая-либо опция в библиотеке parquet-avro, чтобы не иметь этой «оптимизации»?
Спасибо