def _ConvertStack(postfix):
  if not postfix:
    raise bigquery_client.BigqueryInvalidQueryError(
        'Not enough arguments.', None, None, None)
  top = postfix.pop()
  if isinstance(top, util.OperatorToken):
    args = []
    for unused_i in range(top.num_args):
      args.append(_ConvertStack(postfix))
    args.reverse()
    if top.num_args == 1:
      return '%s %s' % (str(top), args[0])
    else:
      return '(%s %s %s)' % (args[0], str(top), args[1])
  elif isinstance(top, util.BuiltInFunctionToken):
    func_name = str(top)
    if func_name in _ZERO_ARGUMENT_FUNCTIONS:
      return '%s()' % func_name
    elif func_name in _ONE_ARGUMENT_FUNCTIONS:
      op = _ConvertStack(postfix)
      return '%s(%s)' % (func_name, op)
    elif func_name in _TWO_ARGUMENT_FUNCTIONS:
      op2 = _ConvertStack(postfix)
      op1 = _ConvertStack(postfix)
      return '%s(%s, %s)' % (top, op1, op2)
    elif func_name in _THREE_ARGUMENT_FUNCTIONS:
      op3 = _ConvertStack(postfix)
      op2 = _ConvertStack(postfix)
      op1 = _ConvertStack(postfix)
      return '%s(%s, %s, %s)' % (top, op1, op2, op3)
    else:
      raise bigquery_client.BigqueryInvalidQueryError(
          'Function %s does not exist.' % str(top), None, None, None)
  elif isinstance(top, util.AggregationFunctionToken):
    num_args = top.num_args
    func_name = str(top)
    ops = []
    for unused_i in range(int(num_args)):
      ops.append(_ConvertStack(postfix))
    ops.reverse()
    if func_name == 'DISTINCTCOUNT':
      func_name = 'COUNT'
      ops[0] = 'DISTINCT ' + ops[0]
    ops = [str(op) for op in ops]
    return func_name + '(' + ', '.join(ops) + ')'
  elif not isinstance(top, basestring):
    return str(top)
  else:
    return top
Ensure that touching the DB raises and error.
dataset/ETHPy150Open google/encrypted-bigquery-client/src/query_interpreter.py/_ConvertStack--crossover with--dataset/ETHPy150Open dimagi/commcare-hq/testrunner.py/TwoStageTestRunner.setup_mock_database