-
Notifications
You must be signed in to change notification settings - Fork 222
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,19 @@ class QueryEngine(CRUDMixin, Base): | |
), | ||
) | ||
|
||
def get_default_schema(self): | ||
default_schema = "default" | ||
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 | ||
Comment on lines
+110
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
return default_schema | ||
|
||
def to_dict(self): | ||
# IMPORTANT: do not expose executor params unless it is for admin | ||
return { | ||
|
@@ -115,6 +128,7 @@ def to_dict(self): | |
"metastore_id": self.metastore_id, | ||
"feature_params": self.get_feature_params(), | ||
"executor": self.executor, | ||
"default_schema": self.get_default_schema(), | ||
} | ||
|
||
def to_dict_admin(self): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,9 +240,12 @@ export class SqlAutoCompleter { | |
return []; | ||
} | ||
|
||
let omit_schema = this.codeAnalysis.lineage.activeSchema || 'default'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
const { data: names } = await SearchTableResource.suggest( | ||
metastoreId, | ||
prefix | ||
prefix, | ||
omit_schema | ||
); | ||
return names; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,7 @@ const contextSensitiveKeyWord = { | |
table: 'table', | ||
update: 'table', | ||
join: 'table', | ||
on: 'column', | ||
set: 'column', | ||
|
||
desc: 'table', | ||
|
@@ -183,6 +184,7 @@ export interface ILinterWarning extends IRange { | |
export interface ILineage { | ||
references: Record<number, TableToken[]>; | ||
aliases: Record<number, Record<string, TableToken>>; | ||
activeSchema: string; | ||
} | ||
|
||
export interface ICodeAnalysis { | ||
|
@@ -646,10 +648,13 @@ export function findWithStatementPlaceholder(statement: IToken[]) { | |
return placeholders; | ||
} | ||
|
||
export function findTableReferenceAndAlias(statements: IToken[][]) { | ||
let defaultSchema = 'default'; | ||
export function findTableReferenceAndAlias( | ||
statements: IToken[][], | ||
defaultSchema: string = 'default' | ||
) { | ||
const references: Record<number, TableToken[]> = {}; | ||
const aliases: Record<number, Record<string, TableToken>> = {}; | ||
let activeSchema = defaultSchema; | ||
|
||
statements.forEach((statement, statementNum) => { | ||
if (statement.length === 0) { | ||
|
@@ -679,6 +684,7 @@ export function findTableReferenceAndAlias(statements: IToken[][]) { | |
const secondToken = statement[tokenCounter++]; | ||
if (secondToken && secondToken.type === 'VARIABLE') { | ||
defaultSchema = secondToken.text; | ||
activeSchema = defaultSchema; | ||
} | ||
} else { | ||
const placeholders: Set<string> = new Set( | ||
|
@@ -807,6 +813,7 @@ export function findTableReferenceAndAlias(statements: IToken[][]) { | |
return { | ||
references, | ||
aliases, | ||
activeSchema, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like |
||
}; | ||
} | ||
|
||
|
There was a problem hiding this comment.
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?