From e287d60f249d4ae038aaf816b99a56ef64e0389f Mon Sep 17 00:00:00 2001 From: admin <2775444633@qq.com> Date: Tue, 24 Nov 2026 18:16:39 +0000 Subject: [PATCH] chore: sync ops/trq.js --- ops/trq.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 ops/trq.js diff --git a/ops/trq.js b/ops/trq.js new file mode 100644 index 0000000..fca2bef --- /dev/null +++ b/ops/trq.js @@ -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); }); \ No newline at end of file