Skip to content

Commit 188c58e

Browse files
kosztimosabua
authored andcommitted
Make QueryEditor as a reusable react component
1 parent ce512c2 commit 188c58e

File tree

15 files changed

+1216
-1087
lines changed

15 files changed

+1216
-1087
lines changed

.github/workflows/release.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: Publish Package to npmjs
33
on:
44
release:
55
types: [created]
6-
pull_request:
76

87
jobs:
98
publish:
@@ -27,11 +26,7 @@ jobs:
2726
- name: Build package
2827
run: npm run build
2928

30-
# This step is a placeholder for publishing to npm.
31-
# The project structure and Node configuration will need to be adjusted
32-
# before this can be enabled and work as intended.
3329
- name: Publish to npm
34-
if: github.event_name == 'release'
3530
run: npm publish
3631
env:
3732
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

README.md

Lines changed: 84 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,48 @@
11
# Trino Query UI
22

3-
This Trino Query UI is a new UI component that can be integrated into Trino and run directly from the Trino installation at the `/query/` path. For testing, it can also be run separately and can proxy to a Trino running locally or elsewhere.
3+
A reusable React component for executing queries against Trino. It can be
4+
embedded into any React application and configured to proxy requests to a local
5+
or remote Trino cluster.
6+
7+
> [!WARNING]
8+
> This package is under heavy development and is not yet recommended for
9+
> production workloads. Treat the current release as an early-stage demo;
10+
> production-ready builds and documentation are planned.
411
512
![Trino Query UI Demo](demos.gif "Trino Query UI Demo")
613

714
Implementation details:
8-
* React Typescript project with Vite
9-
* Using Node.js v20+
10-
* Monaco editor + ANTLR parser using Trino language
15+
* React TypeScript project with Vite
16+
* Uses Node.js v20+
17+
* Monaco editor + ANTLR parser using the Trino language
18+
19+
## Installation
20+
21+
```
22+
npm install trino-query-ui
23+
```
24+
25+
## Quick start
26+
27+
```tsx
28+
import { QueryEditor } from 'trino-query-ui'
29+
import 'trino-query-ui/dist/index.css'
30+
31+
function MyTrinoApp() {
32+
return <QueryEditor />
33+
}
34+
35+
export default MyTrinoApp
36+
```
1137

12-
## Building and Shipping in Trino
38+
## Building and shipping in Trino
1339

1440
The Query UI builds just like the existing UI in Trino.
1541
1. First you build the TypeScript into Javascript and CSS
1642
2. Then copy the distributable path into Trino.
1743
3. Then modify Trino to respond to the query ui path.
1844

19-
### Building for Integration
45+
### Building for integration
2046

2147
```
2248
cd precise
@@ -28,7 +54,7 @@ npm run build
2854
mkdir -p $TRINO_HOME/core/trino-main/src/main/resources/query_ui_webapp/
2955
cp -r dist/* $TRINO_HOME/core/trino-main/src/main/resources/query_ui_webapp/
3056

31-
### Modifying Trino to Respond to /query/
57+
### Modifying Trino to respond to /query/
3258

3359
Modify `$TRINO_HOME/core/trino-main/src/main/java/io/trino/server/ui/WebUiStaticResource.java`:
3460

@@ -88,19 +114,23 @@ Add `/query/` path. Note any path can be used:
88114

89115
## Development
90116

91-
### Setup the Coding Environment
117+
### Build and run
92118

93-
Tested on Ubuntu and Windows.
119+
1. Install Node.js (v20 or newer) from <https://nodejs.org/en/download/>
120+
2. Install the dependencies and run the dev server:
121+
```
122+
cd precise
123+
npm install
124+
npm run dev
125+
```
94126

95-
1. Install node.js <https://nodejs.org/en/download/> at least v20
96-
2. Create an NPM enviroment using Vite: `npm create vite@latest`, pick *React*, then *Typescript*
97-
3. In the precise folder, install monaco `npm install @monaco-editor/react`
98-
4. Install Typescript Runtime for ANTLR4 `npm install antlr4ng` and the cli `npm install --save-dev antlr4ng-cli`
99-
because <https://github.com/tunnelvisionlabs/antlr4ts> seems abandoned?
127+
The local URL is displayed, and you can open it in your browser.
100128

101-
### Setup Proxying to Local Trino Instance
129+
### Set Up proxying to a local Trino instance
102130

103-
To run outside of Trino, update the contents of the `vite.config.ts` with the following so that queries can be properly proxied over to Trino's query endpoint running on `http://localhost:8080` or any other proxy path required.
131+
Update `vite.config.ts` with the following so that queries can be
132+
proxied to Trino's query endpoint running on `http://localhost:8080` (or any
133+
other path you require).
104134

105135
```tsx
106136
import { defineConfig } from 'vite'
@@ -119,24 +149,13 @@ export default defineConfig({
119149
},
120150
},
121151
},
152+
...
122153
});
123154
```
124155

125-
### Build and Run
126-
127-
To run, start:
128-
129-
```shell
130-
cd precise
131-
npm install
132-
npm run dev
133-
```
134-
135-
The local URL will be be displayed which you can open in your browser.
136-
137-
### Building the Parser
156+
### Building the parser
138157

139-
To build parser: `npm run antlr4ng`, as configured in **package.json**
158+
Run `npm run antlr4ng` to build the parser, as configured in **package.json**.
140159

141160
### Linting and code formatting
142161

@@ -146,37 +165,48 @@ To check code quality and formatting:
146165
npm run check
147166
```
148167

149-
This command runs both eslint and prettier, as defined in **package.json**
168+
This command runs both ESLint and Prettier, as defined in **package.json**.
150169

151170
## Philosophy
152171

153-
This UI's purpose is to provide an environment where once the cluster is stood up, executing queries and exploring data sets can be done right away. The idended use cases are:
172+
This UI's purpose is to provide an environment where, once the cluster is up,
173+
you can immediately execute queries and explore data sets. The intended use
174+
cases are:
154175
* Initial proof-of-concept queries.
155176
* Exploration of data sets.
156177
* Performance analysis.
157-
* Adhoc query execution.
158-
* Quickly enabling a data engineering team to start work before other integrations are in place.
178+
* Ad hoc query execution.
179+
* Quickly enabling a data engineering team to start work before other
180+
integrations are in place.
159181
* Early demos.
160182

161-
The approach taken:
162-
1. Direct integration into Trino UI
163-
- No need for additional authentication hop (although it could be added in the future)
164-
- Auth as the user executing the query if using Oauth2
183+
The approach:
184+
1. Direct integration into the Trino UI
185+
- No need for an additional authentication hop (although it could be added
186+
in the future)
187+
- Authenticates as the user executing the query when using OAuth2
165188
- Trino does the heavy lifting
166-
2. Don't need to think, just write a query
167-
- Autocomplete must be aware of not just Trino language but tables and columns
168-
- Syntax highlighting, validation
169-
- Comprehensive catalog explorer
170-
3. No black box query execution
171-
- Show progress and details of execution: people ask "why is my query slow" but mostly this is because they are only shown a spinner for 10 minutes.
172-
- Link to Trino query UI to drill into query performance
173-
- Show stages and split counts like Trino console client
174-
4. Easy to navigate
175-
176-
### Gaps and Future Direction
177-
178-
* The ability to save queries and use source control requires either back end capabilities in the Trino service or can utilize Trino to write queries as tables.
189+
2. Remove friction so you can simply write a query
190+
- Autocomplete understands the Trino language, tables, and columns
191+
- Provides syntax highlighting and validation
192+
- Offers a comprehensive catalog explorer
193+
3. Avoid black-box query execution
194+
- Show progress and execution details. People ask "why is my query slow?"
195+
mostly because they only see a spinner for minutes.
196+
- Link to the Trino Query UI to drill into query performance
197+
- Show stages and split counts like the Trino console client
198+
4. Keep the experience easy to navigate
199+
200+
### Gaps and future direction
201+
202+
* Saving queries and using source control require either backend capabilities
203+
in the Trino service or leveraging Trino to write queries as tables.
179204
* No autocomplete for the Trino function list.
180-
* Basic graphing capabilities - looking at a table is not enough even for inspecting data sets.
181-
* No LLM copilot integration yet, this is done badly in many query UIs and if done well could make query crafting very fast, and solve other issues like translation from other query languages.
182-
* Parameters and string replace: this is partly implemented in `SubstitutionEditor` and should support both SQL parameters and string replacement.
205+
* Basic graphing capabilities are still missing—looking at a table alone is
206+
not enough even for inspecting data sets.
207+
* No LLM copilot integration yet. Many query UIs implement this poorly, but,
208+
done well, it could make query crafting fast and help translate from other
209+
query languages.
210+
* Parameters and string replacement are only partly implemented in
211+
`SubstitutionEditor` and should support both SQL parameters and string
212+
replacement.

precise/.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

precise/eslint.config.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import js from '@eslint/js'
2+
import globals from 'globals';
3+
import tsParser from '@typescript-eslint/parser'
4+
import tsPlugin from '@typescript-eslint/eslint-plugin'
5+
import reactHooksPlugin from 'eslint-plugin-react-hooks';
6+
import reactRefreshPlugin from 'eslint-plugin-react-refresh';
7+
8+
export default [
9+
js.configs.recommended,
10+
{
11+
files: ['**/*.ts', '**/*.tsx'],
12+
languageOptions: {
13+
parser: tsParser,
14+
ecmaVersion: 'latest',
15+
sourceType: 'module',
16+
globals: {
17+
...globals.browser,
18+
process: 'readonly',
19+
React: 'readonly',
20+
},
21+
},
22+
plugins: {
23+
'@typescript-eslint': tsPlugin,
24+
},
25+
rules: {
26+
...tsPlugin.configs.recommended.rules,
27+
'@typescript-eslint/no-unused-expressions': [
28+
'error',
29+
{
30+
allowShortCircuit: true,
31+
allowTernary: true,
32+
},
33+
],
34+
'@typescript-eslint/no-explicit-any': 'off',
35+
'@typescript-eslint/no-unused-vars': 'off',
36+
},
37+
},
38+
{
39+
files: ['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx'],
40+
plugins: {
41+
'react-hooks': reactHooksPlugin,
42+
},
43+
rules: {
44+
...reactHooksPlugin.configs.recommended.rules,
45+
},
46+
},
47+
{
48+
files: ['**/*.{js,jsx,ts,tsx}'], // Match all JS/TS files
49+
plugins: {
50+
'react-refresh': reactRefreshPlugin,
51+
},
52+
rules: {
53+
'react-refresh/only-export-components': [
54+
'warn',
55+
{ allowConstantExport: true },
56+
],
57+
// Fix and enable separately
58+
// 'eol-last': ['warn', 'always'],
59+
// 'no-multiple-empty-lines': ['warn', { max: 1, maxEOF: 0 }],
60+
},
61+
},
62+
{
63+
files: ['src/utils/ProgressBar.tsx'],
64+
rules: {
65+
'@typescript-eslint/no-empty-object-type': 'off',
66+
},
67+
},
68+
{
69+
files: ['src/generated/**/*.ts'],
70+
linterOptions: {
71+
reportUnusedDisableDirectives: false,
72+
},
73+
},
74+
{
75+
ignores: ['dist', 'src/generated/**', '.eslintrc.cjs'],
76+
},
77+
];

precise/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8" />
55
<link rel="icon" type="image/png" href="/commander_bunbun.png" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>Trino Query Editor</title>
7+
<title>Trino Query Editor - Example app</title>
88
</head>
99
<body>
1010
<div id="root"></div>

precise/src/App.tsx

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)