RBQL supports all main SQL keywords: SELECT, UPDATE, WHERE, ORDER BY, JOIN, DISTINCT, GROUP BY, TOP, LIMIT, ...
... And some cool features that traditional SQL engines do not provide!
RBQL implementation is based on a clever hack, see the explanation below if you are curious.
RBQL parses SQL-like user query, creates a new python or JavaScript worker module, then imports and executes it.
Explanation of simplified Python version of RBQL algorithm by example.
User enters the following query, which is stored as a string Q:
SELECT a3, int(a4) + 100, len(a2) WHERE a1 != 'SELL'
RBQL replaces all a{i} substrings in the query string Q with a[{i - 1}] substrings. The result is the following string:
Q = "SELECT a[2], int(a[3]) + 100, len(a[1]) WHERE a[0] != 'SELL'"
RBQL searches for "SELECT" and "WHERE" keywords in the query string Q, throws the keywords away, and puts everything after these keywords into two variables S - select part and W - where part, so we will get:
S = "a[2], int(a[3]) + 100, len(a[1])"
W = "a[0] != 'SELL'"
RBQL has a static template script which looks like this:
for line in sys.stdin:
a = line.rstrip('\n').split('\t')
if %%%W_Expression%%%:
out_fields = [%%%S_Expression%%%]
print '\t'.join([str(v) for v in out_fields])
RBQL replaces %%%W_Expression%%% with W and %%%S_Expression%%% with S so we get the following script:
for line in sys.stdin:
a = line.rstrip('\n').split('\t')
if a[0] != 'SELL':
out_fields = [a[2], int(a[3]) + 100, len(a[1])]
print '\t'.join([str(v) for v in out_fields])
RBQL runs the patched script against user's data file:
./tmp_script.py < data.tsv > result.tsv
Result set of the original query (SELECT a3, int(a4) + 100, len(a2) WHERE a1 != 'SELL') is in the "result.tsv" file. It is clear that this simplified version can only work with tab-separated files.