class_docstr: This handler handles connection and execution of the ClickHouse statements.
class_docstr_tok: ["This","handler","handles","connection","and","execution","of","the","ClickHouse","statements","."]
docstr: Handles the connection to a ClickHouse
docstr_tok: ["Handles","the","connection","to","a","ClickHouse"]
code: def connect(self):
      """
      Handles the connection to a ClickHouse
      """
      if self.is_connected is True:
          return self.connection
  
      protocol = (
          "clickhouse+native"
          if self.protocol == "native"
          else "clickhouse+http"
      )
      host = quote(self.connection_data["host"])
      port = self.connection_data["port"]
      user = quote(self.connection_data["user"])
      password = quote(self.connection_data["password"])
      database = quote(self.connection_data["database"])
      url = f"{protocol}://{user}:{password}@{host}:{port}/{database}"
      if self.protocol == "https":
          url = url + "?protocol=https"
  
      engine = create_engine(url)
      connection = engine.raw_connection()
      self.is_connected = True
      self.connection = connection
      return self.connection
  
imports: from collections import OrderedDict
  from urllib.parse import quote
  import pandas
  from sqlalchemy import create_engine
  from clickhouse_sqlalchemy.drivers.base import ClickHouseDialect
  from mindsdb_sql.parser.ast.base import ASTNode
  from mindsdb_sql.render.sqlalchemy_render import SqlalchemyRender
  from mindsdb.utilities import log
  from mindsdb.integrations.libs.base import DatabaseHandler
  from mindsdb.integrations.libs.response import HandlerStatusResponse, HandlerResponse, RESPONSE_TYPE
  from mindsdb.integrations.libs.const import HANDLER_CONNECTION_ARG_TYPE
label_desc: Use image node_id 3 for calling the ClickHouseHandler obj's underlying member method code with example usage: obj.connect() and returns: self, self