来自 npm 注册表的 apache-arrow 从 aws s3 存储桶读取 parquet 文件

问题描述 投票:0回答:1

我正在使用打字稿。 使用 aws-sdk 和 apache-arrow lib 读取镶木地板文件 s3 存储桶中的 Parquet 文件大小为 49KB

import { tableFromJSON, Table, tableFromIPC } from 'apache-arrow';
...

public static readParquetFile = async (bucket: string, key: string): Promise<Table | null> => {
    const s3 = new AWS.S3();

    try {
      // Fetch the object from S3
      const { Body } = await s3.getObject({ Bucket: bucket, Key: key }).promise();

      if (Body) {
        // Read the Parquet file using Apache Arrow
        const table = tableFromIPC(new Uint8Array(Body as Buffer));
        return table;
      } else {
        console.error('Empty file or file not found.');
        return null;
      }
    } catch (error) {
      console.error('Error reading Parquet file:', error);
      return null;
    }
  };

这个函数在我的 lambda 代码中的使用是这样的......

...
try {
      const table = await Utility.readParquetFile(bucketName, fileName);
      if (table) {
        // Convert the table to string content
        const stringContent = table.toString();
        

        // Process content line by line
        const strRecords = stringContent.split('\n');
       

        await Promise.all(
          strRecords.map(async (strRecord: string) => {
            await publishRecord(
              record,
              strRecord, 
              snsTopic,
              snsClient,
              loggingContext
            );
          })
        );
      } else {
        throw new Error('Failed to read Parquet file');
      }
    } catch (error: any) {
     console.error('Error reading Parquet file:', error);
      throw error;
    }
    ...
    ...`

我在 lambda 执行时收到此错误:读取 Parquet 文件时出错:错误:预期读取 827474256 元数据字节,但仅读取 49256。这里出了什么问题?使用 python 库可以很好地读取 Parquet 文件,但使用 ts lib 则不行。

期望 parquet 文件能够被很好地读取并将每条记录发布到 SNS 主题

typescript apache-arrow
1个回答
0
投票

您好,我遇到了同样的错误。你找到解决办法了吗?

© www.soinside.com 2019 - 2024. All rights reserved.