async def query(request: Request): """ Main endpoint returning query results in the presto on wire format. """ try: sql = (await request.body()).decode().strip() df = request.app.c.sql(sql) if df is None: return DataResults(df, request) uuid = str(uuid4()) request.app.future_list[uuid] = request.app.client.compute(df) logger.debug(f"Registering {sql} with uuid {uuid}.") status_url = str( request.url.replace(path=request.app.url_path_for("status", uuid=uuid)) ) cancel_url = str( request.url.replace(path=request.app.url_path_for("cancel", uuid=uuid)) ) return QueryResults(request=request, next_url=status_url, cancel_url=cancel_url) except Exception as e: return ErrorResults(e, request=request)
async def query(request: Request): """ Main endpoint returning query results in the presto on wire format. """ try: sql = (await request.body()).decode().strip() # required for PrestoDB JDBC driver compatibility # replaces queries to unsupported `system` catalog with queries to `system_jdbc` # schema created by `create_meta_data(context)` when `jdbc_metadata=True` # TODO: explore Trino which should make JDBC compatibility easier but requires # changing response headers (see https://github.com/dask-contrib/dask-sql/pull/351) sql = sql.replace("system.jdbc", "system_jdbc") df = request.app.c.sql(sql) if df is None: return DataResults(df, request) uuid = str(uuid4()) request.app.future_list[uuid] = request.app.client.compute(df) logger.debug(f"Registering {sql} with uuid {uuid}.") status_url = str( request.url.replace(path=request.app.url_path_for("status", uuid=uuid)) ) cancel_url = str( request.url.replace(path=request.app.url_path_for("cancel", uuid=uuid)) ) return QueryResults(request=request, next_url=status_url, cancel_url=cancel_url) except Exception as e: return ErrorResults(e, request=request)
async def query(request: Request): """ Main endpoint returning query results in the presto on wire format. """ try: sql = (await request.body()).decode().strip() df = request.app.c.sql(sql) return DataResults(df, request=request) except Exception as e: return ErrorResults(e, request=request)
async def status(uuid: str, request: Request): """ Return the status (or the result) of an already running calculation """ logger.debug(f"Accessing the request with uuid {uuid}") try: future = request.app.future_list[uuid] except KeyError: raise HTTPException(status_code=404, detail="uuid not found") if future.done(): logger.debug(f"{uuid} is already finished, returning data") df = future.result() del request.app.future_list[uuid] return DataResults(df, request=request) logger.debug(f"{uuid} is not already finished") status_url = str(request.url) return QueryResults(request=request, next_url=status_url)