Select distinct value or combination of values of
    single or multiple fields.

    :params fields: str or list of str.
    :return data: list of list.

    **中文文档**

    选择多列中出现过的所有可能的排列组合。
165019
def select_distinct_field(col, field_or_fields, filters=None):
    
    fields = _preprocess_field_or_fields(field_or_fields)

    if filters is None:
        filters = dict()

    if len(fields) == 1:
        key = fields[0]
        data = list(col.find(filters).distinct(key))
        return data
    else:
        pipeline = [
            {
                "$match": filters
            },
            {
                "$group": {
                    "_id": {key: "$" + key for key in fields},
                },
            },
        ]
        data = list()
        for doc in col.aggregate(pipeline):
            # doc = {"_id": {"a": 0, "b": 0}} ...
            data.append([doc["_id"][key] for key in fields])
        return data
910704
def values_list(self, *fields, **kwargs):
        
        flat = kwargs.pop('flat', False)
        if kwargs:
            raise TypeError('Unexpected keyword arguments to values_list: %s'
                            % (kwargs.keys(),))
        if flat and len(fields) > 1:
            raise TypeError("'flat' is not valid when values_list is called with more than one field.")
        clone = self.only(fields)
        clone._values_list = True
        clone._flat_values_list = flat
        return clone
1088031
def values(self, *fields):
        
        if not fields:
            fields = self._get_simple_fields()

        fields = self._coerce_fields_parameters(fields)

        self._instances = False
        self._values = {'fields': fields, 'mode': 'dicts'}
        return self
266927
def select(self, fields=['rowid', '*'], offset=None, limit=None):
        ''' 
        '''
        # base SQL
        SQL = 'SELECT %s FROM %s' % (','.join(fields), self._table)
        
        # selectors
        if self._selectors:
            SQL = ' '.join([SQL, 'WHERE', self._selectors]).strip()
        
        # modifiers
        if self._modifiers:
            SQL = ' '.join([SQL, self._modifiers])

        # limit
        if limit is not None and isinstance(limit, int):
            SQL = ' '.join((SQL, 'LIMIT %s' % limit))

        # offset
        if (limit is not None) and (offset is not None) and isinstance(offset, int):
            SQL = ' '.join((SQL, 'OFFSET %s' % offset))

        return ''.join((SQL, ';'))
147413
def mk_field(field):
  
  assert len(field) == 1
  identifier, contents = next(iter(field.items()))
  contents = dict(list({'units': '', 'n_with_values': 0}.items()) + list(contents.items()))
  return sbp.resolve_type(sbp.Field(identifier=identifier,
                                    type_id=contents.pop('type'),
                                    options=contents))
917485
private static String join(List<Field> fields, String sep, String fieldPrefix) {
    	return joinAndGetValueForSelect(fields, sep, fieldPrefix);
    }
272972
function selectFields(obj, fields) {
  const result = {}
  if (obj) {
    fields.forEach(x => obj.hasOwnProperty(x) ? result[x] = obj[x] : null)
  }
  return result
}
58014
def distinct(key)
      result = collection.database.command(
        distinct: collection.name,
        key: key.to_s,
        query: selector
      )
      result["values"]
    end
610344
def rm_values_fields(x):
    
    if isinstance(x, dict):
        if "values" in x:
            del x["values"]
        else:
            for k, v in x.items():
                if isinstance(v, dict):
                    rm_values_fields(v)
                elif isinstance(v, list):
                    rm_values_fields(v)
    elif isinstance(x, list):
        for i in x:
            rm_values_fields(i)

    return x
1074551
def clean_unique_fields(self):
        """"""
        if not self.unique_fields:
            return

        keys = set()
        duplicates = []

        for form in self.forms:
            key = tuple(form.cleaned_data[field] for field in self.unique_fields)
            if key in keys:
                duplicates.append(",".join(key))
            else:
                keys.add(key)

        if duplicates:
            raise forms.ValidationError(
                "Fields %s should be unique; found duplicates for %s" % (
                    ','.join(self.unique_fields), duplicates))
39965
def selected_fields(self):
        
        items = self.lstFields.selectedItems()
        if items and self.mode == MULTI_MODE:
            return [item.text() for item in items]
        elif items and self.mode == SINGLE_MODE:
            return items[0].text()
        else:
            return []
1270745
def pack(field: str, kwargs: Dict[str, Any],
         default: Optional[Any] = None, sep: str=',') -> str:
    
    if default is not None:
        value = kwargs.get(field, default)
    else:
        value = kwargs[field]
    if isinstance(value, str):
        return value
    elif isinstance(value, collections.abc.Iterable):
        return sep.join(str(f) for f in value)
    else:
        return str(value)
830865
def _fields_list_to_dict(fields, option_name):
    
    if isinstance(fields, collections.Mapping):
        return fields

    if isinstance(fields, collections.Sequence):
        if not all(isinstance(field, string_type) for field in fields):
            raise TypeError("%s must be a list of key names, each an "
                            "instance of %s" % (option_name,
                                                string_type.__name__))
        return dict.fromkeys(fields, 1)

    raise TypeError("%s must be a mapping or "
                    "list of key names" % (option_name,))
194026
def distinct_values_of(self, field, count_deleted=False):
        
        solr_params = "facet=true&facet.field=%s&rows=0" % field
        result = self.riak_http_search_query(self.index_name, solr_params, count_deleted)
        facet_fields = result['facet_counts']['facet_fields'][field]
        keys = facet_fields[0::2]
        vals = facet_fields[1::2]

        return dict(zip(keys, vals))
216893
def get_distinct_values_from_cols(self, l_col_list):
        
        uniq_vals = []
        for l_col_name in l_col_list:
            #print('col_name: ' + l_col_name)   
            uniq_vals.append(set(self.get_col_data_by_name(l_col_name)))
            #print(' unique values = ', uniq_vals)    
        
        #print(' unique values[0] = ', uniq_vals[0])
        #print(' unique values[1] = ', uniq_vals[1])
        if len(l_col_list) == 0:
            return []
        elif len(l_col_list) == 1:
            return sorted([v for v in uniq_vals])
        elif len(l_col_list) == 2:
            res = []
            res = [(a, b) for a in uniq_vals[0] for b in uniq_vals[1]]
            return res
        else:
            print ("TODO ")
            return -44
363905
def GetFieldValuesTuple(self, trip_id):
    
    result = []
    for fn in self._FIELD_NAMES:
      if fn == 'trip_id':
        result.append(trip_id)
      else:
        # Since we'll be writting to an output file, we want empty values to be
        # outputted as an empty string
        result.append(getattr(self, fn) or '' )
    return tuple(result)
1010187
def is_field_unique_by_group(df, field_col, group_col):
    ''' 
    '''
    def num_unique(x):
        return len(pd.unique(x))
    num_distinct = df.groupby(group_col)[field_col].agg(num_unique)
    return all(num_distinct == 1)