在 nodeJS 中,我尝试读取 Parquet 文件 (compression='snappy') 但没有成功。
我用了https://github.com/ironSource/parquetjs npm 模块打开本地文件并读取它,但 reader.cursor() 抛出神秘错误“尚未实现”。无论使用哪种压缩方式(plain、rle 或 snappy)来创建输入文件,它都会抛出相同的错误。
这是我的代码:
const readParquet = async (fileKey) => {
const filePath = 'parquet-test-file.plain'; // 'snappy';
console.log('----- reading file : ', filePath);
let reader = await parquet.ParquetReader.openFile(filePath);
console.log('---- ParquetReader initialized....');
// create a new cursor
let cursor = reader.getCursor();
// read all records from the file and print them
if (cursor) {
console.log('---- cursor initialized....');
let record = await cursor.next() ; // this line throws exception
while (record) {
console.log(record);
record = await cursor.next();
}
}
await reader.close();
console.log('----- done with reading parquet file....');
return;
};
调用阅读:
let dt = readParquet(fileKeys.dataFileKey);
dt
.then((value) => console.log('--------SUCCESS', value))
.catch((error) => {
console.log('-------FAILURE ', error); // Random error
console.log(error.stack);
})
更多信息: 1. 我使用 pyarrow.parquet 在 python 中生成了我的 Parquet 文件 2. 我在写入文件时使用了“SNAPPY”压缩 3. 我可以毫无问题地在 python 中读取这些文件 4. 每次编写 parquet 文件时,我的架构都不固定(未知)。我在写作时不创建模式。 5. error.stack 在控制台打印undefined 6. console.log('--------失败', 错误);打印“尚未实现”
我想知道是否有人遇到过类似的问题并且有想法/解决方案可以分享。顺便说一句,我的 Parquet 文件存储在 AWS S3 位置(与此测试代码不同)。我仍然需要找到从 S3 存储桶中读取 Parquet 文件的解决方案。
我们将不胜感激任何帮助、建议和代码示例。
最佳答案
使用 var AWS = require('aws-sdk');
从 S3 获取数据。
然后使用node-parquet
将parquet文件读入变量。
import np = require('node-parquet');
// Read from a file:
var reader = new np.ParquetReader(`file.parquet`);
var parquet_info = reader.info();
var parquet_rows = reader.rows();
reader.close();
parquet_rows = parquet_rows + "\n";
关于Javascript - 从 AWS s3 存储桶中读取 Parquet 数据(使用 snappy 压缩),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51411295/