Skip to content

Commit

Permalink
Merge branch 'master' into feat/query-panel-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
saravmajestic authored May 16, 2024
2 parents 320378d + df0d780 commit 45e2455
Show file tree
Hide file tree
Showing 25 changed files with 532 additions and 189 deletions.
74 changes: 37 additions & 37 deletions package-lock.json

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

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@
{
"title": "dbt Power User",
"properties": {
"dbt.unquotedCaseInsensitiveIdentifierRegex": {
"type": "string",
"markdownDescription": "Regex to identify unquoted identifiers. Example: `^([_A-Z]+[_A-Z0-9$]*)$`"
},
"dbt.dbtIntegration": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -1147,7 +1151,7 @@
"eslint-config-prettier": "^8.9.0",
"eslint-plugin-prettier": "^5.0.1",
"file-loader": "^6.1.0",
"glob": "^10.3.10",
"glob": "^10.3.15",
"husky": "^9.0.11",
"lint-staged": "^14.0.1",
"mocha": "^10.3.0",
Expand Down
13 changes: 7 additions & 6 deletions src/commands/tests/staleModelColumnTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Diagnostic, DiagnosticSeverity, Range, Uri } from "vscode";
import { ScanContext } from "./scanContext";
import { AltimateScanStep } from "./step";
import { readFileSync } from "fs";
import { provideSingleton } from "../../utils";
import { getColumnNameByCase, provideSingleton } from "../../utils";
import { createFullPathForNode } from "../../manifest/parsers";

@provideSingleton(StaleModelColumnTest)
Expand Down Expand Up @@ -84,11 +84,8 @@ export class StaleModelColumnTest implements AltimateScanStep {
// do model-level checks here.
const modelDict =
altimateCatalog[projectName + projectRootUri][modelKey];
const existingColumnsLowered = Object.keys(value.columns).map((key) =>
key.toLowerCase(),
);
const allDBColumns = modelDict.map(({ column_name }) =>
column_name.toLowerCase(),
getColumnNameByCase(column_name, project.getAdapterType()),
);
const packagePath = project.getPackageInstallPath();
if (packagePath === undefined) {
Expand All @@ -97,7 +94,11 @@ export class StaleModelColumnTest implements AltimateScanStep {
);
}
for (const existingCol of Object.keys(value.columns)) {
if (!allDBColumns.includes(existingCol.toLowerCase())) {
if (
!allDBColumns.includes(
getColumnNameByCase(existingCol, project.getAdapterType()),
)
) {
const errMessage = `Column ${existingCol} listed in model ${value.name} is not found in the database.
It may be outdated or misspelled.`;
// If we are here, the patch_path is guaranteed to be defined since
Expand Down
8 changes: 5 additions & 3 deletions src/commands/tests/undocumentedModelColumnTest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Diagnostic, DiagnosticSeverity, Range } from "vscode";
import { ScanContext } from "./scanContext";
import { AltimateScanStep } from "./step";
import { provideSingleton } from "../../utils";
import { getColumnNameByCase, provideSingleton } from "../../utils";

@provideSingleton(UndocumentedModelColumnTest)
export class UndocumentedModelColumnTest implements AltimateScanStep {
Expand Down Expand Up @@ -47,11 +47,13 @@ export class UndocumentedModelColumnTest implements AltimateScanStep {
const modelDict =
altimateCatalog[projectName + projectRootUri][modelKey];
const existingColumnsLowered = Object.keys(value.columns).map((key) =>
key.toLowerCase(),
getColumnNameByCase(key, project.getAdapterType()),
);
for (const column of modelDict) {
if (
!existingColumnsLowered.includes(column.column_name.toLowerCase())
!existingColumnsLowered.includes(
getColumnNameByCase(column.column_name, project.getAdapterType()),
)
) {
const errMessage = `Column ${column.column_name} is undocumented in model: ${value.name}`;

Expand Down
21 changes: 20 additions & 1 deletion src/content_provider/sqlPreviewContentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import {
import { DBTProjectContainer } from "../manifest/dbtProjectContainer";
import { debounce, provideSingleton } from "../utils";
import { TelemetryService } from "../telemetry";
import { DeferToProdService } from "../services/deferToProdService";
import { AltimateRequest } from "../altimate";
import { ManifestPathType } from "../constants";

@provideSingleton(SqlPreviewContentProvider)
export class SqlPreviewContentProvider
Expand All @@ -28,6 +31,8 @@ export class SqlPreviewContentProvider

constructor(
private dbtProjectContainer: DBTProjectContainer,
private deferToProdService: DeferToProdService,
private altimateRequest: AltimateRequest,
private telemetry: TelemetryService,
) {
this.subscriptions = workspace.onDidCloseTextDocument((compilationDoc) =>
Expand Down Expand Up @@ -81,7 +86,21 @@ export class SqlPreviewContentProvider
}
this.telemetry.sendTelemetryEvent("requestCompilation");
await project.refreshProjectConfig();
return await project.unsafeCompileQuery(query);
const result = await project.unsafeCompileQuery(query);
const { manifestPathType } =
this.deferToProdService.getDeferConfigByProjectRoot(
project.projectRoot.fsPath,
);
const dbtIntegrationMode = workspace
.getConfiguration("dbt")
.get<string>("dbtIntegration", "core");
if (
dbtIntegrationMode === "core" &&
manifestPathType === ManifestPathType.REMOTE
) {
this.altimateRequest.sendDeferToProdEvent(ManifestPathType.REMOTE);
}
return result;
} catch (error: any) {
const errorMessage = (error as Error).message;
window.showErrorMessage(`Error while compiling: ${errorMessage}`);
Expand Down
7 changes: 7 additions & 0 deletions src/dbt_client/dbtCoreIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,13 @@ export class DBTCoreProjectIntegration
result = await queryThread!.lock<ExecuteSQLResult>(
(python) => python`to_dict(project.execute_sql(${compiledQuery}))`,
);
const { manifestPathType } =
this.deferToProdService.getDeferConfigByProjectRoot(
this.projectRoot.fsPath,
);
if (manifestPathType === ManifestPathType.REMOTE) {
this.altimateRequest.sendDeferToProdEvent(ManifestPathType.REMOTE);
}
} catch (err) {
const message = `Error while executing sql: ${compiledQuery}`;
this.dbtTerminal.error("dbtCore:executeSQL", message, err);
Expand Down
2 changes: 1 addition & 1 deletion src/hover_provider/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function generateHoverMarkdownString(
);
if (column.data_type !== null) {
content.appendMarkdown(
`<span>-&nbsp;${column.data_type.toUpperCase()}</span>`,
`<span>-&nbsp;${column.data_type.toLowerCase()}</span>`,
);
}
if (column.description !== "") {
Expand Down
21 changes: 14 additions & 7 deletions src/manifest/dbtProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { DBTTerminal } from "../dbt_client/dbtTerminal";
import {
debounce,
extendErrorWithSupportLinks,
getColumnNameByCase,
setupWatcherHandler,
} from "../utils";
import {
Expand Down Expand Up @@ -1006,20 +1007,26 @@ select * from renamed
// Flagging events where more than 100 columns are fetched from db to get a sense of how many of these happen
this.telemetry.sendTelemetryEvent("excessiveColumnsFetchedFromDB");
}
const columns: Record<string, ColumnMetaData> = {};
const columnsFromManifest: Record<string, ColumnMetaData> = {};
Object.entries(node.columns).forEach(([k, v]) => {
columns[k.toLowerCase()] = v;
columnsFromManifest[getColumnNameByCase(k, this.getAdapterType())] = v;
});

for (const c of columnsFromDB) {
const existing_column = columns[c.column.toLowerCase()];
const columnNameFromDB = getColumnNameByCase(
c.column,
this.getAdapterType(),
);
const existing_column = columnsFromManifest[columnNameFromDB];
if (existing_column) {
existing_column.data_type = existing_column.data_type || c.dtype;
existing_column.data_type = (
existing_column.data_type || c.dtype
)?.toLowerCase();
continue;
}
node.columns[c.column] = {
name: c.column,
data_type: c.dtype,
node.columns[columnNameFromDB] = {
name: columnNameFromDB,
data_type: c.dtype?.toLowerCase(),
description: "",
};
}
Expand Down
10 changes: 6 additions & 4 deletions src/services/dbtTestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
CreateDbtTestRequest,
UserInputError,
} from "../altimate";
import { provideSingleton } from "../utils";
import { isColumnNameEqual, provideSingleton } from "../utils";
import { DocGenService } from "./docGenService";
import { StreamingService } from "./streamingService";
import { QueryManifestService } from "./queryManifestService";
Expand Down Expand Up @@ -85,7 +85,7 @@ export class DbtTestService {
public getConfigByTest(
test: TestMetaData,
modelName: string,
column_name?: string,
columnNameFromTestMetadata?: string,
) {
const eventResult = this.queryManifestService.getEventByCurrentProject();
if (!eventResult?.event) {
Expand Down Expand Up @@ -133,7 +133,7 @@ export class DbtTestService {
const model = parsedDocFile.models?.find((m: any) => m.name === modelName);

// model test
if (!column_name) {
if (!columnNameFromTestMetadata) {
this.dbtTerminal.debug(
"getDbtTestCode",
"finding model test from yml",
Expand All @@ -145,7 +145,9 @@ export class DbtTestService {

const column =
model.columns &&
model.columns.find((yamlColumn: any) => yamlColumn.name === column_name);
model.columns.find((yamlColumn: any) =>
isColumnNameEqual(yamlColumn.name, columnNameFromTestMetadata),
);
this.dbtTerminal.debug(
"getDbtTestCode",
"finding column test from yml",
Expand Down
Loading

0 comments on commit 45e2455

Please sign in to comment.