Converts the query to a ServiceNow-interpretable format
        :return:
            - ServiceNow query
762400
def _get_formatted_query(self, fields, limit, order_by, offset):
        

        if not isinstance(order_by, list):
            raise InvalidUsage("Argument order_by should be a `list` of fields")

        if not isinstance(fields, list):
            raise InvalidUsage("Argument fields should be a `list` of fields")

        if isinstance(self.query, QueryBuilder):
            sysparm_query = str(self.query)
        elif isinstance(self.query, dict):  # Dict-type query
            sysparm_query = '^'.join(['%s=%s' % (k, v) for k, v in six.iteritems(self.query)])
        elif isinstance(self.query, six.string_types):  # String-type query
            sysparm_query = self.query
        else:
            raise InvalidUsage("Query must be instance of %s, %s or %s" % (QueryBuilder, str, dict))

        for field in order_by:
            if field[0] == '-':
                sysparm_query += "^ORDERBYDESC%s" % field[1:]
            else:
                sysparm_query += "^ORDERBY%s" % field

        params = {'sysparm_query': sysparm_query}
        params.update(self.request_params)

        if limit is not None:
            params.update({'sysparm_limit': limit, 'sysparm_suppress_pagination_header': True})

        if offset is not None:
            params.update({'sysparm_offset': offset})

        if len(fields) > 0:
            params.update({'sysparm_fields': ",".join(fields)})

        return params
1242443
def query(self):
        
        if not self.b64_query:
            return None
        s = QSerializer(base64=True)
        return s.loads(self.b64_query)
75342
public static String queryToExpressionStr(ServiceInstanceQuery query){
        List<QueryCriterion> criteria = query.getCriteria();
        StringBuilder sb = new StringBuilder();
        for(QueryCriterion criterion : criteria){
            String statement = criterionToExpressionStr(criterion);
            if(statement != null && ! statement.isEmpty()){
                sb.append(statement).append(";");
            }
        }
        return sb.toString();
    }
290137
def get_query_uri(self):
        
        # Query URI has extra path we don't want so strip it off here
        query_uri = self.service.settings.data['query']['uri']
        query_uri = urlparse(query_uri)
        return query_uri.scheme + '://' + query_uri.netloc
454786
def raw_query(self, query, query_parameters=None):
        
        self.assert_no_raw_query()

        if len(self._where_tokens) != 0 or len(self._select_tokens) != 0 or len(
                self._order_by_tokens) != 0 or len(self._group_by_tokens) != 0:
            raise InvalidOperationException(
                "You can only use raw_query on a new query, without applying any operations "
                "(such as where, select, order_by, group_by, etc)")

        if query_parameters:
            self.query_parameters = query_parameters
        self._query = query
        return self
1017284
def query(self, queryString):
    '''
    
    '''
    self._setHeaders('query')
    return self._sforce.service.query(queryString)
1123453
def parse_query(qs, d = nil)
      params = {}

      (qs || '').split(d ? /[#{d}] */n : DEFAULT_SEP).each do |p|
        k, v = p.split('=', 2).map { |x| unescape(x) }

        if cur = params[k]
          if cur.class == Array
            params[k] << v
          else
            params[k] = [cur, v]
          end
        else
          params[k] = v
        end
      end

      return params
    end
250492
def __doQuery(self, query, format, convert):
		
		self.__getFormat(format)
		self.sparql.setQuery(query)
		if convert:
			results = self.sparql.query().convert()
		else:
			results = self.sparql.query()

		return results
1284695
def raw_query(self, query, format=None, pretty=False):
        '''
        '''
        if format:
            format = format
        else:
            format = self.format

        payload = self._payload_builder(query, format=format)
        response = self.execute_query(payload)
        if pretty:
            response = self.response_builder(response)

        return response
478823
def as_cql_query(self, formatted=False):
        
        ret = "CREATE TYPE %s.%s (%s" % (
            protect_name(self.keyspace),
            protect_name(self.name),
            "\n" if formatted else "")

        if formatted:
            field_join = ",\n"
            padding = "    "
        else:
            field_join = ", "
            padding = ""

        fields = []
        for field_name, field_type in zip(self.field_names, self.field_types):
            fields.append("%s %s" % (protect_name(field_name), field_type))

        ret += field_join.join("%s%s" % (padding, field) for field in fields)
        ret += "\n)" if formatted else ")"
        return ret
489003
def get_query():
    
    q = get("q", "")

    qs = q.lstrip("*.!$%&/()=#-+:'`´^")
    if qs and not qs.endswith("*"):
        qs += "*"
    return qs
498505
def build(self):
        
        if self.es_version == '1':
            if len(self.filters) > 0:
                return {
                    'filtered': {
                        'query': self.query,
                        'filter': {
                            'and': self.filters
                        }
                    }
                }
            else:
                return self.query
        else:
            query = {
                'bool': {
                    'must': self.query
                }
            }
            if len(self.filters) > 0:
                query["bool"]["filter"] = self.filters
            return query
1055314
def canned_query(n,s):
    
    qobj = qmap[n]
    chain = qobj['chain']
    prefix = qobj['prefix']
    whr = chain2where(chain + [prefix], 'x')
    query = """
    SELECT * WHERE {{
    <{s}> {w}
    }}
    """.format(s=s, w=whr)
    bindings = run_sparql(query)
    rows = [ensure_prefixed(r['x']['value'], prefix) for r in bindings]
    return rows
857244
def refine(query, description):
    

    for attribute, arguments in description.items():
        if hasattr(query, attribute):
            attribute = getattr(query, attribute)
        else:
            raise ValueError("Unknown query method: " + attribute)

        # query descriptions are often automatically generated, and
        # may include empty calls, which we skip
        if utils.isempty(arguments):
            continue

        if callable(attribute):
            method = attribute
            if isinstance(arguments, dict):
                query = method(**arguments)
            elif isinstance(arguments, list):
                query = method(*arguments)
            else:
                query = method(arguments)
        else:
            setattr(attribute, arguments)

    return query
239038
def parse_query(self, query):
        
        logger.debug(u'query to parse2: {}'.format(query))

        # this should find all records
        if query == {} or query is None:
            return Query()._id != u'-1'  # noqa

        q = None
        # find the final result of the generator
        for c in self.parse_condition(query):
            if q is None:
                q = c
            else:
                q = q & c

        logger.debug(u'new query item2: {}'.format(q))

        return q
1305389
def _parse_asn_query(self, query_str):
        
        # find query parts
        query_str_parts = self._get_query_parts(query_str)

        # go through parts and add to query_parts list
        query_parts = list()
        for query_str_part in query_str_parts:

            is_int = True
            try:
                int(query_str_part['string'])
            except ValueError:
                is_int = False

            if is_int:
                self._logger.debug("Query part '" + query_str_part['string'] + "' interpreted as integer (ASN)")
                query_parts.append({
                    'interpretation': {
                        'string': query_str_part['string'],
                        'interpretation': 'asn',
                        'attribute': 'asn',
                        'operator': 'equals',
                    },
                    'operator': 'equals',
                    'val1': 'asn',
                    'val2': query_str_part['string']
                })

            else:
                self._logger.debug("Query part '" + query_str_part['string'] + "' interpreted as text")
                query_parts.append({
                    'interpretation': {
                        'string': query_str_part['string'],
                        'interpretation': 'text',
                        'attribute': 'name',
                        'operator': 'regex',
                    },
                    'operator': 'regex_match',
                    'val1': 'name',
                    'val2': query_str_part['string']
                })

        # Sum all query parts to one query
        query = {}
        if len(query_parts) > 0:
            query = query_parts[0]

        if len(query_parts) > 1:
            for query_part in query_parts[1:]:
                query = {
                    'interpretation': {
                        'interpretation': 'and',
                        'operator': 'and',
                    },
                    'operator': 'and',
                    'val1': query_part,
                    'val2': query
                }

        return True, query
258636
def query(self, query, interpolations=None):
        
        return self._client.ts_query(self, query, interpolations)