chore: sync ops/trq.js
This commit is contained in:
1 parent
162d4a904b
commit
e287d60f24
1 file changed
+23
+23
@@ -0,0 +1,23 @@
|
||||
// usage: node ops/trq.js "SQL" [user]
|
||||
const sql = process.argv[2];
|
||||
const user = process.argv[3] || 'ops';
|
||||
const base = process.env.TRINO_URL || 'http://localhost:8090';
|
||||
async function main() {
|
||||
let r = await fetch(base + '/v1/statement', { method: 'POST', headers: { 'X-Trino-User': user, 'Content-Type': 'text/plain' }, body: sql });
|
||||
let j = await r.json();
|
||||
let cols = null, rows = [];
|
||||
for (let i = 0; i < 600; i++) {
|
||||
if (j.error) { console.log('ERROR', JSON.stringify(j.error).slice(0, 800)); process.exit(1); }
|
||||
if (j.columns && !cols) cols = j.columns.map(c => c.name);
|
||||
if (j.data) rows.push(...j.data);
|
||||
if (!j.nextUri) break;
|
||||
await new Promise(res => setTimeout(res, 200));
|
||||
r = await fetch(j.nextUri, { headers: { 'X-Trino-User': user } });
|
||||
j = await r.json();
|
||||
}
|
||||
console.log('STATE', j.stats && j.stats.state);
|
||||
if (cols) console.log(cols.join('\t'));
|
||||
for (const row of rows.slice(0, 60)) console.log(row.map(v => v === null ? 'NULL' : String(v)).join('\t'));
|
||||
console.log('ROWS', rows.length);
|
||||
}
|
||||
main().catch(e => { console.log('FAIL', e.message); process.exit(1); });
|
||||
Reference in new issue
Block a user