-
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 4 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,26 @@ | ||
| import {submitQuery} from "../../../../api/presto-search"; | ||
| import type {PrestoQueryJobCreationSchema} 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); | ||
| }); | ||
hoophalab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
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 |
|---|---|---|
| @@ -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,91 @@ | ||||||||||||||||||||||||||
| 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) { | ||||||||||||||||||||||||||
| throw new Error("Presto not available"); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
| * Submits a search query and initiates the search process. | ||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
| 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 should be completed. | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| // eslint-disable-next-line no-warning-comments | |
| // TODO: Data, error, and success handlers are dummy implementations | |
| // and should be completed. | |
| request.log.info({ | |
| error: error, | |
| searchJobId: newSearchJobId, | |
| state: stats.state, | |
| }, "Presto search state updated"); | |
| success: () => { | |
| request.log.info("Presto search succeeded"); | |
| resolve(searchJobId); | |
| }, |
🤖 Prompt for AI Agents
In components/webui/server/src/routes/api/presto-search/index.ts around lines 49
to 51, remove the outdated TODO comment that states the data, error, and success
handlers are dummy implementations, as these handlers have now been properly
implemented and the comment is no longer relevant.
| 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.