def test_simulate(): with pytest.raises(parse.BQLParseError): # Need limit. parse_bql_string('create table s as simulate x from t') with pytest.raises(parse.BQLParseError): # Need limit. parse_bql_string('create table s as simulate x from t given y = 0') assert parse_bql_string('create table s as' ' simulate x from t limit 10') == \ [ast.CreateTabSim(False, False, 's', ast.Simulate(['x'], 't', ast.ExpLit(ast.LitNull(None)), [], ast.ExpLit(ast.LitInt(10))))] assert parse_bql_string('create table if not exists s as' ' simulate x, y from t given z = 0 limit 10') == \ [ast.CreateTabSim(False, True, 's', ast.Simulate(['x', 'y'], 't', ast.ExpLit(ast.LitNull(None)), [('z', ast.ExpLit(ast.LitInt(0)))], ast.ExpLit(ast.LitInt(10))))] assert parse_bql_string('create temp table s as' ' simulate x, y from t given z = 0 limit 10') == \ [ast.CreateTabSim(True, False, 's', ast.Simulate(['x', 'y'], 't', ast.ExpLit(ast.LitNull(None)), [('z', ast.ExpLit(ast.LitInt(0)))], ast.ExpLit(ast.LitInt(10))))] assert parse_bql_string('create temp table if not exists s as' ' simulate x, y from t given z = 0, w = 1 limit 10') == \ [ast.CreateTabSim(True, True, 's', ast.Simulate(['x', 'y'], 't', ast.ExpLit(ast.LitNull(None)), [ ('z', ast.ExpLit(ast.LitInt(0))), ('w', ast.ExpLit(ast.LitInt(1))), ], ast.ExpLit(ast.LitInt(10))))]
def p_command_createtab_as(self, temp, ifnotexists, name, query): if isinstance(query, ast.Simulate): return ast.CreateTabSim(temp, ifnotexists, name, query) else: return ast.CreateTabAs(temp, ifnotexists, name, query)