class_docstr: Engine spec for Apache Drill
docstr: Return a modified URL with the username set.
  
  :param url: SQLAlchemy URL object
  :param impersonate_user: Flag indicating if impersonation is enabled
  :param username: Effective username
docstr_tok: ["Return","a","modified","URL","with","the","username","set",".",":","param","url",":","SQLAlchemy","URL","object",":","param","impersonate_user",":","Flag","indicating","if","impersonation","is","enabled",":","param","username",":","Effective","username"]
code: def get_url_for_impersonation(
      cls, url: URL, impersonate_user: bool, username: Optional[str]
  ) -> URL:
      """
      Return a modified URL with the username set.
  
      :param url: SQLAlchemy URL object
      :param impersonate_user: Flag indicating if impersonation is enabled
      :param username: Effective username
      """
      if impersonate_user and username is not None:
          if url.drivername == "drill+odbc":
              url = url.update_query_dict({"DelegationUID": username})
          elif url.drivername in ["drill+sadrill", "drill+jdbc"]:
              url = url.update_query_dict(
                  {"impersonation_target": username}
              )
          else:
              raise SupersetDBAPIProgrammingError(
                  f"impersonation is not supported for {url.drivername}"
              )
  
      return url
  
file_path: superset/superset/db_engine_specs/drill.py
imports: from datetime import datetime
  from typing import Any, Optional
  from urllib import parse
  from sqlalchemy import types
  from sqlalchemy.engine.url import URL
  from superset.constants import TimeGrain
  from superset.db_engine_specs.base import BaseEngineSpec
  from superset.db_engine_specs.exceptions import SupersetDBAPIProgrammingError
label_desc: Use image node_id 6 for calling the DrillEngineSpec obj's underlying member method code with example usage: obj.get_url_for_impersonation(cls, url, impersonate_user, username) and returns: url