Skip to content

Commit

Permalink
flatten columnName, allow : in field names
Browse files Browse the repository at this point in the history
  • Loading branch information
danvk committed Nov 13, 2014
1 parent ab89c6e commit 3770e94
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
51 changes: 28 additions & 23 deletions __tests__/js/query-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var _ = require('underscore'),


describe('Query Language', function() {
var columns = ['A', 'B', 'INFO.DP'];
var columns = ['A', 'B', 'INFO.DP', 'INFO:AF'];

function expectParse(query, expectedResult) {
var result = QueryLanguage.parse(query, columns);
Expand All @@ -17,9 +17,14 @@ describe('Query Language', function() {
}

it('should parse simple filters', function() {
expectParse('A < 10', {filters:[{type: '<', value:'10', columnName:['A']}]});
expectParse('B = ABC', {filters:[{type: '=', value:'ABC', columnName:['B']}]});
expectParse('INFO.DP like "ABC"', {filters:[{type: 'LIKE', value:'ABC', columnName:['INFO', 'DP']}]});
expectParse('A < 10', {filters:[{type: '<', value:'10', columnName:'A'}]});
expectParse('B = ABC', {filters:[{type: '=', value:'ABC', columnName:'B'}]});
expectParse('INFO.DP like "ABC"', {
filters:[{type: 'LIKE', value:'ABC', columnName:'INFO.DP'}]
});
expectParse('INFO:AF rlike "^.*$"', {
filters:[{type: 'RLIKE', value:'^.*$', columnName:'INFO:AF'}]
});
});

it('should parse ranges', function() {
Expand All @@ -30,51 +35,51 @@ describe('Query Language', function() {
});

it('should parse simple order bys', function() {
expectParse('ORDER BY A', {sortBy:[{order:'asc', columnName: ['A']}]});
expectParse('ORDER BY B DESC', {sortBy:[{order:'desc', columnName: ['B']}]});
expectParse('ORDER BY INFO.DP ASC', {sortBy:[{order:'asc', columnName: ['INFO', 'DP']}]});
expectParse('ORDER BY A', {sortBy:[{order:'asc', columnName: 'A'}]});
expectParse('ORDER BY B DESC', {sortBy:[{order:'desc', columnName: 'B'}]});
expectParse('ORDER BY INFO.DP ASC', {sortBy:[{order:'asc', columnName: 'INFO.DP'}]});
});

it('should parse quoted filters with spaces', function() {
expectParse('A like \'A"" C\'', {filters:[{type: 'LIKE', value:'A"" C', columnName:['A']}]});
expectParse('A like \'A"" C\'', {filters:[{type: 'LIKE', value:'A"" C', columnName:'A'}]});
});

it('should parse compound filters', function() {
expectParse('A < 10 AND B >= ABC', {
filters: [
{type: '<', value:'10', columnName:['A']},
{type: '>=', value:'ABC', columnName:['B']}
{type: '<', value:'10', columnName:'A'},
{type: '>=', value:'ABC', columnName:'B'}
]
});
});

it('should parse compound filters with ranges', function() {
expectParse('20:1234- AND A < 10', {
range: {contig:'20', start: '1234'},
filters: [{type: '<', value: '10', columnName: ['A']}]
filters: [{type: '<', value: '10', columnName: 'A'}]
});
});

it('should parse compound order bys', function() {
expectParse('ORDER BY A, B', {
sortBy:[{order:'asc', columnName: ['A']},
{order:'asc', columnName: ['B']}]
sortBy:[{order:'asc', columnName: 'A'},
{order:'asc', columnName: 'B'}]
});

expectParse('ORDER BY A DESC, B', {
sortBy:[{order:'desc', columnName: ['A']},
{order:'asc', columnName: ['B']}]
sortBy:[{order:'desc', columnName: 'A'},
{order:'asc', columnName: 'B'}]
});

expectParse('ORDER BY A ASC, B ASC', {
sortBy:[{order:'asc', columnName: ['A']},
{order:'asc', columnName: ['B']}]
sortBy:[{order:'asc', columnName: 'A'},
{order:'asc', columnName: 'B'}]
});

expectParse('ORDER BY A ASC, B, INFO.DP DESC', {
sortBy:[{order:'asc', columnName: ['A']},
{order:'asc', columnName: ['B']},
{order:'desc', columnName: ['INFO', 'DP']}]
sortBy:[{order:'asc', columnName: 'A'},
{order:'asc', columnName: 'B'},
{order:'desc', columnName: 'INFO.DP'}]
});
});

Expand All @@ -83,10 +88,10 @@ describe('Query Language', function() {
{
range: {contig: 'X', start: '345', end: '4567'},
filters: [
{type: '<=', value: '10', columnName: ['A']},
{type: '=', value: 'ABC', columnName: ['B']}
{type: '<=', value: '10', columnName: 'A'},
{type: '=', value: 'ABC', columnName: 'B'}
],
sortBy:[{order:'asc', columnName: ['INFO', 'DP']}]
sortBy:[{order:'asc', columnName: 'INFO.DP'}]
});
});

Expand Down
2 changes: 1 addition & 1 deletion cycledash/static/js/QueryLanguage.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function parse(query, columnNames) {
if (!_.contains(columnNames, field)) {
errors.push({error: 'Unknown field ' + field});
} else {
item['columnName'] = field.split('.');
item['columnName'] = field;
delete item['field'];
}
});
Expand Down
2 changes: 1 addition & 1 deletion grammars/querylanguage.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ filter "filter"
= k:field ws op:op ws v:value { return {type: 'filter', field: k, op: op, value: v} }

field "field"
= chars:[0-9a-z.]i+ { return chars.join(''); }
= chars:[0-9a-z.:]i+ { return chars.join(''); }

This comment has been minimized.

Copy link
@ihodes

ihodes Nov 13, 2014

Member

May be good to add underscores as well, maybe dashes?


value "value"
= chars:[0-9a-z.]i+ { return chars.join(''); }
Expand Down

0 comments on commit 3770e94

Please sign in to comment.