首页 > 解决方案 > javascript 无法写入镶木地板文件(始终为 1kb)

问题描述

我想弄清楚如何使用nodejs创建数据并将其写入镶木地板文件。我在下面创建了非常简单的代码:

var parquet = require('parquetjs');

init();

async function init(){
    console.log('BEGIN DEBUG PARQUET')
    var debugschema = new parquet.ParquetSchema({
        name: { type: 'UTF8' },
        quantity: { type: 'INT64' },
        price: { type: 'DOUBLE' },
        date: { type: 'TIMESTAMP_MILLIS' },
        in_stock: { type: 'BOOLEAN' }
      });
    // create new ParquetWriter that writes to 'fruits.parquet`
    var debugwriter = await parquet.ParquetWriter.openFile(debugschema, `./DEBUGPARQUET.parquet`);
    // append a few rows to the file
    await debugwriter.appendRow({name: 'apples', quantity: 10, price: 2.5, date: new Date(), in_stock: true});
    await debugwriter.appendRow({name: 'apples', quantity: 10, price: 2.5, date: new Date(), in_stock: true});
    await debugwriter.appendRow({name: 'apples', quantity: 10, price: 2.5, date: new Date(), in_stock: true});
    await debugwriter.appendRow({name: 'apples', quantity: 10, price: 2.5, date: new Date(), in_stock: true});
    await debugwriter.appendRow({name: 'apples', quantity: 10, price: 2.5, date: new Date(), in_stock: true});
    await debugwriter.appendRow({name: 'apples', quantity: 10, price: 2.5, date: new Date(), in_stock: true});
    console.log('END DEBUG PARQUET')
}

node index.js在 Windows 10 命令提示符终端中使用命令运行,文件运行没有错误,现在我有一个DEBUGPARQUET.parquet只有 1 kb 大小的文件,我根本无法打开这个文件来查看镶木地板数据(我尝试安装 apache parquet view 程序并使用它,但它不起作用,我无法在带有 parquet 扩展名的 vscode 中查看文件的内容,并且查看 parquet 文件的在线站点也不起作用)

我的代码中是否缺少某些内容?还是在 Windows 10 上编写镶木地板文件有问题?

标签: javascriptnode.jsparquet

解决方案


var debugwriter = await parquet.ParquetWriter.openFile(debugschema, `./DEBUGPARQUET.parquet`);
    // append a few rows to the file
    await debugwriter.appendRow({name: 'apples', quantity: 10, price: 2.5, date: new Date(), in_stock: true});
    await debugwriter.appendRow({name: 'apples', quantity: 10, price: 2.5, date: new Date(), in_stock: true});
    await debugwriter.appendRow({name: 'apples', quantity: 10, price: 2.5, date: new Date(), in_stock: true});
    await debugwriter.appendRow({name: 'apples', quantity: 10, price: 2.5, date: new Date(), in_stock: true});
    await debugwriter.appendRow({name: 'apples', quantity: 10, price: 2.5, date: new Date(), in_stock: true});
    await debugwriter.appendRow({name: 'apples', quantity: 10, price: 2.5, date: new Date(), in_stock: true});
await debugwriter.close();
console.log('END DEBUG PARQUET')

推荐阅读