forked from ankur-paan/ekuiper-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sql_casts.js
More file actions
46 lines (40 loc) · 1.52 KB
/
Copy pathtest_sql_casts.js
File metadata and controls
46 lines (40 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const http = require('https');
const payloads = [
{ id: "cast_quoted_type", sql: "SELECT * FROM sdm120_stream WHERE CAST(self AS 'string') = 'ON'" },
{ id: "cast_comma", sql: "SELECT * FROM sdm120_stream WHERE CAST(self, 'string') = 'ON'" },
{ id: "cast_bigint", sql: "SELECT * FROM sdm120_stream WHERE CAST(self AS bigint) = 1" },
{ id: "cast_self_project", sql: "SELECT CAST(self AS string) AS val FROM sdm120_stream" },
{ id: "self_to_string", sql: "SELECT * FROM sdm120_stream WHERE self::string = 'ON'" }
];
async function validate(payload) {
return new Promise((resolve) => {
const data = JSON.stringify({
id: "val_" + payload.id,
sql: payload.sql,
actions: [{ log: {} }]
});
const req = http.request('https://ruler1.i-dacs.com/rules/validate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
}, (res) => {
let body = '';
res.on('data', (chunk) => body += chunk);
res.on('end', () => {
resolve({ id: payload.id, status: res.statusCode, body });
});
});
req.on('error', (e) => resolve({ id: payload.id, error: e.message }));
req.write(data);
req.end();
});
}
async function run() {
for (const p of payloads) {
const res = await validate(p);
console.log(`Test ${res.id}: ${res.status} - ${res.body}`);
}
}
run();