0
votes

I am trying to invoke Presto Query via nodejs to fetch the results back to a js variable using presto-stream-client (https://www.npmjs.com/package/presto-stream-client). The nodejs is running in aws lambda. My current test code is as follows. The code exits with error stating file /tmp/test.txt don't exists. So I assume client.execute(query) failed to generate a test.txt data file. However no error is logged from query execute part. it will be great if someone could shed some light here.

const fs = require('fs');
const util = require('util');
const pipeline = util.promisify(require('stream').pipeline);
const { Client } = require('presto-stream-client');

    //Presto query
    
    const client = new Client({
        user: 'presto',
        host: "presto-host-url",
        port: "8080",
        catalog: 'catalogname',
        schema:  'schemaname'
    }); 
    
(async ()=>{
    const statement = await client.execute({query:'SELECT mydata FROM catalog.schema.myprestotable',
          success: function(error, stats){  console.log(" error on success : " + error); },
          error:   function(error){ console.log(" error on failure : " + error); }
    });

    const writeStream = fs.createWriteStream('/tmp/test.txt');

    statement.on('state_change',(currentState,stats)=>{
        console.log(`state changed to ${currentState} for query ${statement.query_id}`);
        console.log(stats);
    });
    await pipeline(statement,writeStream);

})();

var content = fs.readFileSync('/tmp/test.txt','utf8');
console.log(content)