docs: def _expanded_sql(self, sampling=None):
      """Get the expanded SQL of this object, including all subqueries, UDFs, and external datasources
  
      Returns:
        The expanded SQL string of this object
      """
  
      # use lists to preserve the order of subqueries, bigquery will not like listing subqueries
      # out of order if they depend on each other. for example. the following will be rejected:
      # WITH q2 as (SELECT * FROM q1),
      #      q1 as (SELECT * FROM mytable),
      # SELECT * FROM q2
      # so when we're getting the dependencies, use recursion into a list to maintain the order
      udfs = []
      subqueries = []
      expanded_sql = ''
  
      def _recurse_subqueries(query):
        """Recursively scan subqueries and add their pieces to global scope udfs and subqueries
        """
        if query._subqueries:
          for subquery in query._subqueries:
            _recurse_subqueries(subquery[1])
          subqueries.extend([s for s in query._subqueries if s not in subqueries])
        if query._udfs:
          # query._udfs is a list of (name, UDF) tuples; we just want the UDF.
          udfs.extend([u[1] for u in query._udfs if u[1] not in udfs])
  
      _recurse_subqueries(self)
  
      if udfs:
        expanded_sql += '\n'.join([udf._expanded_sql() for udf in udfs])
        expanded_sql += '\n'
  
      def _indent_query(subquery):
        return '  ' + subquery._sql.replace('\n', '\n  ')
  
      if subqueries:
        expanded_sql += 'WITH ' + \
                        '\n),\n'.join(['%s AS (\n%s' % (sq[0], _indent_query(sq[1]))
                                       for sq in subqueries])
        expanded_sql += '\n)\n\n'
  
      expanded_sql += sampling(self._sql) if sampling else self._sql
  
      return expanded_sql