def _expand_simmodel_exp(exp, simcols): if isinstance(exp, ast.ExpCol) or ast.is_bql(exp): tmpname = 'v%d' % (len(simcols), ) simcols.append(ast.SelColExp(exp, tmpname)) return ast.ExpCol(None, tmpname) elif isinstance(exp, ast.ExpLit) or \ isinstance(exp, ast.ExpNumpar) or \ isinstance(exp, ast.ExpNampar): return exp elif isinstance(exp, ast.ExpSub) or \ isinstance(exp, ast.ExpExists): # XXX Not really right -- need to provide correct scoping. return exp # XXX subquery scoping elif isinstance(exp, ast.ExpCollate): subexp = _expand_simmodel_exp(exp.expression, simcols) return ast.ExpCollate(subexp, exp.collation) elif isinstance(exp, ast.ExpInQuery): subexp = _expand_simmodel_exp(exp.expression, simcols) subquery = exp.subquery # XXX subquery scoping return ast.ExpIn(subexp, exp.positive, subquery) elif isinstance(exp, ast.ExpInExp): subexp = _expand_simmodel_exp(exp.expression, simcols) subexps = [_expand_simmodel_exp(se, simcols) for se in exp.expressions] return ast.ExpIn(subexp, exp.positive, subexps) elif isinstance(exp, ast.ExpCast): subexp = _expand_simmodel_exp(exp.expression, simcols) return ast.ExpCast(subexp, exp.type) elif isinstance(exp, ast.ExpApp): operands = [ _expand_simmodel_exp(operand, simcols) for operand in exp.operands ] return ast.ExpApp(exp.distinct, exp.operator, operands) elif isinstance(exp, ast.ExpAppStar): return exp elif isinstance(exp, ast.ExpCase): raise NotImplementedError("I'm too lazy to do CASE right now.") elif isinstance(exp, ast.ExpOp): operands = [ _expand_simmodel_exp(operand, simcols) for operand in exp.operands ] return ast.ExpOp(exp.operator, operands) else: assert False, 'Invalid expression: %s' % (repr(exp), )
def p_primary_cast(self, e, t): return ast.ExpCast(e, t)
def p_primary_cast(self, e, t): return ast.ExpCast(e, t) def p_primary_exists(self, q): return ast.ExpExists(q)