original_docstring:  Build a scan/query from a statement 
docstring: Build a scan/query from a statement
docstring_tokens: Build a scan / query from a statement
code: def _build_query(self, table, tree, visitor):
          """ Build a scan/query from a statement """
          kwargs = {}
          index = None
          if tree.using:
              index_name = kwargs["index"] = tree.using[1]
              index = table.get_index(index_name)
          if isinstance(tree.where, ConstraintExpression):
              constraints = tree.where
              possible_hash = constraints.possible_hash_fields()
              possible_range = constraints.possible_range_fields()
              if index is None:
                  # See if we can find an index to query on
                  indexes = table.get_matching_indexes(possible_hash, possible_range)
                  if not indexes:
                      action = "scan"
                      kwargs["filter"] = constraints.build(visitor)
                      kwargs["expr_values"] = visitor.expression_values
                      kwargs["alias"] = visitor.attribute_names
                  elif len(indexes) == 1:
                      index = indexes[0]
                      action = "query"
                      add_query_kwargs(kwargs, visitor, constraints, index)
                  else:
                      names = ", ".join([index.name for index in indexes])
                      raise SyntaxError(
                          "No index specified with USING <index>, "
                          "but multiple possibilities for query: "
                          "%s" % names
                      )
              else:
                  if index.hash_key in possible_hash:
                      action = "query"
                      add_query_kwargs(kwargs, visitor, constraints, index)
                  else:
                      action = "scan"
                      if not index.scannable:
                          raise SyntaxError("Cannot scan local index %r" % index_name)
                      kwargs["filter"] = constraints.build(visitor)
                      kwargs["expr_values"] = visitor.expression_values
                      kwargs["alias"] = visitor.attribute_names
          else:
              action = "scan"
          return [action, kwargs, index]
code_tokens: def _build_query ( self , table , tree , visitor ) : kwargs = { } index = None if tree . using : index_name = kwargs [ "index" ] = tree . using [ 1 ] index = table . get_index ( index_name ) if isinstance ( tree . where , ConstraintExpression ) : constraints = tree . where possible_hash = constraints . possible_hash_fields ( ) possible_range = constraints . possible_range_fields ( ) if index is None : indexes = table . get_matching_indexes ( possible_hash , possible_range ) if not indexes : action = "scan" kwargs [ "filter" ] = constraints . build ( visitor ) kwargs [ "expr_values" ] = visitor . expression_values kwargs [ "alias" ] = visitor . attribute_names elif len ( indexes ) == 1 : index = indexes [ 0 ] action = "query" add_query_kwargs ( kwargs , visitor , constraints , index ) else : names = ", " . join ( [ index . name for index in indexes ] ) raise SyntaxError ( "No index specified with USING <index>, " "but multiple possibilities for query: " "%s" % names ) else : if index . hash_key in possible_hash : action = "query" add_query_kwargs ( kwargs , visitor , constraints , index ) else : action = "scan" if not index . scannable : raise SyntaxError ( "Cannot scan local index %r" % index_name ) kwargs [ "filter" ] = constraints . build ( visitor ) kwargs [ "expr_values" ] = visitor . expression_values kwargs [ "alias" ] = visitor . attribute_names else : action = "scan" return [ action , kwargs , index ]
short_docstring: Build a scan/query from a statement
short_docstring_tokens: Build a scan / query from a statement
comment: """ Build a scan/query from a statement """$SEP$# See if we can find an index to query on