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: editor awareness of default schemas #1422

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alexgann
Copy link

@alexgann alexgann commented Mar 9, 2024

Video Demo/Explanation of Feature: https://youtu.be/w0z4pU_E0bM

Issue

QueryBook QueryEditor is unaware of QueryEngine Connection URI's Default/Named database/schema

Resolution (see video for walkthrough):

Add simple get_default_schema method to QueryEngine python model to parse any provided default schema on the connection URI
Make this defaultSchema known to the front-end for Linting, Analysis, and AutoCompletion
Retain support for use statements and explicit schemas when needed, and no-op to implicit "default" schema name when not provided

@alexgann
Copy link
Author

alexgann commented Mar 9, 2024

@jczhong84 thanks again for taking a look!

Comment on lines +110 to +117
connection_string = self.executor_params.get("connection_string")
try:
connection_url = sql.engine.make_url(connection_string)
except Exception:
connection_url = None

if connection_url:
default_schema = connection_url.database or default_schema
Copy link
Collaborator

Choose a reason for hiding this comment

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

not all the connection strings have the database, I think it will be better to have a seprate executor param for the default schema.

Comment on lines +137 to +145
possible_schema = prefix.split(".")[0]
omit_schema = not active_schema.startswith(possible_schema)

query = construct_suggest_table_query(prefix, limit, metastore_id)
options = get_matching_suggestions(query, ES_CONFIG["tables"]["index_name"])
texts = [
"{}.{}".format(
option.get("_source", {}).get("schema", ""),
option.get("_source", {}).get("name", ""),
(
option.get("_source", {}).get("name", "")
if omit_schema and active_schema == option.get("_source", {}).get("schema", "")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure I'm following what this active_schema and this omit_schema is trying to do here. could you elaborate a bit?

@@ -807,6 +813,7 @@ export function findTableReferenceAndAlias(statements: IToken[][]) {
return {
references,
aliases,
activeSchema,
Copy link
Collaborator

Choose a reason for hiding this comment

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

looks like activeSchema is just the same as defaultSchema, you dont need to define a new variable, but just return the defaultSchema.

@@ -240,9 +240,12 @@ export class SqlAutoCompleter {
return [];
}

let omit_schema = this.codeAnalysis.lineage.activeSchema || 'default';
Copy link
Collaborator

Choose a reason for hiding this comment

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

const. also || default is not necessarily needed, as the API has the default value default for the 3rd parameter. could be just below

suggest(
            metastoreId,
            prefix,
            this.codeAnalysis.lineage.activeSchema)

@jczhong84
Copy link
Collaborator

@alexgann sorry for not looking it sooner. thanks for the demo and PR! this will be quite useful. left some comments

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.

None yet

2 participants