turn a filter_parameter key => value into a Sequel::SQL::Expression subclass
 field will be the field name ultimately used in the expression. Defaults to key.
339250
def to_expr( key, value, field = nil )
      Sequel.expr( predicates[key, value, field] )
    end
893915
def order_by( filter, *fields, label: fields.first.to_s.titleize, order_link_class: default_order_link_class )
      return label if filter.nil?

      # current ordering from the filter
      # each expr is a Sequel::SQL::Expression
      exprs = Hash[ filter.order_expressions ]

      # Invert each ordering for the generated link. Current sort order will be displayed.
      order_links = fields.map do |field|
        if exprs[field]
          order_link_class.new exprs[field].invert, active: true
        else
          order_link_class.new Sequel.asc(field)
        end
      end

      # filter params must have order in the right format
      filter_params = filter.filter_parameters.dup
      filter_params[:order] = unify_array( order_links.map( &:name ) )

      params_hash = {filter.class::Model.model_name.param_key.to_sym => filter_params}
      link_text = raw( [label, order_links.first.andand.icon].compact.join(' ') )
      link_to link_text, params_hash, {class: order_links.first.andand.css_class}
    end
357173
public function apply($dbDriver, $alias, $field, $exprValue, $namedParameter = null, &$value = null)
	{
		$matches = [];
		
		if (!preg_match(self::PATTERN, $exprValue, $matches)) {
			throw new BadQueryExprException(sprintf('The query expression converter "range" does not support the following pattern "%s".', $exprValue));
		}
		
		switch (true) {
			case $matches[2] && !$matches[3]:
				return $this->createGreaterExpr($field, $matches[1], trim($matches[2]));
				
			case !$matches[2] && $matches[3]:
				return $this->createLessExpr($field, $matches[4], trim($matches[3]));
				
			case $matches[2] && $matches[3]:
				return (new \Doctrine\MongoDB\Query\Expr())->addAnd(
						$this->createGreaterExpr($field, $matches[1], trim($matches[2])), 
						$this->createLessExpr($field, $matches[4], trim($matches[3]))
					);
				
			default:
				throw new BadQueryExprException('the range query expression converter requires left or right value of range');
		}
	}
781016
def get_filter_qobj(self, keys=None):
    
    # only care about columns in aggregates right?
    cols = set()
    for agg in self.select.aggregates:
        cols.update(agg.cols)
    sels = [SelectExpr(col, [col], col, None) for col in cols]
    select = Select(sels)
    where = list(self.where)
    if keys:
      keys = list(keys)
      keys = map(sqlize, list(keys))
      expr = self.select.nonaggs[0].expr

      clause = []
      if None in keys:
        clause.append("%s is null" % expr)
      if len([k for k in keys if k is not None]) > 0:
        clause.append("%s in %%s" % expr)
      clause = " or ".join(clause)
      where.append(clause)
    else:
      where.append( '%s = %%s' % (self.select.nonaggs[0].expr ) )
    q = Query(self.db, select, self.fr, where)
    return q
690652
def filter_from_url_arg(model_cls, query, arg, query_operator=and_,
                        arg_types=None):
    

    fields = arg.split(',')
    mapper = class_mapper(model_cls)

    if not arg_types:
        arg_types = {}

    exprs = []
    joins = set()
    for expr in fields:
        if expr == "":
            continue

        e_mapper = mapper
        e_model_cls = model_cls

        operator = None
        method = None
        for op in operator_order:
            if op in expr:
                operator = op
                method = operator_to_method[op]
                break

        if operator is None:
            raise Exception('No operator in expression "{0}".'.format(expr))

        (column_names, value) = expr.split(operator)

        column_names = column_names.split('__')
        value = value.strip()

        for column_name in column_names:
            if column_name in arg_types:
                typed_value = arg_types[column_name](value)
            else:
                typed_value = value

            if column_name in e_mapper.relationships:
                joins.add(column_name)
                e_model_cls = e_mapper.attrs[column_name].mapper.class_
                e_mapper = class_mapper(e_model_cls)

        if hasattr(e_model_cls, column_name):
            column = getattr(e_model_cls, column_name)
            exprs.append(getattr(column, method)(typed_value))
        else:
            raise Exception('Invalid property {0} in class {1}.'.format(column_name, e_model_cls))

    return query.join(*joins).filter(query_operator(*exprs))
6799
def complete_key(name, field, val)
      return ["#{name}."] if !val || !val.is_a?(String) || !(val.include?('.'))
      val = val.sub(/.*\./,'')

      connection    = definition.klass.connection
      quoted_table  = field.key_klass.connection.quote_table_name(field.key_klass.table_name)
      quoted_field  = field.key_klass.connection.quote_column_name(field.key_field)
      field_name    = "#{quoted_table}.#{quoted_field}"

      field.key_klass
        .where(value_conditions(field_name, val))
        .select(field_name)
        .limit(20)
        .distinct
        .map(&field.key_field)
        .compact
        .map { |f| "#{name}.#{f} " }
    end
479890
public function apply($dbDriver, $alias, $field, $exprValue, $namedParameter = null, &$value = null)
	{
		$value = [];
		$matches = [];
		$leftExpr = $alias.'.'.$field;
		
		if (!preg_match(self::PATTERN, $exprValue, $matches)) {
			throw new BadQueryExprException(sprintf('The query expression converter "range" does not support the following pattern "%s".', $exprValue));
		}
		
		switch (true) {
			case $matches[2] && !$matches[3]:
				$rightExpr = $namedParameter ?: ':'.$field;
				$value[$rightExpr] = trim($matches[2]);
				
				return $this->createGreaterThanExpr($leftExpr, $matches[1], $rightExpr);
				
			case !$matches[2] && $matches[3]:
				$rightExpr = $namedParameter ?: ':'.$field;
				$value[$rightExpr] = trim($matches[3]);
				
				return $this->createLessThanExpr($leftExpr, $matches[4], $rightExpr);
				
			case $matches[2] && $matches[3]:
				$rightExpr1 = ($namedParameter ?: ':'.$field) . '1';
				$rightExpr2 = ($namedParameter ?: ':'.$field) . '2';
				$value[$rightExpr1] = trim($matches[2]);
				$value[$rightExpr2] = trim($matches[3]);
				
				return (new \Doctrine\ORM\Query\Expr())->andX(
						$this->createGreaterThanExpr($leftExpr, $matches[1], $rightExpr1), 
						$this->createLessThanExpr($leftExpr, $matches[4], $rightExpr2)
					);
				
			default:
				throw new BadQueryExprException('The range query expression converter requires left or right value of range');
		}
	}
702286
function processExpressionObject( val, key ) {
	var operator;
	if ( sys.isObject( val ) ) {
		var opKeys = Object.keys( val );
		var op = opKeys[ 0 ];

		if ( sys.indexOf( nestedOps, op ) > -1 ) {
			operator = processNestedOperator( key, val );
		} else if ( sys.indexOf( prefixOps, key ) > -1 ) {
			operator = processPrefixOperator( key, val );
		} else if ( op === "$regex" ) {
			// special handling for regex options
			operator = processNestedOperator( key, val );
		} else if ( op === "$elemMatch" ) {
			// elemMatch is just a weird duck
			operator = {
				path      : key,
				operation : op,
				operands  : []
			};
			sys.each( val[ op ], function ( entry ) {
				operator.operands = parseQueryExpression( entry );
			} );
		}
		else {
			throw new Error( "Unrecognized operator" );
		}
	} else {
		operator = processNestedOperator( key, { $eq : val } );
	}
	return operator;
}
1162107
function parse_select_fields(ObjType, traits) {
	debug.assert(ObjType).is('function');
	debug.assert(traits).ignore(undefined).is('object');
	return ARRAY(traits.fields).map(function(f) {
		return _parse_predicate_key(ObjType, {'traits': traits, 'epoch':false}, f);
	}).valueOf();
}
1083940
def filter_value(obj, property, value, row)
      flt = filter_for(obj, property.to_sym)
      return value if flt.nil?
      fval = flt.call(obj, value, row)
      unless value == fval then
        logger.debug { "The migration filter transformed the #{obj.qp} #{property} value from #{value.qp} to #{fval}." }
      end
      fval
    end
723121
private SelectorBuilderImpl multipleValuePredicate(String field, String[] propertyValues,
      PredicateOperator operator) {
    if (propertyValues == null) {
      return this;
    }

    Predicate predicate = new Predicate();
    predicate.setOperator(operator);
    predicate.setField(field);

    for (String propertyValue : propertyValues) {
      predicate.getValues().add(propertyValue);
    }

    this.predicates.add(predicate);

    return this;
  }
1207026
def filters_from_key_value_pair(kvp)
      kvp[:qualifier] = kvp[:column].split(':')
      kvp[:column] = kvp[:qualifier].shift
      if (kvp[:condition].to_s != "LIKE")
        "(SingleColumnValueFilter('#{kvp[:column]}','#{kvp[:qualifier].join(':')}',#{kvp[:condition]},'binary:#{kvp[:value]}',true,true))"
      else
        kvp[:value] = Regexp.escape(kvp[:value])
        kvp[:value].sub!(/^%/,"^.*")
        kvp[:value].sub!(/%$/,".*$")
        while kvp[:value].match(/([^\\]{1,1})%/)
          kvp[:value].sub!(/([^\\]{1,1})%/,"#{$1}.*?")
        end
        kvp[:value].sub!(/^_/,"^.")
        kvp[:value].sub!(/_$/,".$")
        while kvp[:value].match(/([^\\]{1,1})_/)
          kvp[:value].sub!(/([^\\]{1,1})_/,"#{$1}.")
        end
        "(SingleColumnValueFilter('#{kvp[:column]}','#{kvp[:qualifier].join(':')}',=,'regexstring:#{kvp[:value]}',true,true))"
      end
    end
188015
def make_filter_string(cls, filter_specification):
        
        registry = get_current_registry()
        visitor_cls = registry.getUtility(IFilterSpecificationVisitor,
                                          name=EXPRESSION_KINDS.CQL)
        visitor = visitor_cls()
        filter_specification.accept(visitor)
        return str(visitor.expression)
1074491
def field_class_type_prefix(attr, options)
      if options[:as]
        options[:as].to_s.capitalize
      elsif options.has_key? :collection
        'Select'
      else
        derive_field_class_prefix attr
      end
    end
1051356
def parse_filtering_param(filtering_param, allowed_params)
      return {} unless filtering_param.present?

      fields = {}

      # Extract the fields for each type from the fields parameters
      if filtering_param.is_a?(Hash)
        filtering_param.each do |field, value|
          resource_fields = value.split(',') unless value.nil? || value.empty?
          fields[field.to_sym] = resource_fields
        end
      else
        raise InvalidFilterException, "Invalid filter format for #{filtering_param}"
      end
      check_filtering_param(fields, allowed_params)
      fields
    end
1036193
public function getFilter($key, $value = null)
    {
        if (!$this->expr instanceof ExpressionBuilder) {
            throw new QueryParseException('Cannot call method without an Expression Builder parameter set', 1);
        }

        /** @var callable $callback */
        foreach ($this->filterHandlers as $callback) {
            $result = $callback($key, $value, $this->expr);
            if ($result instanceof Filter) {
                return $result;
            }
        }

        return null;
    }
362435
def setFilterData(self, key, value):
        
        self._filterData[nativestring(key)] = nativestring(value)