Skip to content

Commit

Permalink
DA#304: BugFix: Incorrect filter definition bug
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushTyagi1 committed Oct 5, 2023
1 parent fc675cf commit 5383d08
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
19 changes: 17 additions & 2 deletions src/commands/documents/filterDocuments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import CollectionNode from "../../model/CollectionNode";
import * as vscode from "vscode";
import { Memory } from "../../util/util";
import { IFilterDocuments } from "../../types/IFilterDocuments";
import { Commands } from "../extensionCommands/commands";
import { logger } from "../../logger/logger";
import { ParsingFailureError } from "couchbase";

export const filterDocuments = async (node: CollectionNode) => {
// Check if indexes are present for collection
Expand Down Expand Up @@ -32,7 +32,7 @@ export const filterDocuments = async (node: CollectionNode) => {
logger.error("Error checking primary index: " + err);
return false;
});
if(!primaryIndexExists){
if (!primaryIndexExists) {
return;
}

Expand Down Expand Up @@ -65,6 +65,21 @@ export const filterDocuments = async (node: CollectionNode) => {
if (newDocFilterStmt === undefined) {
return;
}
try {
if (newDocFilterStmt.trim() !== "") {
await node.connection.cluster?.query(`SELECT META().id FROM \`${node.bucketName}\`.\`${node.scopeName}\`.\`${collectionName}\` WHERE ${newDocFilterStmt}`);
}
} catch (err) {
if (err instanceof ParsingFailureError) {
vscode.window.showErrorMessage(
"Parsing Failed: Incorrect filter definition"
);
} else {
logger.error(err);
}
return;
}

const newDocFilter: IFilterDocuments = {
filter: newDocFilterStmt.trim(),
};
Expand Down
5 changes: 4 additions & 1 deletion src/model/CollectionNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import { INode } from "../types/INode";
import DocumentNode from "./DocumentNode";
import { PagerNode } from "./PagerNode";
import { abbreviateCount } from "../util/common";
import { PlanningFailureError } from "couchbase";
import { ParsingFailureError, PlanningFailureError } from "couchbase";
import InformationNode from "./InformationNode";
import { Memory } from "../util/util";
import { IFilterDocuments } from "../types/IFilterDocuments";
import { SchemaDirectory } from "./SchemaDirectory";
import { getActiveConnection } from "../util/connections";
import { Commands } from "../commands/extensionCommands/commands";
import { IndexDirectory } from "./IndexDirectory";
import { logger } from "../logger/logger";

export default class CollectionNode implements INode {
constructor(
Expand Down Expand Up @@ -130,6 +131,8 @@ export default class CollectionNode implements INode {
}
);
documentList.push(infoNode);
} else if (err instanceof ParsingFailureError) {
logger.error(`In Collection Node: ${this.collectionName}: Parsing Failed: Incorrect filter definition`);
}
}
result?.rows.forEach((documentName: string) => {
Expand Down
6 changes: 3 additions & 3 deletions src/model/ScopeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { IFilterDocuments } from "../types/IFilterDocuments";
import CollectionNode from "./CollectionNode";
import { logger } from "../logger/logger";
import InformationNode from "./InformationNode";
import { PlanningFailureError } from "couchbase";
import { ParsingFailureError, PlanningFailureError } from "couchbase";

export class ScopeNode implements INode {
constructor(
Expand Down Expand Up @@ -84,8 +84,8 @@ export class ScopeNode implements INode {
vscode.window.showErrorMessage(
"Unable to find primary index for document and filter seems to be applied, showing count as 0"
);
} else {
throw new Error(err);
} else if (err instanceof ParsingFailureError) {
logger.error(`In Scope Node: ${this.scopeName}: Parsing Failed: Incorrect filter definition`);
}
}

Expand Down

0 comments on commit 5383d08

Please sign in to comment.