def controller(requestBuffer): request = RequestSchemaFrom(requestBuffer) print(request.header) dmlResponse = DMLResponseSchema(resultToken=123456, nodeConnection=NodeConnectionSchema( path='/', type=1, ), calciteTime=1) responseBuffer = ResponseSchema( status=Status.Success, payload=dmlResponse.ToBuffer() ).ToBuffer() return responseBuffer
def _open(self): requestBuffer = MakeAuthRequestBuffer(OrchestratorMessageType.AuthOpen) try: responseBuffer = self.send(requestBuffer) except ConnectionError as err: print(err) response = ResponseSchema.From(responseBuffer) if response.status == Status.Error: raise Error(ResponseErrorSchema.From(response.payload).errors) else: self.accessToken = AuthResponseSchema.From(response.payload).accessToken # TODO find a way to print only for debug mode (add verbose arg) return self.accessToken
def _create_table(self, tableName, columnNames, columnTypes): create_table_message = DDLCreateTableRequestSchema(name=tableName, columnNames=columnNames, columnTypes=columnTypes, dbName=self.dbname) requestBuffer = MakeRequestBuffer(OrchestratorMessageType.DDL_CREATE_TABLE, self.connection.accessToken, create_table_message) responseBuffer = self.connection.send(requestBuffer) response = ResponseSchema.From(responseBuffer) if response.status == Status.Error: raise Error(ResponseErrorSchema.From(response.payload).errors) return response.status
def main(): ACCESS_TOKEN = 456 connection = blazingdb.protocol.UnixSocketConnection('/tmp/socket') client = blazingdb.protocol.Client(connection) getResult = GetResultRequestSchema(resultToken=123456) requestBuffer = MakeRequestBuffer(InterpreterMessage.GetResult, ACCESS_TOKEN, getResult) responseBuffer = client.send(requestBuffer) response = ResponseSchema.From(responseBuffer) print(response.status) dmlResponse = DMLResponseSchema.From(response.payload) print(dmlResponse.resultToken)
def close(self): requestBuffer = MakeAuthRequestBuffer(OrchestratorMessageType.AuthClose) try: responseBuffer = self.send(requestBuffer) except ConnectionError as err: print(err) response = ResponseSchema.From(responseBuffer) if response.status == Status.Error: raise Error(ResponseErrorSchema.From(response.payload).errors) self._socket = None self._unix_connection = None self.accessToken = None
def remove_table(self, table_name): """ Args: table: table name. """ drop_table_message = DDLDropTableRequestSchema(name=table_name, dbName=self.dbname) requestBuffer = MakeRequestBuffer(OrchestratorMessageType.DDL_DROP_TABLE, self.connection.accessToken, drop_table_message) responseBuffer = self.connection.sendRequest(requestBuffer) response = ResponseSchema.From(responseBuffer) if response.status == Status.Error: raise Error(ResponseErrorSchema.From(response.payload).errors) return response.status
def get_result(self, result_token, interpreter_path): getResultRequest = GetResultRequestSchema(resultToken=result_token) requestBuffer = MakeRequestBuffer(InterpreterMessage.GetResult, self.connection.accessToken, getResultRequest) responseBuffer = self._send_request(interpreter_path, requestBuffer) response = ResponseSchema.From(responseBuffer) if response.status == Status.Error: raise Error(ResponseErrorSchema.From(response.payload).errors) queryResult = GetQueryResultFrom(response.payload) return queryResult
def run_query(self, query, tables): """ Returns token object. """ tableGroup = self._to_table_group(tables) dml_message = BuildDMLRequestSchema(query, tableGroup) requestBuffer = MakeRequestBuffer(OrchestratorMessageType.DML, self.connection.accessToken, dml_message) responseBuffer = self.connection.send(requestBuffer) response = ResponseSchema.From(responseBuffer) if response.status == Status.Error: errorResponse = ResponseErrorSchema.From(response.payload) if b'SqlSyntaxException' in errorResponse.errors: raise SyntaxError(errorResponse.errors.decode('utf-8')) raise Error(errorResponse.errors) result = DMLResponseSchema.From(response.payload) return (result.resultToken, result.nodeConnection.path, result.calciteTime)