Skip to content
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

feat: auto add quotes for table/columns #1109

Merged
merged 4 commits into from
Dec 22, 2022
Merged

feat: auto add quotes for table/columns #1109

merged 4 commits into from
Dec 22, 2022

Conversation

czgu
Copy link
Collaborator

@czgu czgu commented Dec 21, 2022

If a column is like "foo/bar" then querybook would auto add quotes around the column names, similarly for tables.

For Presto
image

For MySQL
image

also 2 bug fixes:

  • If column name has upper case, still match prefix
  • make sure getSQLHint always goes to the latest language type

@czgu czgu marked this pull request as ready for review December 22, 2022 00:19
@@ -559,13 +559,11 @@ export const QueryEditor: React.FC<

const handleOnFocus = useCallback(
(editor: CodeMirror.Editor, event) => {
autoCompleter.registerHelper();
Copy link
Collaborator

Choose a reason for hiding this comment

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

why it's not needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

actually it is needed, otherwise query hint wouldn't work. I changed back the code and added more comments

@@ -233,7 +257,7 @@ export class SqlAutoCompleter {
(id) => dataSources.dataColumnsById[id].name
);
const filteredColumnNames = columnNames.filter((name) =>
name.startsWith(prefix)
name.toLowerCase().startsWith(prefix)
Copy link
Collaborator

Choose a reason for hiding this comment

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

is prefix also lowercased?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, in this line

searchStr = token.string.toLowerCase();

Comment on lines +316 to +318
const schemaTableNames = tableName.split('.');

if (schemaTableNames.length === 2) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like I saw this similar code piece multiple times, might be good to have tiny util function for it? can return an object with parsed schema name and table name, so that

const {schemaName, tableName} = parseFullTableName(..)
if (schemaName && tableName) {
   ...
   this.flatQuotationFormatter(tableName)
   ...
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmm it is just .split('.') and used in 2 places, i think we can make a function for it if it is more common in future

} else if (
lineAnalysis.context === 'column' &&
lineAnalysis.reference
) {
results = this.getColumnsFromPrefix(
searchStr,
lineAnalysis.reference
).map(formatter.bind(null, lineAnalysis.context));
)
.map(this.flatQuotationFormatter)
Copy link
Collaborator

Choose a reason for hiding this comment

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

how about just move this .map(this.flatQuotationFormatter) into getColumnsFromPrefix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i moved all of the quotation formatting logic to the formatter level so it would not interfere with display

@czgu czgu merged commit d2c1f09 into pinterest:master Dec 22, 2022
@czgu czgu deleted the quotes branch December 22, 2022 19:07
rohan-sh1 pushed a commit to CAI-TECHNOLOGIES/cai-ext-db-explorer that referenced this pull request Feb 28, 2023
* feat: auto add quotes for table/columns

* fix wrong sql hint being registered

* update according to comments

* remove autocompleter from hooks ret
aidenprice pushed a commit to arrowtail-precision/querybook that referenced this pull request Jan 3, 2024
* feat: auto add quotes for table/columns

* fix wrong sql hint being registered

* update according to comments

* remove autocompleter from hooks ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants