nodes: 0, module; 1, function_definition; 2, function_name:sorted; 3, parameters; 4, block; 5, identifier:field_name; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, if_statement; 11, expression_statement; 12, expression_statement; 13, return_statement; 14, identifier:ascending; 15, True; 16, identifier:fields; 17, None; 18, identifier:count; 19, integer:5; 20, comment:"""Provides a sampling strategy that picks from an ordered set of rows.
  
      Args:
        field_name: the name of the field to sort the rows by.
        ascending: whether to sort in ascending direction or not.
        fields: an optional list of field names to retrieve.
        count: optional number of rows to limit the sampled results to.
      Returns:
        A sampling function that can be applied to get the initial few rows.
      """; 21, comparison_operator:field_name is None; 22, block; 23, assignment; 24, assignment; 25, lambda; 26, identifier:field_name; 27, None; 28, raise_statement; 29, identifier:direction; 30, conditional_expression:'' if ascending else ' DESC'; 31, identifier:projection; 32, call; 33, lambda_parameters; 34, binary_operator:'SELECT %s FROM (%s) ORDER BY %s%s LIMIT %d' % (projection, sql, field_name,
                                                                         direction, count); 35, call; 36, string; 37, identifier:ascending; 38, string; 39, attribute; 40, argument_list; 41, identifier:sql; 42, string; 43, tuple; 44, identifier:Exception; 45, argument_list; 46, string_content:DESC; 47, identifier:Sampling; 48, identifier:_create_projection; 49, identifier:fields; 50, string_content:SELECT %s FROM (%s) ORDER BY %s%s LIMIT %d; 51, identifier:projection; 52, identifier:sql; 53, identifier:field_name; 54, identifier:direction; 55, identifier:count; 56, string; 57, string_content:Sort field must be specified
code: def sorted(field_name, ascending=True, fields=None, count=5):
      """Provides a sampling strategy that picks from an ordered set of rows.
  
      Args:
        field_name: the name of the field to sort the rows by.
        ascending: whether to sort in ascending direction or not.
        fields: an optional list of field names to retrieve.
        count: optional number of rows to limit the sampled results to.
      Returns:
        A sampling function that can be applied to get the initial few rows.
      """
      if field_name is None:
        raise Exception('Sort field must be specified')
      direction = '' if ascending else ' DESC'
      projection = Sampling._create_projection(fields)
      return lambda sql: 'SELECT %s FROM (%s) ORDER BY %s%s LIMIT %d' % (projection, sql, field_name,
                                                                         direction, count)