def __init__(self, user=None, password=None, host=None, port=9091, dbname=None, protocol="http"): if protocol == "http": if not host.startswith(protocol): # the THttpClient expects http[s]://localhost host = protocol + '://' + host transport = THttpClient.THttpClient(host) proto = TJSONProtocol.TJSONProtocol(transport) socket = None elif protocol == "binary": socket = TSocket.TSocket(host, port) transport = TTransport.TBufferedTransport(socket) proto = TBinaryProtocol.TBinaryProtocol(transport) else: raise TypeError("`protocol` should be one of ['http', 'binary'], ", "got {} instead".format(protocol)) self._user = user self._password = password self._host = host self._port = port self._dbname = dbname self._transport = transport self._protocol = protocol self._socket = socket self._transport.open() self._client = MapD.Client(proto) self._session = self._client.connect(user, password, dbname)
def get_client(host, port): socket = TSocket.TSocket(host, port) transport = TTransport.TBufferedTransport(socket) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = MapD.Client(protocol) transport.open() return client
def get_client(host_or_uri, port, http): if http: transport = THttpClient.THttpClient(host_or_uri) protocol = TJSONProtocol.TJSONProtocol(transport) else: socket = TSocket.TSocket(host_or_uri, port) transport = TTransport.TBufferedTransport(socket) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = MapD.Client(protocol) transport.open() return client