From fbc0fb4962fc7aef5508437f94c97f9c69becd7a Mon Sep 17 00:00:00 2001 From: hoophalab <200652805+hoophalab@users.noreply.github.com> Date: Tue, 22 Jul 2025 14:22:29 -0400 Subject: [PATCH 1/4] feat: Add presto search route. --- .../webui/client/src/api/presto-search.ts | 43 +++++++++ .../SearchControls/Presto/RunButton/index.tsx | 15 ++++ components/webui/server/package-lock.json | 38 ++++++++ components/webui/server/package.json | 4 +- components/webui/server/settings.json | 6 +- .../src/routes/api/presto-search/index.ts | 89 +++++++++++++++++++ .../webui/server/src/schemas/presto-search.ts | 20 +++++ 7 files changed, 213 insertions(+), 2 deletions(-) create mode 100644 components/webui/client/src/api/presto-search.ts create mode 100644 components/webui/server/src/routes/api/presto-search/index.ts create mode 100644 components/webui/server/src/schemas/presto-search.ts diff --git a/components/webui/client/src/api/presto-search.ts b/components/webui/client/src/api/presto-search.ts new file mode 100644 index 0000000000..876ccd8179 --- /dev/null +++ b/components/webui/client/src/api/presto-search.ts @@ -0,0 +1,43 @@ +import { + Static, + Type, +} from "@sinclair/typebox"; +import {Value} from "@sinclair/typebox/value"; +import axios 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. +const StringSchema = Type.String({ + minLength: 1, +}); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const PrestoSearchJobCreationSchema = Type.Object({ + queryString: StringSchema, +}); + +type PrestoSearchJobCreation = Static; + +const PrestoJobSchema = Type.Object( + { + searchJobId: StringSchema, + } +); + +type PrestoJob = Static; + +/** + * Sends post request to server tosubmit presto query. + * + * @param payload + * @return + */ +const submitQuery = async (payload: PrestoSearchJobCreation): Promise => { + const ret = await axios.post("/api/presto-search/query", payload); + return Value.Parse(PrestoJobSchema, ret.data); +}; + +export {submitQuery}; diff --git a/components/webui/client/src/pages/SearchPage/SearchControls/Presto/RunButton/index.tsx b/components/webui/client/src/pages/SearchPage/SearchControls/Presto/RunButton/index.tsx index 839d96209f..51b7c40ab8 100644 --- a/components/webui/client/src/pages/SearchPage/SearchControls/Presto/RunButton/index.tsx +++ b/components/webui/client/src/pages/SearchPage/SearchControls/Presto/RunButton/index.tsx @@ -1,9 +1,12 @@ +import {useCallback} from "react"; + import {CaretRightOutlined} from "@ant-design/icons"; import { Button, Tooltip, } from "antd"; +import {submitQuery} from "../../../../../api/presto-search"; import useSearchStore from "../../../SearchState/index"; @@ -20,6 +23,17 @@ const RunButton = () => { "Enter SQL query to run" : ""; + const handleClick = useCallback(() => { + submitQuery({queryString}) + .then(({searchJobId}) => { + const {updateSearchJobId} = useSearchStore.getState(); + updateSearchJobId(searchJobId); + }) + .catch((err: unknown) => { + console.error("Failed to submit query:", err); + }); + }, [queryString]); + return ( diff --git a/components/webui/server/package-lock.json b/components/webui/server/package-lock.json index 976f56548c..97a013757b 100644 --- a/components/webui/server/package-lock.json +++ b/components/webui/server/package-lock.json @@ -29,10 +29,12 @@ "fastify-plugin": "^5.0.1", "http-status-codes": "^2.3.0", "pino-pretty": "^13.0.0", + "presto-client": "^1.1.0", "socket.io": "^4.8.1", "typescript": "~5.7.3" }, "devDependencies": { + "@types/presto-client": "^1.0.2", "concurrently": "^9.1.2", "eslint-config-yscope": "latest", "fastify-cli": "^7.4.0", @@ -3674,6 +3676,13 @@ "undici-types": "~6.20.0" } }, + "node_modules/@types/presto-client": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@types/presto-client/-/presto-client-1.0.2.tgz", + "integrity": "sha512-1q7QtX+ykoX5zjWTJpntIzxyhr20ZHrEySk2p2PQCOwPI7DJtGsL62KKFZMsTqPjikpjLL71BWtVA0cPMyYdfA==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/webidl-conversions": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", @@ -7041,6 +7050,26 @@ "license": "ISC", "peer": true }, + "node_modules/follow-redirects": { + "version": "1.15.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/for-each": { "version": "0.3.5", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.5.tgz", @@ -10065,6 +10094,15 @@ "node": ">= 0.8.0" } }, + "node_modules/presto-client": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/presto-client/-/presto-client-1.1.0.tgz", + "integrity": "sha512-DOWEKp0eHP/x6Fupk5673vZND7OUxFtV9VUO9HMvf4DFzoWKTLMRAJ3o5/7Mgs5z9w5BEUKU88IZaume6LMelw==", + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.15.3" + } + }, "node_modules/prismjs": { "version": "1.29.0", "resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.29.0.tgz", diff --git a/components/webui/server/package.json b/components/webui/server/package.json index b2bd7bafa6..ebe68d80ec 100644 --- a/components/webui/server/package.json +++ b/components/webui/server/package.json @@ -22,10 +22,10 @@ "@aws-sdk/s3-request-presigner": "^3.758.0", "@fastify/autoload": "^6.3.0", "@fastify/env": "^5.0.2", + "@fastify/http-proxy": "^11.3.0", "@fastify/mongodb": "^9.0.2", "@fastify/mysql": "^5.0.2", "@fastify/rate-limit": "^10.2.2", - "@fastify/http-proxy": "^11.3.0", "@fastify/sensible": "^6.0.3", "@fastify/static": "^8.1.1", "@fastify/type-provider-typebox": "^5.1.0", @@ -38,10 +38,12 @@ "fastify-plugin": "^5.0.1", "http-status-codes": "^2.3.0", "pino-pretty": "^13.0.0", + "presto-client": "^1.1.0", "socket.io": "^4.8.1", "typescript": "~5.7.3" }, "devDependencies": { + "@types/presto-client": "^1.0.2", "concurrently": "^9.1.2", "eslint-config-yscope": "latest", "fastify-cli": "^7.4.0", diff --git a/components/webui/server/settings.json b/components/webui/server/settings.json index 5f7f789364..2727c573d3 100644 --- a/components/webui/server/settings.json +++ b/components/webui/server/settings.json @@ -16,5 +16,9 @@ "StreamTargetUncompressedSize": 134217728, "StreamFilesS3Region": null, "StreamFilesS3PathPrefix": null, - "StreamFilesS3Profile": null + "StreamFilesS3Profile": null, + + "EnablePresto": true, + "PrestoHost": "localhost", + "PrestoPort": 8080 } diff --git a/components/webui/server/src/routes/api/presto-search/index.ts b/components/webui/server/src/routes/api/presto-search/index.ts new file mode 100644 index 0000000000..7d58e9d648 --- /dev/null +++ b/components/webui/server/src/routes/api/presto-search/index.ts @@ -0,0 +1,89 @@ +import {FastifyPluginAsyncTypebox} from "@fastify/type-provider-typebox"; +import {StatusCodes} from "http-status-codes"; +import {Client} from "presto-client"; + +import settings from "../../../../settings.json" with {type: "json"}; +import {ErrorSchema} from "../../../schemas/error.js"; +import { + PrestoJobSchema, + PrestoSearchJobCreationSchema, +} from "../../../schemas/presto-search.js"; +import {Nullable} from "../../../typings/common.js"; + + +/** + * Presto search API routes. + * + * @param fastify + */ +const plugin: FastifyPluginAsyncTypebox = async (fastify) => { + if (false === settings.EnablePresto) { + return; + } + + const client = new Client({host: settings.PrestoHost, port: settings.PrestoPort}); + + /** + * Submits a search query and initiates the search process. + */ + fastify.post( + "/query", + { + schema: { + body: PrestoSearchJobCreationSchema, + response: { + [StatusCodes.CREATED]: PrestoJobSchema, + [StatusCodes.INTERNAL_SERVER_ERROR]: ErrorSchema, + }, + tags: ["Search"], + }, + }, + + async (request, reply) => { + const {queryString} = request.body; + + let searchJobId: Nullable = null; + + searchJobId = await new Promise((resolve) => { + client.execute({ + data: (error, data, columns) => { + if (null === searchJobId) { + request.log.error("Data arrived from Presto before the search job id."); + } + request.log.info({error, searchJobId, columns, data}, "Presto data"); + }, + error: (error) => { + request.log.info(error, "Presto search failed"); + + // The `/query` endpoint will catch this error if `resolve` hasn't + // been called. + throw new Error("Presto search failed."); + }, + query: queryString, + state: (error, newSearchJobId, stats) => { + request.log.info({ + error: error, + searchJobId: newSearchJobId, + state: stats.state, + }, "Presto search state updated"); + + resolve(newSearchJobId); + }, + success: () => { + request.log.info("Presto search succeeded"); + }, + }); + }); + + reply.code(StatusCodes.CREATED); + + if (null === searchJobId) { + throw new Error("searchJobId is null"); + } + + return {searchJobId}; + } + ); +}; + +export default plugin; diff --git a/components/webui/server/src/schemas/presto-search.ts b/components/webui/server/src/schemas/presto-search.ts new file mode 100644 index 0000000000..0d32f088b1 --- /dev/null +++ b/components/webui/server/src/schemas/presto-search.ts @@ -0,0 +1,20 @@ +import {Type} from "@sinclair/typebox"; + +import {StringSchema} from "./common.js"; + + +/** + * Schema for request to create a new query job. + */ +const PrestoSearchJobCreationSchema = Type.Object({ + queryString: StringSchema, +}); + +const PrestoJobSchema = Type.Object({ + searchJobId: StringSchema, +}); + +export { + PrestoJobSchema, + PrestoSearchJobCreationSchema, +}; From 73d41d5e52341208dab65d6d007947028c7575b2 Mon Sep 17 00:00:00 2001 From: hoophalab <200652805+hoophalab@users.noreply.github.com> Date: Fri, 25 Jul 2025 17:06:07 -0400 Subject: [PATCH 2/4] fix a typo in jsdoc --- components/webui/client/src/api/presto-search.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/webui/client/src/api/presto-search.ts b/components/webui/client/src/api/presto-search.ts index 876ccd8179..41705a12ad 100644 --- a/components/webui/client/src/api/presto-search.ts +++ b/components/webui/client/src/api/presto-search.ts @@ -30,7 +30,7 @@ const PrestoJobSchema = Type.Object( type PrestoJob = Static; /** - * Sends post request to server tosubmit presto query. + * Sends post request to server to submit presto query. * * @param payload * @return From 879941e0232bb7e1e708df87be5c2838385158c9 Mon Sep 17 00:00:00 2001 From: Marco Date: Thu, 31 Jul 2025 18:58:45 +0000 Subject: [PATCH 3/4] latest --- components/webui/client/public/settings.json | 2 +- .../webui/client/src/api/presto-search.ts | 43 --------- .../SearchControls/Presto/RunButton/index.tsx | 11 +-- .../Presto/presto-search-requests.ts | 26 ++++++ components/webui/server/settings.json | 2 +- .../webui/server/src/plugins/app/Presto.ts | 47 ++++++++++ .../src/routes/api/presto-search/index.ts | 90 ++++++++++--------- .../webui/server/src/schemas/presto-search.ts | 13 +-- 8 files changed, 131 insertions(+), 103 deletions(-) delete mode 100644 components/webui/client/src/api/presto-search.ts create mode 100644 components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts create mode 100644 components/webui/server/src/plugins/app/Presto.ts diff --git a/components/webui/client/public/settings.json b/components/webui/client/public/settings.json index 67f60e795b..05048049af 100644 --- a/components/webui/client/public/settings.json +++ b/components/webui/client/public/settings.json @@ -1,6 +1,6 @@ { "ClpStorageEngine": "clp", - "ClpQueryEngine": "native", + "ClpQueryEngine": "presto", "MongoDbSearchResultsMetadataCollectionName": "results-metadata", "SqlDbClpArchivesTableName": "clp_archives", "SqlDbClpDatasetsTableName": "clp_datasets", diff --git a/components/webui/client/src/api/presto-search.ts b/components/webui/client/src/api/presto-search.ts deleted file mode 100644 index 41705a12ad..0000000000 --- a/components/webui/client/src/api/presto-search.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { - Static, - Type, -} from "@sinclair/typebox"; -import {Value} from "@sinclair/typebox/value"; -import axios 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. -const StringSchema = Type.String({ - minLength: 1, -}); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -const PrestoSearchJobCreationSchema = Type.Object({ - queryString: StringSchema, -}); - -type PrestoSearchJobCreation = Static; - -const PrestoJobSchema = Type.Object( - { - searchJobId: StringSchema, - } -); - -type PrestoJob = Static; - -/** - * Sends post request to server to submit presto query. - * - * @param payload - * @return - */ -const submitQuery = async (payload: PrestoSearchJobCreation): Promise => { - const ret = await axios.post("/api/presto-search/query", payload); - return Value.Parse(PrestoJobSchema, ret.data); -}; - -export {submitQuery}; diff --git a/components/webui/client/src/pages/SearchPage/SearchControls/Presto/RunButton/index.tsx b/components/webui/client/src/pages/SearchPage/SearchControls/Presto/RunButton/index.tsx index 51b7c40ab8..e0f5c26d48 100644 --- a/components/webui/client/src/pages/SearchPage/SearchControls/Presto/RunButton/index.tsx +++ b/components/webui/client/src/pages/SearchPage/SearchControls/Presto/RunButton/index.tsx @@ -6,8 +6,8 @@ import { Tooltip, } from "antd"; -import {submitQuery} from "../../../../../api/presto-search"; import useSearchStore from "../../../SearchState/index"; +import {handlePrestoQuerySubmit} from "../presto-search-requests"; /** @@ -24,14 +24,7 @@ const RunButton = () => { ""; const handleClick = useCallback(() => { - submitQuery({queryString}) - .then(({searchJobId}) => { - const {updateSearchJobId} = useSearchStore.getState(); - updateSearchJobId(searchJobId); - }) - .catch((err: unknown) => { - console.error("Failed to submit query:", err); - }); + handlePrestoQuerySubmit({queryString}); }, [queryString]); return ( diff --git a/components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts b/components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts new file mode 100644 index 0000000000..f6bcff6a80 --- /dev/null +++ b/components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts @@ -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); + }); +}; + +export { + handlePrestoQuerySubmit, +}; diff --git a/components/webui/server/settings.json b/components/webui/server/settings.json index 2727c573d3..a5bb5c8d0d 100644 --- a/components/webui/server/settings.json +++ b/components/webui/server/settings.json @@ -18,7 +18,7 @@ "StreamFilesS3PathPrefix": null, "StreamFilesS3Profile": null, - "EnablePresto": true, + "ClpQueryEngine": "presto", "PrestoHost": "localhost", "PrestoPort": 8080 } diff --git a/components/webui/server/src/plugins/app/Presto.ts b/components/webui/server/src/plugins/app/Presto.ts new file mode 100644 index 0000000000..dd6ccf31be --- /dev/null +++ b/components/webui/server/src/plugins/app/Presto.ts @@ -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)); + }, +); diff --git a/components/webui/server/src/routes/api/presto-search/index.ts b/components/webui/server/src/routes/api/presto-search/index.ts index 7d58e9d648..858b91b496 100644 --- a/components/webui/server/src/routes/api/presto-search/index.ts +++ b/components/webui/server/src/routes/api/presto-search/index.ts @@ -1,14 +1,11 @@ import {FastifyPluginAsyncTypebox} from "@fastify/type-provider-typebox"; import {StatusCodes} from "http-status-codes"; -import {Client} from "presto-client"; -import settings from "../../../../settings.json" with {type: "json"}; import {ErrorSchema} from "../../../schemas/error.js"; import { - PrestoJobSchema, - PrestoSearchJobCreationSchema, + PrestoQueryJobCreationSchema, + PrestoQueryJobSchema, } from "../../../schemas/presto-search.js"; -import {Nullable} from "../../../typings/common.js"; /** @@ -17,11 +14,11 @@ import {Nullable} from "../../../typings/common.js"; * @param fastify */ const plugin: FastifyPluginAsyncTypebox = async (fastify) => { - if (false === settings.EnablePresto) { - return; - } + const {Presto} = fastify; - const client = new Client({host: settings.PrestoHost, port: settings.PrestoPort}); + if ("undefined" === typeof Presto) { + throw new Error("Presto not available"); + } /** * Submits a search query and initiates the search process. @@ -30,57 +27,62 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => { "/query", { schema: { - body: PrestoSearchJobCreationSchema, + body: PrestoQueryJobCreationSchema, response: { - [StatusCodes.CREATED]: PrestoJobSchema, + [StatusCodes.CREATED]: PrestoQueryJobSchema, [StatusCodes.INTERNAL_SERVER_ERROR]: ErrorSchema, }, - tags: ["Search"], + tags: ["Presto Search"], }, }, async (request, reply) => { const {queryString} = request.body; - let searchJobId: Nullable = null; + let searchJobId: string; - searchJobId = await new Promise((resolve) => { - client.execute({ - data: (error, data, columns) => { - if (null === searchJobId) { - request.log.error("Data arrived from Presto before the search job id."); - } - request.log.info({error, searchJobId, columns, data}, "Presto data"); - }, - error: (error) => { - request.log.info(error, "Presto search failed"); + try { + searchJobId = await new Promise((resolve, reject) => { + let isResolved = false; - // The `/query` endpoint will catch this error if `resolve` hasn't - // been called. - throw new Error("Presto search failed."); - }, - query: queryString, - state: (error, newSearchJobId, stats) => { - request.log.info({ - error: error, - searchJobId: newSearchJobId, - state: stats.state, - }, "Presto search state updated"); + Presto.client.execute({ + // eslint-disable-next-line no-warning-comments + // TODO: Data, error, and success handlers are dummy implementations + // and should be completed. + 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"); - resolve(newSearchJobId); - }, - success: () => { - request.log.info("Presto search succeeded"); - }, + 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); - if (null === searchJobId) { - throw new Error("searchJobId is null"); - } - return {searchJobId}; } ); diff --git a/components/webui/server/src/schemas/presto-search.ts b/components/webui/server/src/schemas/presto-search.ts index 0d32f088b1..ec4a92002d 100644 --- a/components/webui/server/src/schemas/presto-search.ts +++ b/components/webui/server/src/schemas/presto-search.ts @@ -4,17 +4,20 @@ import {StringSchema} from "./common.js"; /** - * Schema for request to create a new query job. + * Schema for request to create a new Presto query job. */ -const PrestoSearchJobCreationSchema = Type.Object({ +const PrestoQueryJobCreationSchema = Type.Object({ queryString: StringSchema, }); -const PrestoJobSchema = Type.Object({ +/** + * Schema to identify a Presto query job. + */ +const PrestoQueryJobSchema = Type.Object({ searchJobId: StringSchema, }); export { - PrestoJobSchema, - PrestoSearchJobCreationSchema, + PrestoQueryJobCreationSchema, + PrestoQueryJobSchema, }; From b2c8614f0f4d2957b6a9f6da9cc83976ebc3991f Mon Sep 17 00:00:00 2001 From: Marco Date: Thu, 31 Jul 2025 19:32:19 +0000 Subject: [PATCH 4/4] latest --- components/webui/client/public/settings.json | 2 +- .../client/src/api/presto-search/index.ts | 36 +++++++++++++++++++ .../Presto/presto-search-requests.ts | 11 +++--- components/webui/server/settings.json | 4 +-- .../src/routes/api/presto-search/index.ts | 7 ++-- 5 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 components/webui/client/src/api/presto-search/index.ts diff --git a/components/webui/client/public/settings.json b/components/webui/client/public/settings.json index 05048049af..67f60e795b 100644 --- a/components/webui/client/public/settings.json +++ b/components/webui/client/public/settings.json @@ -1,6 +1,6 @@ { "ClpStorageEngine": "clp", - "ClpQueryEngine": "presto", + "ClpQueryEngine": "native", "MongoDbSearchResultsMetadataCollectionName": "results-metadata", "SqlDbClpArchivesTableName": "clp_archives", "SqlDbClpDatasetsTableName": "clp_datasets", diff --git a/components/webui/client/src/api/presto-search/index.ts b/components/webui/client/src/api/presto-search/index.ts new file mode 100644 index 0000000000..fdd34b6aa1 --- /dev/null +++ b/components/webui/client/src/api/presto-search/index.ts @@ -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> => { + console.log("Submitting query:", JSON.stringify(payload)); + + return axios.post("/api/presto-search/query", payload); +}; + +export type { + PrestoQueryJobCreationSchema, + PrestoQueryJobSchema, +}; + +export {submitQuery}; diff --git a/components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts b/components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts index f6bcff6a80..a42e4110d1 100644 --- a/components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts +++ b/components/webui/client/src/pages/SearchPage/SearchControls/Presto/presto-search-requests.ts @@ -1,5 +1,8 @@ -import {submitQuery} from "../../../../api/presto-search"; -import type {PrestoQueryJobCreationSchema} from "../../../../api/presto-search"; +import { + type PrestoQueryJobCreationSchema, + submitQuery, +} from "../../../../api/presto-search"; + /** * Submits a new Presto query to server. @@ -21,6 +24,4 @@ const handlePrestoQuerySubmit = (payload: PrestoQueryJobCreationSchema) => { }); }; -export { - handlePrestoQuerySubmit, -}; +export {handlePrestoQuerySubmit}; diff --git a/components/webui/server/settings.json b/components/webui/server/settings.json index a5bb5c8d0d..4a5990b32f 100644 --- a/components/webui/server/settings.json +++ b/components/webui/server/settings.json @@ -18,7 +18,7 @@ "StreamFilesS3PathPrefix": null, "StreamFilesS3Profile": null, - "ClpQueryEngine": "presto", + "ClpQueryEngine": "native", "PrestoHost": "localhost", - "PrestoPort": 8080 + "PrestoPort": 8889 } diff --git a/components/webui/server/src/routes/api/presto-search/index.ts b/components/webui/server/src/routes/api/presto-search/index.ts index 858b91b496..2c8e8acc23 100644 --- a/components/webui/server/src/routes/api/presto-search/index.ts +++ b/components/webui/server/src/routes/api/presto-search/index.ts @@ -17,11 +17,12 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => { const {Presto} = fastify; if ("undefined" === typeof Presto) { - throw new Error("Presto not available"); + // If Presto client is not available, skip the plugin registration. + return; } /** - * Submits a search query and initiates the search process. + * Submits a search query. */ fastify.post( "/query", @@ -48,7 +49,7 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => { Presto.client.execute({ // eslint-disable-next-line no-warning-comments // TODO: Data, error, and success handlers are dummy implementations - // and should be completed. + // and will be replaced with proper implementations. data: (_, data, columns) => { request.log.info({columns, data}, "Presto data"); },