code: def extract_top_from_query(
      statement: TokenList, top_keywords: set[str]
  ) -> Optional[int]:
      """
      Extract top clause value from SQL statement.
  
      :param statement: SQL statement
      :param top_keywords: keywords that are considered as synonyms to TOP
      :return: top value extracted from query, None if no top value present in statement
      """
  
      str_statement = str(statement)
      str_statement = str_statement.replace("\n", " ").replace("\r", "")
      token = str_statement.rstrip().split(" ")
      token = [part for part in token if part]
      top = None
      for i, part in enumerate(token):
          if part.upper() in top_keywords and len(token) - 1 > i:
              try:
                  top = int(token[i + 1])
              except ValueError:
                  top = None
              break
      return top
  
imports: import logging
  import re
  from collections.abc import Iterator
  from dataclasses import dataclass
  from typing import Any, cast, Optional
  from urllib import parse
  import sqlparse
  from sqlalchemy import and_
  from sqlparse import keywords
  from sqlparse.lexer import Lexer
  from sqlparse.sql import Identifier, IdentifierList, Parenthesis, remove_quotes, Token, TokenList, Where
  from sqlparse.tokens import Comment, CTE, DDL, DML, Keyword, Name, Punctuation, String, Whitespace, Wildcard
  from sqlparse.utils import imt
  from superset.exceptions import QueryClauseValidationException
  from superset.utils.backports import StrEnum
label_desc: Use image node_id 2 for calling a global function with example usage: extract_top_from_query(statement, top_keywords) and returns: top