Skip to content

Need help to know how to fetch/consolidate query result #778

@yash-chaudharii25

Description

@yash-chaudharii25

Hi Team,

I am not getting result of query in one go, however I am getting few records at a time.

I am using code as mentioned below:

// Example (adapt to your trino-client version and authentication method)
import {Trino, BasicAuth} from 'trino-client';

async function test()
{
  const sslOption = {
    rejectUnauthorized: false
  }

  const client = Trino.create({
    server: 'https://abc-trino.env.xyz.example.com',
    catalog: 'iceberg',
    auth: new BasicAuth('username', 'password'),
    ssl: sslOption
  });

  console.log('client - ', JSON.stringify(client))

  const iterData = await client.query('select * from table_name')
  console.log('iterData - ', JSON.stringify(iterData))

  for await (const queryResult of iterData) {
// this part is getting call/executed multiple time to return the query result
    console.log('Header: ', queryResult.data);
  }
  
}
await test();

Could anyone please help me know if trino client supports something like mentioned in below example:

const stream = await client.queryStream('SELECT * FROM your_table');

   stream.on('data', (row) => {
       // Process each row as it comes
       console.log(row);
   });

   stream.on('end', () => {
       console.log('Query completed');
       client.end();
   });

   stream.on('error', (error) => {
       console.error('Error:', error);
       client.end();
   });

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions