【问题标题】:Reading a parquet file in nodejs在nodejs中读取镶木地板文件
【发布时间】:2021-01-12 11:19:36
【问题描述】:

我正在尝试使用以下代码(来自 parquetjs-lite 和 stackoverflow 示例)来读取 nodejs 中的 parquet 文件:

const readParquetFile = async () => {
try {
       // create new ParquetReader that reads from test.parquet
       let reader = await parquet.ParquetReader.openFile('test.parquet');
    }
catch (e){
    console.log(e); 
    throw e;
  }
 
// create a new cursor
let cursor = reader.getCursor();
 
// read all records from the file and print them
let record = null;
while (record = await cursor.next()) {
  console.log(record);
}

await reader.close();

  };

当我运行这段代码时,什么也没有发生。控制台没有写入任何内容,出于测试目的,我只使用了一个小的 csv 文件,我使用 python 将其转换为 parquet。

  1. 是因为我已经使用 python 从 csv 转换为 parquet(我找不到任何 JS 等价于我最终必须能够使用的大文件)。
  2. 我希望我的应用程序能够接收并读取任何 parquet 文件。 parquetjs-lite 在这方面是否有任何限制。
  3. 我的 CSV 中有 NaN 值,这可能是个问题吗?

任何指针都会有所帮助。

谢谢

【问题讨论】:

    标签: javascript node.js apache parquet apache-arrow


    【解决方案1】:

    可能的失败案例是

    您在没有运行网络服务器的情况下在某个文件中调用此函数。 在这种情况下,文件将以异步模式运行,并且当异步函数进入回调堆栈并且您的主堆栈为空时,程序将结束,即使您的调用堆栈中有代码,它也不会运行或记录任何内容。

    要解决这个问题,请尝试运行网络服务器或更好地使用同步调用

    //app.js(无网络服务器)

    const readParquetFile = async () => {
        console.log("running")
    }
    readParquetFile()
    console.log("exit")
    

    当你运行上面的代码时,输​​出将是

    exit
    

    //syncApp.js

    const readParquetFile = () => {
        console.log("running")
        // all function should be sync
    }
    readParquetFile()
    console.log("exit")
    

    控制台日志将在此处

    running
    exit
    

    【讨论】:

      猜你喜欢
      • 2015-06-21
      • 2022-11-24
      • 2019-08-04
      • 2022-06-16
      • 1970-01-01
      • 2019-09-23
      • 2017-12-27
      • 2017-05-06
      • 2018-08-13
      相关资源
      最近更新 更多