0

I tried using parquetjs: https://www.npmjs.com/package/parquetjs

Code from their example:

var parquet = require('parquetjs');

// declare a schema for the `fruits` table
var schema = 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 writer = await parquet.ParquetWriter.openFile(schema, 'fruits.parquet');

// append a few rows to the file
await writer.appendRow({name: 'apples', quantity: 10, price: 2.5, date: new Date(), in_stock: true});
await writer.appendRow({name: 'oranges', quantity: 10, price: 2.5, date: new Date(), in_stock: true});

Error: SyntaxError: await is only valid in async function

What should be the problem (since they posted this as example)?

Joe
  • 11,983
  • 31
  • 109
  • 183

1 Answers1

0
SyntaxError: await is only valid in async function

What that means is you can await keyword in only a function which has async keyword in the function signature.

As a quick work around, you can use a async IIFE.

(async() => {
    // create new ParquetWriter that writes to 'fruits.parquet'
    var writer = await parquet.ParquetWriter.openFile(schema, 'fruits.parquet');

    // append a few rows to the file
    await writer.appendRow({name: 'apples', quantity: 10, price: 2.5, date: new Date(), in_stock: true});
    await writer.appendRow({name: 'oranges', quantity: 10, price: 2.5, date: new Date(), in_stock: true});
})()
Anand Undavia
  • 3,493
  • 5
  • 19
  • 33