def do_query(self, line):
        """
        query [:tablename] [-r] [--count|-c] [--array|-a] [-{max}] [{rkey-condition}] hkey [attributes,...]

        where rkey-condition:
            --eq={key} (equal key)
            --ne={key} (not equal key)
            --le={key} (less or equal than key)
            --lt={key} (less than key)
            --ge={key} (greater or equal than key)
            --gt={key} (greater than key)
            --exists   (key exists)
            --nexists  (key does not exists)
            --contains={key} (contains key)
            --ncontains={key} (does not contains key)
            --begin={startkey} (rkey begins with startkey)
            --between={firstkey},{lastkey} (between firstkey and lastkey)
        """

        table, line = self.get_table_params(line)
        args = self.getargs(line)

        condition = None
        count = False
        as_array = False
        max_size = None
        batch_size = None
        start = None

        if '-r' in args:
            asc = False
            args.remove('-r')
        else:
            asc = True

        while args:
            arg = args[0]

            if arg[0] == '-' and arg[1:].isdigit():
                max_size = int(arg[1:])
                args.pop(0)

            elif args[0].startswith('--max='):
                arg = args.pop(0)
                max_size = int(arg[6:])

            elif arg in ['--count', '-c']:
                count = True
                args.pop(0)

            elif arg in ['--array', '-a']:
                as_array = True
                args.pop(0)

            elif args[0].startswith('--batch='):
                arg = args.pop(0)
                batch_size = int(arg[8:])

            elif args[0].startswith('--start='):
                arg = args.pop(0)
                start = (arg[8:], )

            elif args[0] == '--next':
                arg = args.pop(0)
                if self.next_key:
                    start = self.next_key
                else:
                    print "no next"
                    return

            elif arg.startswith("--begin="):
                condition = BEGINS_WITH(self.get_typed_key_value(table, arg[8:], False))
                args.pop(0)
            elif arg.startswith("--eq="):
                condition = EQ(self.get_typed_key_value(table, arg[5:], False))
                args.pop(0)
            elif arg.startswith("--ne="):
                condition = NE(self.get_typed_key_value(table, arg[5:], False))
                args.pop(0)
            elif arg.startswith("--le="):
                condition = LE(self.get_typed_key_value(table, arg[5:], False))
                args.pop(0)
            elif arg.startswith("--lt="):
                condition = LT(self.get_typed_key_value(table, arg[5:], False))
                args.pop(0)
            elif arg.startswith("--ge="):
                condition = GE(self.get_typed_key_value(table, arg[5:], False))
                args.pop(0)
            elif arg.startswith("--gt="):
                condition = GT(self.get_typed_key_value(table, arg[5:], False))
                args.pop(0)
            elif arg == "--exists":
                condition = NOT_NULL()
                args.pop(0)
            elif arg == "--nexists":
                condition = NULL()
                args.pop(0)
            elif arg.startswith("--contains="):
                condition = CONTAINS(self.get_typed_key_value(table, arg[11:], False))
                args.pop(0)
            elif arg.startswith("--between="):
                parts = arg[10:].split(",", 1)
                condition = BETWEEN(self.get_typed_key_value(table, parts[0], True), self.get_typed_key_value(table, parts[1], False))
                args.pop(0)

            else:
                break

        hkey = self.get_typed_key_value(table, args.pop(0))
        attr_keys = args[0].split(",") if args else None
        attrs = list(set(attr_keys)) if attr_keys else None

        result = table.query(hkey, range_key_condition=condition, attributes_to_get=attrs, scan_index_forward=asc, request_limit=batch_size, max_results=max_size, count=count, exclusive_start_key=start)

        if count:
            print "count: %s/%s" % (result.scanned_count, result.count)
            self.next_key = None
        else:
            if as_array and attr_keys:
                self.print_iterator_array(result, attr_keys)
            else:
                self.print_iterator(result)

            self.next_key = result.last_evaluated_key

        if self.consumed:
            print "consumed units:", result.consumed_units
query [:tablename] [-r] [--count|-c] [--array|-a] [-{max}] [{rkey-condition}] hkey [attributes,...]

        where rkey-condition:
            --eq={key} (equal key)
            --ne={key} (not equal key)
            --le={key} (less or equal than key)
            --lt={key} (less than key)
            --ge={key} (greater or equal than key)
            --gt={key} (greater than key)
            --exists   (key exists)
            --nexists  (key does not exists)
            --contains={key} (contains key)
            --ncontains={key} (does not contains key)
            --begin={startkey} (rkey begins with startkey)
            --between={firstkey},{lastkey} (between firstkey and lastkey)