Skip to content

Commit 47f8dbe

Browse files
committed
Supports rowsort
1 parent b198157 commit 47f8dbe

File tree

5 files changed

+112
-64
lines changed

5 files changed

+112
-64
lines changed

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,31 @@ The goal (for now) is not to pass all the tests, but to help us describe (in the
4848

4949
The format of the tests are desribed here: http://www.sqlite.org/sqllogictest/doc/trunk/about.wiki
5050

51+
Supported
52+
---------
53+
54+
- Verify that the parser parses all the tests
55+
56+
- Floating point values are rendered as if by printf("%.3f").
57+
58+
- NULL values are rendered as "NULL". Empty strings are rendered as "(empty)". Within non-empty strings, all control characters and unprintable characters are rendered as "@".
59+
60+
5161

5262

5363
ToDo
5464
----
5565

56-
- Verify that the parser parses all the tests (ongoing development in the sqllogivtestparserV2.js)
5766

58-
- Implement verification of returned valued with sortorder set
5967

6068
- Change the compabillity flags in alasql accordng to whats mimicked
6169

6270
- implement:
6371
> The <label> argument is also optional. If included, sqllogictest stores a hash of the results of this query under the given label. If the label is reused, then sqllogictest verifies that the results are the same. This can be used to verify that two or more queries in the same test script that are logically equivalent always generate the same output.
6472
65-
- Implement:
66-
> Floating point values are rendered as if by printf("%.3f").
6773

68-
- Implement:
69-
> NULL values are rendered as "NULL". Empty strings are rendered as "(empty)". Within non-empty strings, all control characters and unprintable characters are rendered as "@".
7074

71-
72-
- Implement
75+
- Implement verification of returned valued with sortorder set
7376
> The <sort-mode> argument is optional. If included, it must be one of "nosort", "rowsort", or "valuesort". The default is "nosort". In nosort mode, the results appear in exactly the order in which they were received from the database engine. The nosort mode should only be used on queries that have an ORDER BY clause or which only have a single row of result, since otherwise the order of results is undefined and might vary from one database engine to another. The "rowsort" mode gathers all output from the database engine then sorts it by rows on the client side. Sort comparisons use strcmp() on the rendered ASCII text representation of the values. Hence, "9" sorts after "10", not before. The "valuesort" mode works like rowsort except that it does not honor row groupings. Each individual result value is sorted on its own.
7477
7578
**Not ToDo**

sqllogic/demo.test

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ SELECT a+b*2+c*3+d*4+e*5,
8787
----
8888
60 values hashing to 808146289313018fce25f1a280bd8c30
8989

90-
halt
90+
#halt
9191

9292
query IIIII nosort
9393
SELECT a+b*2+c*3+d*4+e*5,
@@ -113,4 +113,5 @@ SELECT CASE WHEN c>(SELECT avg(c) FROM t1) THEN a*2 ELSE b*10 END
113113
----
114114
1000
115115
1180
116-
1240
116+
1240
117+

sqllogic/parser.peg

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,17 @@ query
8181
sql:sql
8282
result:result?
8383
{
84-
return {
85-
command: 'execute',
86-
expectSuccess: true,
87-
sql: sql.trim(),
88-
result: result
89-
}
84+
if(result){
85+
result.colType = queryMain.colInfo,
86+
result.sort = queryMain.sortInfo
87+
}
88+
return {
89+
command: 'execute',
90+
expectSuccess: true,
91+
sql: sql.trim(),
92+
result: result,
93+
label:queryMain.label
94+
}
9095
}
9196

9297
result
@@ -112,7 +117,7 @@ resultHash
112117

113118

114119
resultList
115-
= list:(v:$[^\n]+ (nl/!.){if(v.match(/NULL/i)){v = null};return v})+
120+
= list:(v:$[^\n]+ (nl/!.){if(v.match(/NULL/i)){v = 'NULL'};return v})+
116121
{
117122
return {
118123
type:'list',
@@ -148,7 +153,7 @@ queryInitCommand
148153

149154

150155
queryMain
151-
= "query"i _ colInfo (_ sortInfo)? (_ label)? _*
156+
= "query"i _ colInfo:colInfo _? sortInfo:sortInfo? _? label:label? _* { return {colInfo:colInfo, sortInfo:sortInfo, label:label}}
152157

153158

154159
skipif
@@ -159,9 +164,9 @@ colInfo
159164
= [a-z]i+
160165

161166
sortInfo
162-
= "nosort"i
163-
/ "rowsort"i
164-
/ "valuesort"i
167+
= "nosort"i {return 'nosort'}
168+
/ "rowsort"i {return 'rowsort'}
169+
/ "valuesort"i {return 'valuesort'}
165170

166171

167172
label

sqllogic/run_md.js

Lines changed: 77 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var testfiles = walkFiles(
3232
'test', // Folder where to find test files
3333

3434

35-
/\.test$/, // Regexp for files to include (all files ending with .test )
35+
/select1\.test$/, // Regexp for files to include (all files ending with .test )
3636

3737

3838
// Regexp for files to exclude - keep one and outcomment the rest
@@ -192,7 +192,7 @@ console.log('_Please note that repetetive errors is not always included in this
192192

193193

194194
function printStats(){
195-
console.log('');
195+
console.log('');
196196
console.log('-----------------------------');
197197

198198
console.log('');
@@ -254,13 +254,20 @@ function runSQLtestFromFile(path, db, mimic){
254254
return;
255255

256256
} else if('setThreshold' === fragment.command){
257-
console.log('`setThreshold not implemented`');
257+
// Not important when we compare the results to whats in the testfiles
258+
//console.log('`setThreshold not implemented`');
258259
continue;
259260

260261
}else if('execute' !== fragment.command){
261262
console.log('Unknown command: ',fragments[i].command);
262263
continue;
263-
}
264+
} if('execute' !== fragment.command){
265+
console.log('Unknown command: ',fragments[i].command);
266+
continue;
267+
} if ('valuesort' === fragment.result.sort){
268+
console.log('valuesort not supported.');
269+
continue;
270+
}
264271

265272
var test = verifyTest(fragment, db)
266273

@@ -296,18 +303,15 @@ function verifyTest(fragment, db){
296303
//console.log('-----------------------------------------------')
297304
var req = runTest(fragment.sql, db)
298305
req.ok = (fragment.expectSuccess === req.success)
299-
300-
301-
302-
//if(false) // Converting returned values to expected result is still creating too many false positives
306+
//console.log(fragment)
303307
if(fragment.result && req.success && req.ok){
304308
var ok;
305309

306-
console.log(req.result)
307-
req.result = cleanResults(req.result)
310+
//console.log(req.result)
311+
req.result = cleanResults(req.result, fragment.result.sort)
308312

309-
console.log(fragment.result)
310-
console.log(req.result)
313+
//console.log(fragment.result)
314+
//console.log(req.result)
311315

312316

313317
if(! (req.result && req.result.length)){
@@ -354,7 +358,7 @@ function verifyTest(fragment, db){
354358

355359
}
356360

357-
function cleanResults(result){
361+
function cleanResults(result, sortType){
358362
if(!result){
359363
return result;
360364
}
@@ -367,32 +371,67 @@ function cleanResults(result){
367371
return result;
368372
}
369373
// I expect matrix respond
374+
console.log(result)
375+
376+
for(var i = 0;i<result.length;i++){
377+
result[i] = result[i].map(function(x){
378+
if(true === x){
379+
return "1";
380+
}
381+
382+
if(false === x){
383+
return "0";
384+
}
385+
386+
if(null === ''+x){
387+
return 'NULL';
388+
}
389+
390+
if('Infinity' === ''+x){
391+
return 'NULL';
392+
}
393+
394+
if('NaN' === ''+x){
395+
return 'NULL';
396+
}
397+
398+
if('undefined' === ''+x){
399+
return 'NULL';
400+
}
401+
402+
if('' === x){
403+
return "(empty)";
404+
}
405+
406+
// Its a float
407+
if(x === +x && x !== (x|0)){
408+
return ''+x.toFixed(3);
409+
}
410+
411+
// remove printable chars
412+
return (''+x).replace(/[\n\r\t\x00\x08\x0B\x0C\x0E-\x1F\x7F]/gim, '@');
413+
});
414+
}
415+
console.log(result)
416+
417+
if('rowsort' === sortType){
418+
//The "rowsort" mode gathers all output from the database engine then sorts it by rows on the client side. Sort comparisons use strcmp() on the rendered ASCII text representation of the values. Hence, "9" sorts after "10", not before.
419+
result.sort(function(a,b){
420+
var str1 = a.join('');
421+
var str2 = b.join('');
422+
return ( ( str1 === str2 ) ? 0 : ( ( str1 > str2 ) ? 1 : -1 ) )
423+
})
424+
425+
426+
} else if('valuesort' === sortType){
427+
//The "valuesort" mode works like rowsort except that it does not honor row groupings. Each individual result value is sorted on its own.
428+
// MRW: i dont get this...
429+
return null;
430+
}
431+
432+
result = [].concat.apply([], result);
370433

371-
result = [].concat.apply([], result);
372-
373-
return result.map(function(x){
374-
if(true === x){
375-
return "1";
376-
}else if(false === x){
377-
return "0";
378-
}else if('Infinity' === ''+x){
379-
return null;
380-
}else if('NaN' === ''+x){
381-
return null;
382-
}else if('undefined' === ''+x){
383-
return null;
384-
}else if('' === x){
385-
return "(empty)";
386-
}
387-
388-
// Its a float
389-
if(x === +x && x !== (x|0)){
390-
return ''+x.toFixed(3);
391-
}
392-
393-
// remove printable chars
394-
return (''+x).replace(/[\n\r\t\x00\x08\x0B\x0C\x0E-\x1F\x7F]/gim, '@');
395-
});
434+
return result;
396435

397436
}
398437

sqllogic/sqllogictestparserV2.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ module.exports = function(path) {
7272
commands.push(parser.parse(textCommands[i]+"\n"));
7373
}catch(e){
7474
// output if could not be passed
75-
console.log('************ Error parseing test number', i, 'in file', path)
76-
console.log('previus test (passed):',textCommands[i-1]);
77-
console.log('this test (failed):', textCommands[i]);
75+
console.log('************ Error parseing test number', (i+1), 'in file', path)
76+
console.log('previus one (passed):',textCommands[i-1]);
77+
console.log('this one (failed):', textCommands[i]);
7878
if(i+1 < textCommands.length)
79-
console.log('Next test to be passed:'.textCommands[Math.max(i+1)]);
79+
console.log('Next test to be passed:', textCommands[i+1]);
8080
console.log('')
81-
console.log(JSON.stringify({error:e}))
81+
console.log(JSON.stringify({error:e.message}))
8282
console.log('----------------')
8383
console.log('')
8484
}

0 commit comments

Comments
 (0)