-
Notifications
You must be signed in to change notification settings - Fork 83
feat(webui): Add support for submitting Presto SQL queries. #1127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fbc0fb4
73d41d5
767dcf5
879941e
b2c8614
257a901
c740212
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import axios, {AxiosResponse} from "axios"; | ||
|
|
||
|
|
||
| // eslint-disable-next-line no-warning-comments | ||
| // TODO: Replace with shared type from the `@common` directory once refactoring is completed. | ||
| // Currently, server schema types require typebox dependency so they cannot be moved to the | ||
| // `@common` directory with current implementation. | ||
| type PrestoQueryJobCreationSchema = { | ||
| queryString: string; | ||
| }; | ||
|
|
||
| type PrestoQueryJobSchema = { | ||
| searchJobId: string; | ||
| }; | ||
|
|
||
|
|
||
| /** | ||
| * Sends post request to server to submit presto query. | ||
| * | ||
| * @param payload | ||
| * @return | ||
| */ | ||
| const submitQuery = async ( | ||
| payload: PrestoQueryJobCreationSchema | ||
| ): Promise<AxiosResponse<PrestoQueryJobSchema>> => { | ||
| console.log("Submitting query:", JSON.stringify(payload)); | ||
|
|
||
| return axios.post<PrestoQueryJobSchema>("/api/presto-search/query", payload); | ||
| }; | ||
|
|
||
| export type { | ||
| PrestoQueryJobCreationSchema, | ||
| PrestoQueryJobSchema, | ||
| }; | ||
|
|
||
| export {submitQuery}; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { | ||
| type PrestoQueryJobCreationSchema, | ||
| submitQuery, | ||
| } from "../../../../api/presto-search"; | ||
|
|
||
|
|
||
| /** | ||
| * Submits a new Presto query to server. | ||
| * | ||
| * @param payload | ||
| */ | ||
| const handlePrestoQuerySubmit = (payload: PrestoQueryJobCreationSchema) => { | ||
| submitQuery(payload) | ||
| .then((result) => { | ||
| const {searchJobId} = result.data; | ||
| console.debug( | ||
| "Presto search job created - ", | ||
| "Search job ID:", | ||
| searchJobId | ||
| ); | ||
| }) | ||
| .catch((err: unknown) => { | ||
| console.error("Failed to submit query:", err); | ||
| }); | ||
| }; | ||
davemarco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export {handlePrestoQuerySubmit}; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,5 +16,9 @@ | |
| "StreamTargetUncompressedSize": 134217728, | ||
| "StreamFilesS3Region": null, | ||
| "StreamFilesS3PathPrefix": null, | ||
| "StreamFilesS3Profile": null | ||
| "StreamFilesS3Profile": null, | ||
|
|
||
| "ClpQueryEngine": "native", | ||
| "PrestoHost": "localhost", | ||
| "PrestoPort": 8889 | ||
|
Comment on lines
+21
to
+23
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should also configure these in @coderabbitai create an issue to track this
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainI'll examine the current structure of the start_clp.py file and then create an issue to track this configuration work. 🏁 Script executed: Length of output: 2869 Now I'll create a GitHub issue to track this configuration work. 🏁 Script executed: Length of output: 1275 @junhaoliao I've created issue #1260 to track the configuration of the new Presto settings in The issue documents the need to add the three new settings ( 🧠 Learnings used |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import fp from "fastify-plugin"; | ||
| import { | ||
| Client, | ||
| ClientOptions, | ||
| } from "presto-client"; | ||
|
|
||
| import settings from "../../../settings.json" with {type: "json"}; | ||
|
|
||
|
|
||
| /** | ||
| * Class to manage Presto client connections. | ||
| */ | ||
| class Presto { | ||
| readonly client; | ||
|
|
||
| /** | ||
| * @param clientOptions | ||
| */ | ||
| constructor (clientOptions: ClientOptions) { | ||
| this.client = new Client(clientOptions); | ||
| } | ||
| } | ||
|
|
||
| declare module "fastify" { | ||
| interface FastifyInstance { | ||
| Presto?: Presto; | ||
| } | ||
| } | ||
|
|
||
| export default fp( | ||
| (fastify) => { | ||
| if ("presto" !== settings.ClpQueryEngine) { | ||
| return; | ||
| } | ||
|
|
||
| const clientOptions: ClientOptions = { | ||
| host: settings.PrestoHost, | ||
| port: settings.PrestoPort, | ||
| }; | ||
|
|
||
| fastify.log.info( | ||
| clientOptions, | ||
| "Initializing Presto" | ||
| ); | ||
| fastify.decorate("Presto", new Presto(clientOptions)); | ||
| }, | ||
| ); | ||
davemarco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import {FastifyPluginAsyncTypebox} from "@fastify/type-provider-typebox"; | ||
| import {StatusCodes} from "http-status-codes"; | ||
|
|
||
| import {ErrorSchema} from "../../../schemas/error.js"; | ||
| import { | ||
| PrestoQueryJobCreationSchema, | ||
| PrestoQueryJobSchema, | ||
| } from "../../../schemas/presto-search.js"; | ||
|
|
||
|
|
||
| /** | ||
| * Presto search API routes. | ||
| * | ||
| * @param fastify | ||
| */ | ||
| const plugin: FastifyPluginAsyncTypebox = async (fastify) => { | ||
| const {Presto} = fastify; | ||
|
|
||
| if ("undefined" === typeof Presto) { | ||
| // If Presto client is not available, skip the plugin registration. | ||
| return; | ||
| } | ||
|
|
||
| /** | ||
| * Submits a search query. | ||
| */ | ||
| fastify.post( | ||
| "/query", | ||
| { | ||
| schema: { | ||
| body: PrestoQueryJobCreationSchema, | ||
| response: { | ||
| [StatusCodes.CREATED]: PrestoQueryJobSchema, | ||
| [StatusCodes.INTERNAL_SERVER_ERROR]: ErrorSchema, | ||
| }, | ||
| tags: ["Presto Search"], | ||
| }, | ||
| }, | ||
|
|
||
davemarco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| async (request, reply) => { | ||
| const {queryString} = request.body; | ||
|
|
||
| let searchJobId: string; | ||
|
|
||
| try { | ||
| searchJobId = await new Promise<string>((resolve, reject) => { | ||
| let isResolved = false; | ||
|
|
||
| Presto.client.execute({ | ||
| // eslint-disable-next-line no-warning-comments | ||
| // TODO: Data, error, and success handlers are dummy implementations | ||
| // and will be replaced with proper implementations. | ||
| data: (_, data, columns) => { | ||
| request.log.info({columns, data}, "Presto data"); | ||
| }, | ||
| error: (error) => { | ||
| request.log.info(error, "Presto search failed"); | ||
| if (false === isResolved) { | ||
| isResolved = true; | ||
| reject(new Error("Presto search failed")); | ||
| } | ||
| }, | ||
| query: queryString, | ||
| state: (_, queryId, stats) => { | ||
| request.log.info({ | ||
| searchJobId: queryId, | ||
| state: stats.state, | ||
| }, "Presto search state updated"); | ||
|
|
||
| if (false === isResolved) { | ||
| isResolved = true; | ||
| resolve(queryId); | ||
| } | ||
| }, | ||
| success: () => { | ||
| request.log.info("Presto search succeeded"); | ||
| }, | ||
| }); | ||
| }); | ||
| } catch (error) { | ||
| request.log.error(error, "Failed to submit Presto query"); | ||
| throw error; | ||
| } | ||
|
|
||
| reply.code(StatusCodes.CREATED); | ||
|
|
||
| return {searchJobId}; | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
| export default plugin; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import {Type} from "@sinclair/typebox"; | ||
|
|
||
| import {StringSchema} from "./common.js"; | ||
|
|
||
|
|
||
| /** | ||
| * Schema for request to create a new Presto query job. | ||
| */ | ||
| const PrestoQueryJobCreationSchema = Type.Object({ | ||
| queryString: StringSchema, | ||
| }); | ||
|
|
||
| /** | ||
| * Schema to identify a Presto query job. | ||
| */ | ||
| const PrestoQueryJobSchema = Type.Object({ | ||
| searchJobId: StringSchema, | ||
| }); | ||
|
|
||
| export { | ||
| PrestoQueryJobCreationSchema, | ||
| PrestoQueryJobSchema, | ||
| }; |
Uh oh!
There was an error while loading. Please reload this page.