def add_partition_statements(partitions, bucket, table_name):
    """Generate ALTER TABLE commands from existing partitions. It wil yield Athena
    statement string(s), the length of each string should be less than Athena query
    statement length limit, 262144 bytes.
    https://docs.aws.amazon.com/athena/latest/ug/service-limits.html

    Args:
        partitions (set): The unique set of partitions gathered from Athena
        bucket (str): The bucket name
        table_name (str): The name of the Athena table

    Yields:
        string: The ALTER TABLE statements to add the new partitions
    """
    # Each add partition statement starting with "ALTER TABLE"
    initial_statement = 'ALTER TABLE {} ADD IF NOT EXISTS'.format(table_name)
    initial_statement_len = len(initial_statement)

    # The statement will be stored in a list of string format before join into a string
    statement = [initial_statement]
    statement_len = initial_statement_len

    fmt_values = {
        'bucket': bucket,
        'table_name': table_name
    }

    for partition in sorted(partitions):
        parts = PARTITION_PARTS.match(partition)
        if not parts:
            continue

        fmt_values.update(parts.groupdict())
        partition_stmt = PARTITION_STMT.format(**fmt_values)
        partition_stmt_len = len(partition_stmt)

        # It will add a space between sub strings when join the whole statement
        space_count = len(statement)

        # Monitor the lenght of whole statement and make sure it won't exceed the limit
        if statement_len + partition_stmt_len + space_count >= MAX_QUERY_LENGTH:
            # If the length of whole statement about to exceed the limit, yield
            # the statement and reset it for rest of partitions
            yield ' '.join(statement)
            statement = [initial_statement]
            statement_len = initial_statement_len

        statement_len += partition_stmt_len
        statement.append(partition_stmt)

    yield ' '.join(statement)