我正在使用以下方法在镶木地板文件中写入数据:
static void toParquet() {
String schema = "message spark_schema {\n optional binary stringField (UTF8);\n optional INT96 createdAt;\n}";
MessageType readSchema = MessageTypeParser.parseMessageType(schema);
Configuration configuration = new Configuration();
GroupWriteSupport.setSchema(readSchema, configuration);
SimpleGroupFactory sfg = new SimpleGroupFactory(readSchema);
Path file = new Path("/home/user/data-" + System.currentTimeMillis() + ".parquet");
try {
ParquetWriter<Group> writer = new ParquetWriter<Group>(file, new GroupWriteSupport(), CompressionCodecName.UNCOMPRESSED, 1024, 1024, 512,
true, false, ParquetProperties.WriterVersion.PARQUET_1_0, configuration);
for (int i = 0; i < 10000; ++i) {
writer.write(sfg.newGroup().append("stringField", "abc").append("createdAt", String.valueOf(System.currentTimeMillis())));
}
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
但它给了我以下例外:
java.lang.IllegalArgumentException:固定二进制大小 13 与 org.apache.parquet.column.values.plain.FixedLenByteArrayPlainValuesWriter.writeBytes(FixedLenByteArrayPlainValuesWriter.java:53) 中 org.apache.parquet.column.values 的字段类型长度 12 不匹配.dictionary.DictionaryValuesWriter$PlainFixedLenArrayDictionaryValuesWriter.createDictionaryPage(DictionaryValuesWriter.java:324) at org.apache.parquet.column.values.fallback.FallbackValuesWriter.createDictionaryPage(FallbackValuesWriter.java:102) at org.apache.parquet.column.impl.ColumnWriterV1 .flush(ColumnWriterV1.java:242) 在 org.apache.parquet.column.impl.ColumnWriteStoreV1.flush(ColumnWriteStoreV1.java:126) 在 org.apache.parquet.hadoop.InternalParquetRecordWriter.flushRowGroupToStore(InternalParquetRecordWriter.java:164) 在org.apache.parquet。hadoop.InternalParquetRecordWriter.checkBlockSizeReached(InternalParquetRecordWriter.java:141) at org.apache.parquet.hadoop.InternalParquetRecordWriter.write(InternalParquetRecordWriter.java:123) at org.apache.parquet.hadoop.ParquetWriter.write(ParquetWriter.java:288)在 com.app.test.SimpleParquet.toParquet(SimpleParquet.java:498) 在 com.app.test.SimpleParquet.main(SimpleParquet.java:63)
由于 System.currentTimeMillis() 给出 13 字节值,而 epoc 时间为 10 字节,如何为当前时间戳提供 int96 值,这是一个固定长度的 12 字节数组。
我发现一些线程,他们说时间戳是儒略日和纳秒时间的组合,我如何将当前时间戳转换为这种格式?