def test_simulate_models_nontrivial(): # XXX test descent into ExpLit # XXX test descent into ExpNumpar # XXX test descent into ExpNampar # XXX test descent into ExpCol # XXX test descent into ExpSub # XXX test descent into ExpCollate # XXX test descent into ExpIn # XXX test descent into ExpCast # XXX test descent into ExpExists # XXX test descent into ExpApp # XXX test descent into ExpAppStar # XXX test descent into ExpCase mutinf0 = ast.ExpBQLMutInf(['c0'], ['c1', 'c2'], [('c3', ast.ExpLit(ast.LitInt(3)))], None) mutinf1 = ast.ExpBQLMutInf(['c4', 'c5'], ['c6'], [('c7', ast.ExpLit(ast.LitString('ergodic')))], 100) probdensity = ast.ExpBQLProbDensity( [('x', ast.ExpLit(ast.LitFloat(1.2)))], # No conditions for now -- that changes the weighting of the average. []) expression0 = ast.ExpOp(ast.OP_LT, [ mutinf0, ast.ExpOp(ast.OP_MUL, [ast.ExpLit(ast.LitFloat(0.1)), mutinf1]), ]) expression1 = probdensity simmodels = ast.SimulateModelsExp([ ast.SelColExp(expression0, 'quagga'), ast.SelColExp(expression1, 'eland'), ], 'p', 'g') assert macro.expand_simulate_models(simmodels) == \ ast.Select(ast.SELQUANT_ALL, [ ast.SelColExp( ast.ExpOp(ast.OP_LT, [ ast.ExpCol(None, 'v0'), ast.ExpOp(ast.OP_MUL, [ ast.ExpLit(ast.LitFloat(0.1)), ast.ExpCol(None, 'v1'), ]) ]), 'quagga'), ast.SelColExp(ast.ExpCol(None, 'v2'), 'eland'), ], [ast.SelTab( ast.SimulateModels( [ ast.SelColExp(mutinf0, 'v0'), ast.SelColExp(mutinf1, 'v1'), ast.SelColExp(probdensity, 'v2'), ], 'p', 'g'), None)], None, None, None, None)
def test_select_trivial(): assert parse_bql_string('select null;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpLit(ast.LitNull(None)), None)], None, None, None, None, None)] assert parse_bql_string("select 'x';") == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpLit(ast.LitString('x')), None)], None, None, None, None, None)] assert parse_bql_string("select 'x''y';") == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpLit(ast.LitString("x'y")), None)], None, None, None, None, None)] assert parse_bql_string('select "x";') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpCol(None, 'x'), None)], None, None, None, None, None)] assert parse_bql_string('select "x""y";') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpCol(None, 'x"y'), None)], None, None, None, None, None)] assert parse_bql_string('select 0;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpLit(ast.LitInt(0)), None)], None, None, None, None, None)] assert parse_bql_string('select 0.;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpLit(ast.LitFloat(0)), None)], None, None, None, None, None)] assert parse_bql_string('select .0;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpLit(ast.LitFloat(0)), None)], None, None, None, None, None)] assert parse_bql_string('select 0.0;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpLit(ast.LitFloat(0)), None)], None, None, None, None, None)] assert parse_bql_string('select 1e0;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpLit(ast.LitFloat(1)), None)], None, None, None, None, None)] assert parse_bql_string('select 1e+1;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpLit(ast.LitFloat(10)), None)], None, None, None, None, None)] assert parse_bql_string('select 1e-1;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpLit(ast.LitFloat(.1)), None)], None, None, None, None, None)] assert parse_bql_string('select 1.e0;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpLit(ast.LitFloat(1)), None)], None, None, None, None, None)] assert parse_bql_string('select .1e0;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpLit(ast.LitFloat(.1)), None)], None, None, None, None, None)] assert parse_bql_string('select .1e1;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpLit(ast.LitFloat(1)), None)], None, None, None, None, None)] assert parse_bql_string('select 1.e10;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpLit(ast.LitFloat(1e10)), None)], None, None, None, None, None)] assert parse_bql_string('select all 0;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpLit(ast.LitInt(0)), None)], None, None, None, None, None)] assert parse_bql_string('select distinct 0;') == \ [ast.Select(ast.SELQUANT_DISTINCT, [ast.SelColExp(ast.ExpLit(ast.LitInt(0)), None)], None, None, None, None, None)] assert parse_bql_string('select 0 as z;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpLit(ast.LitInt(0)), 'z')], None, None, None, None, None)] assert parse_bql_string('select * from t;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColAll(None)], [ast.SelTab('t', None)], None, None, None, None)] assert parse_bql_string('select t1.* from t1;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColAll('t1')], [ast.SelTab('t1', None)], None, None, None, None)] assert parse_bql_string('select c from t;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpCol(None, 'c'), None)], [ast.SelTab('t', None)], None, None, None, None)] assert parse_bql_string('select c as d from t;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpCol(None, 'c'), 'd')], [ast.SelTab('t', None)], None, None, None, None)] assert parse_bql_string('select t.c as d from t;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpCol('t', 'c'), 'd')], [ast.SelTab('t', None)], None, None, None, None)] assert parse_bql_string('select t.c as d, p as q, x from t;') == \ [ast.Select(ast.SELQUANT_ALL, [ ast.SelColExp(ast.ExpCol('t', 'c'), 'd'), ast.SelColExp(ast.ExpCol(None, 'p'), 'q'), ast.SelColExp(ast.ExpCol(None, 'x'), None), ], [ast.SelTab('t', None)], None, None, None, None)] assert parse_bql_string('select * from t, u;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColAll(None)], [ast.SelTab('t', None), ast.SelTab('u', None)], None, None, None, None)] assert parse_bql_string('select * from t as u;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColAll(None)], [ast.SelTab('t', 'u')], None, None, None, None)] assert parse_bql_string('select * where x;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColAll(None)], None, ast.ExpCol(None, 'x'), None, None, None)] assert parse_bql_string('select * from t where x;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColAll(None)], [ast.SelTab('t', None)], ast.ExpCol(None, 'x'), None, None, None)] assert parse_bql_string('select * group by x;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColAll(None)], None, None, ast.Grouping([ast.ExpCol(None, 'x')], None), None, None)] assert parse_bql_string('select * from t where x group by y;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColAll(None)], [ast.SelTab('t', None)], ast.ExpCol(None, 'x'), ast.Grouping([ast.ExpCol(None, 'y')], None), None, None)] assert parse_bql_string('select * from t where x group by y, z;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColAll(None)], [ast.SelTab('t', None)], ast.ExpCol(None, 'x'), ast.Grouping([ast.ExpCol(None, 'y'), ast.ExpCol(None, 'z')], None), None, None)] assert parse_bql_string('select * order by x;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColAll(None)], None, None, None, [ast.Ord(ast.ExpCol(None, 'x'), ast.ORD_ASC)], None)] assert parse_bql_string('select * order by x asc;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColAll(None)], None, None, None, [ast.Ord(ast.ExpCol(None, 'x'), ast.ORD_ASC)], None)] assert parse_bql_string('select * order by x desc;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColAll(None)], None, None, None, [ast.Ord(ast.ExpCol(None, 'x'), ast.ORD_DESC)], None)] assert parse_bql_string('select * order by x, y;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColAll(None)], None, None, None, [ast.Ord(ast.ExpCol(None, 'x'), ast.ORD_ASC), ast.Ord(ast.ExpCol(None, 'y'), ast.ORD_ASC)], None)] assert parse_bql_string('select * order by x desc, y;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColAll(None)], None, None, None, [ast.Ord(ast.ExpCol(None, 'x'), ast.ORD_DESC), ast.Ord(ast.ExpCol(None, 'y'), ast.ORD_ASC)], None)] assert parse_bql_string('select * order by x, y asc;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColAll(None)], None, None, None, [ast.Ord(ast.ExpCol(None, 'x'), ast.ORD_ASC), ast.Ord(ast.ExpCol(None, 'y'), ast.ORD_ASC)], None)] assert parse_bql_string('select * limit 32;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColAll(None)], None, None, None, None, ast.Lim(ast.ExpLit(ast.LitInt(32)), None))] assert parse_bql_string('select * limit 32 offset 16;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColAll(None)], None, None, None, None, ast.Lim(ast.ExpLit(ast.LitInt(32)), ast.ExpLit(ast.LitInt(16))))] assert parse_bql_string('select * limit 16, 32;') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColAll(None)], None, None, None, None, ast.Lim(ast.ExpLit(ast.LitInt(32)), ast.ExpLit(ast.LitInt(16))))] assert parse_bql_string('select (select0);') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpCol(None, 'select0'), None)], None, None, None, None, None)] assert parse_bql_string('select (select 0);') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp( ast.ExpSub(ast.Select(ast.SELQUANT_ALL, [ast.SelColExp(ast.ExpLit(ast.LitInt(0)), None)], None, None, None, None, None) ), None, )], None, None, None, None, None)] assert parse_bql_string('select f(f(), f(x), f(*), f(distinct x), y);') == \ [ast.Select(ast.SELQUANT_ALL, [ast.SelColExp( ast.ExpApp(False, 'f', [ ast.ExpApp(False, 'f', []), ast.ExpApp(False, 'f', [ast.ExpCol(None, 'x')]), ast.ExpAppStar('f'), ast.ExpApp(True, 'f', [ast.ExpCol(None, 'x')]), ast.ExpCol(None, 'y'), ]), None, )], None, None, None, None, None)]
def p_literal_string(self, s): return ast.LitString(s)
def p_literal_string(self, s): return ast.LitString(s) def p_type_name(self, n): return ast.Type(n, [])