Skip to content

Commit dea8a93

Browse files
AdiGajbhiyemdesmet
andauthored
fix: handle source node (#721)
Co-authored-by: Michiel De Smet <[email protected]>
1 parent b51cac5 commit dea8a93

File tree

6 files changed

+268
-74
lines changed

6 files changed

+268
-74
lines changed

new_lineage_panel/src/TableDetails.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const ColumnSection: FunctionComponent<{
130130
if (!selectedTable) {
131131
return;
132132
}
133-
getColumns(selectedTable.table, true).then((_data) => {
133+
getColumns(selectedTable, true).then((_data) => {
134134
setData(_data);
135135
setFilteredColumn(_data.columns);
136136
});
@@ -233,7 +233,7 @@ const TableDetails = () => {
233233
if (!selectedTable) {
234234
return;
235235
}
236-
getColumns(selectedTable.table, false).then((_data) => {
236+
getColumns(selectedTable, false).then((_data) => {
237237
setData(_data);
238238
setFilteredColumn(_data.columns);
239239
setIsLoading(false);

new_lineage_panel/src/service.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,15 @@ export const downstreamTables = (tableKey: string) => {
4545
}>;
4646
};
4747

48-
export const getColumns = (table: string, refresh: boolean) => {
49-
return requestExecutor("getColumns", { table, refresh }) as Promise<
48+
export const getColumns = (
49+
{ key, nodeType }: { key: string; nodeType: string },
50+
refresh: boolean,
51+
) => {
52+
return requestExecutor("getColumns", {
53+
tableKey: key,
54+
refresh,
55+
nodeType,
56+
}) as Promise<
5057
Columns
5158
>;
5259
};

src/manifest/dbtProject.ts

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ export class DBTProject implements Disposable {
570570
return yamlString;
571571
}
572572

573-
async getColumnsInRelation(
573+
async getColumnsOfModel(
574574
modelName: string,
575575
): Promise<{ [key: string]: string }[]> {
576576
await this.blockUntilPythonBridgeIsInitalized();
@@ -585,18 +585,59 @@ export class DBTProject implements Disposable {
585585
return [];
586586
}
587587
// Get database and schema
588-
const refNode = (await this.python?.lock(
588+
const node = (await this.python?.lock(
589589
(python) => python!`to_dict(project.get_ref_node(${modelName}))`,
590590
)) as ResolveReferenceResult;
591591
// Get columns
592-
if (!refNode) {
592+
if (!node) {
593593
return [];
594594
}
595+
return this.getColumsOfRelation(
596+
node.database,
597+
node.schema,
598+
node.alias || modelName,
599+
);
600+
}
601+
602+
async getColumnsOfSource(
603+
sourceName: string,
604+
tableName: string,
605+
): Promise<{ [key: string]: string }[]> {
606+
await this.blockUntilPythonBridgeIsInitalized();
607+
if (!this.pythonBridgeInitialized) {
608+
window.showErrorMessage(
609+
"Could not execute query, because the Python bridge has not been initalized. If the issue persists, please open a Github issue.",
610+
);
611+
this.telemetry.sendTelemetryError(
612+
"getColumnsInRelationPythonBridgeNotInitializedError",
613+
);
614+
// TODO: improve this, the errors should be captured at a higher level
615+
return [];
616+
}
617+
// Get database and schema
618+
const node = (await this.python?.lock(
619+
(python) =>
620+
python!`to_dict(project.get_source_node(${sourceName}, ${tableName}))`,
621+
)) as ResolveReferenceResult;
622+
// Get columns
623+
if (!node) {
624+
return [];
625+
}
626+
return this.getColumsOfRelation(
627+
node.database,
628+
node.schema,
629+
node.alias || tableName,
630+
);
631+
}
632+
633+
async getColumsOfRelation(
634+
database: string | undefined,
635+
schema: string | undefined,
636+
objectName: string,
637+
) {
595638
return await this.python?.lock(
596639
(python) =>
597-
python!`to_dict(project.get_columns_in_relation(project.create_relation(${
598-
refNode.database
599-
}, ${refNode.schema}, ${refNode.alias || modelName})))`,
640+
python!`to_dict(project.get_columns_in_relation(project.create_relation(${database}, ${schema}, ${objectName})))`,
600641
);
601642
}
602643

@@ -664,7 +705,7 @@ export class DBTProject implements Disposable {
664705
this.telemetry.sendTelemetryEvent("generateSchemaYML", {
665706
adapter: this.adapterType,
666707
});
667-
const columnsInRelation = await this.getColumnsInRelation(modelName);
708+
const columnsInRelation = await this.getColumnsOfModel(modelName);
668709
// Generate yml file content
669710
const fileContents = this.createYMLContent(
670711
columnsInRelation,

src/manifest/dbtProjectContainer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export class DBTProjectContainer implements Disposable {
134134
);
135135
if (answer === PromptAnswer.YES) {
136136
commands.executeCommand("dbtPowerUser.openSetupWalkthrough");
137-
}
137+
}
138138
this.setToGlobalState("showSetupWalkthrough", false);
139139
}
140140

src/webview_provider/docsEditPanel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export class DocsEditViewPanel implements WebviewViewProvider {
261261
const modelName = path.basename(currentFilePath.fsPath, ".sql");
262262
try {
263263
const columnsInRelation =
264-
await project.getColumnsInRelation(modelName);
264+
await project.getColumnsOfModel(modelName);
265265
const columns = columnsInRelation.map((column) => {
266266
return {
267267
name: column.column,

0 commit comments

Comments
 (0)