Skip to content

Commit

Permalink
[Feature] Add Support for SQL Formatting in Query Editor (#11725)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnavBalyan authored Feb 24, 2024
1 parent 55cecc1 commit c8060c1
Show file tree
Hide file tree
Showing 4 changed files with 14,062 additions and 32 deletions.
6 changes: 6 additions & 0 deletions pinot-controller/package-lock.json

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

38 changes: 31 additions & 7 deletions pinot-controller/src/main/resources/app/pages/Query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import PinotMethodUtils from '../utils/PinotMethodUtils';
import '../styles/styles.css';
import {Resizable} from "re-resizable";
import { useHistory, useLocation } from 'react-router';
import sqlFormatter from '@sqltools/formatter';

const useStyles = makeStyles((theme) => ({
title: {
Expand Down Expand Up @@ -78,7 +79,15 @@ const useStyles = makeStyles((theme) => ({
},
runNowBtn: {
marginLeft: 'auto',
paddingLeft: '74px',
paddingLeft: '10px',
},
formatSQLBtn: {
marginLeft: 'auto',
paddingLeft: '30px',
},
formatMSE: {
marginLeft: '-30px',
paddingLeft: 'auto',
},
sqlDiv: {
height: '100%',
Expand Down Expand Up @@ -271,6 +280,11 @@ const QueryPage = () => {
setInputQuery(querySplit.join("\n"));
}

const handleFormatSQL = (query?: string) => {
const formatted = sqlFormatter.format(query);
setInputQuery(formatted);
};

const handleRunNow = async (query?: string) => {
setQueryLoader(true);
queryExecuted.current = true;
Expand Down Expand Up @@ -503,7 +517,7 @@ const QueryPage = () => {
Tracing
</Grid>

<Grid item xs={3}>
<Grid item xs={3} className={classes.formatMSE}>
<Checkbox
name="useMSE"
color="primary"
Expand All @@ -515,16 +529,26 @@ const QueryPage = () => {

<Grid item xs={3}>
<FormControl fullWidth={true} className={classes.timeoutControl}>
<InputLabel htmlFor="my-input">Timeout (in Milliseconds)</InputLabel>
<InputLabel htmlFor="my-input">Timeout (Milliseconds)</InputLabel>
<Input id="my-input" type="number" value={queryTimeout} onChange={(e)=> setQueryTimeout(Number(e.target.value) || '')}/>
</FormControl>
</Grid>

<Grid item xs={3} className={classes.runNowBtn}>
<Grid item xs={2} className={classes.formatSQLBtn}>
<Button
variant="contained"
color="primary"
onClick={() => handleRunNow()}
variant="contained"
color="primary"
onClick={() => handleFormatSQL(inputQuery)}
>
Format SQL
</Button>
</Grid>

<Grid item xs={2} className={classes.runNowBtn}>
<Button
variant="contained"
color="primary"
onClick={() => handleRunNow()}
>
Run Query
</Button>
Expand Down
Loading

0 comments on commit c8060c1

Please sign in to comment.