Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions components/webui/client/src/api/presto-search/index.ts
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
@@ -1,10 +1,13 @@
import {useCallback} from "react";

import {CaretRightOutlined} from "@ant-design/icons";
import {
Button,
Tooltip,
} from "antd";

import useSearchStore from "../../../SearchState/index";
import {handlePrestoQuerySubmit} from "../presto-search-requests";


/**
Expand All @@ -20,6 +23,10 @@ const RunButton = () => {
"Enter SQL query to run" :
"";

const handleClick = useCallback(() => {
handlePrestoQuerySubmit({queryString});
}, [queryString]);

return (
<Tooltip title={tooltipTitle}>
<Button
Expand All @@ -28,6 +35,7 @@ const RunButton = () => {
icon={<CaretRightOutlined/>}
size={"large"}
variant={"solid"}
onClick={handleClick}
>
Run
</Button>
Expand Down
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);
});
};

export {handlePrestoQuerySubmit};
38 changes: 38 additions & 0 deletions components/webui/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion components/webui/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion components/webui/server/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should also configure these in server_settings_json_updates in components/clp-package-utils/clp_package_utils/scripts/start_clp.py

@coderabbitai create an issue to track this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

I'll examine the current structure of the start_clp.py file and then create an issue to track this configuration work.


🏁 Script executed:

#!/bin/bash
# Examine the start_clp.py file to understand the server_settings_json_updates structure
cat components/clp-package-utils/clp_package_utils/scripts/start_clp.py | grep -A 20 -B 5 "server_settings_json_updates"

Length of output: 2869


Now I'll create a GitHub issue to track this configuration work.


🏁 Script executed:

#!/bin/bash
# Create a GitHub issue to track the Presto settings configuration in start_clp.py
gh issue create \
  --title "Configure Presto settings in start_clp.py server_settings_json_updates" \
  --body "## Description

The recent addition of Presto SQL query support in PR #1127 introduced new configuration settings in \`components/webui/server/settings.json\`:

- \`ClpQueryEngine\`: \"native\"
- \`PrestoHost\`: \"localhost\"  
- \`PrestoPort\`: 8889

These settings need to be properly configured in the \`server_settings_json_updates\` dictionary in \`components/clp-package-utils/clp_package_utils/scripts/start_clp.py\` to ensure consistency between the webui server configuration and the CLP startup script.

## Current Status

The settings are currently hardcoded in \`settings.json\` but are not dynamically configured through the startup script's configuration management system.

## Expected Behavior

The Presto-related settings should be configurable through the CLP configuration system and properly injected into the webui server settings during startup, similar to how other settings like database and MongoDB configurations are handled.

## References

- PR: https://github.com/y-scope/clp/pull/1127
- Comment: https://github.com/y-scope/clp/pull/1127#discussion_r2296622851
- Requested by: @junhaoliao" \
  --assignee junhaoliao

Length of output: 1275


@junhaoliao I've created issue #1260 to track the configuration of the new Presto settings in start_clp.py.

The issue documents the need to add the three new settings (ClpQueryEngine, PrestoHost, and PrestoPort) to the server_settings_json_updates dictionary so they can be properly configured through the CLP configuration system rather than being hardcoded in settings.json.


🧠 Learnings used
Learnt from: junhaoliao
PR: y-scope/clp#1152
File: components/clp-package-utils/clp_package_utils/scripts/start_clp.py:613-613
Timestamp: 2025-08-08T06:59:42.436Z
Learning: In components/clp-package-utils/clp_package_utils/scripts/start_clp.py, generic_start_scheduler sets CLP_LOGGING_LEVEL using clp_config.query_scheduler.logging_level for both schedulers; compression scheduler should use its own logging level. Tracking via an issue created from PR #1152 discussion.

}
47 changes: 47 additions & 0 deletions components/webui/server/src/plugins/app/Presto.ts
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));
},
);
92 changes: 92 additions & 0 deletions components/webui/server/src/routes/api/presto-search/index.ts
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"],
},
},

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;
23 changes: 23 additions & 0 deletions components/webui/server/src/schemas/presto-search.ts
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,
};