11import { ViewColumn } from "vscode" ;
22
33import {
4+ ALERTS_TABLE_NAME ,
45 FromCompareViewMessage ,
6+ InterpretedQueryCompareResult ,
7+ QueryCompareResult ,
58 RawQueryCompareResult ,
69 ToCompareViewMessage ,
710} from "../common/interface-types" ;
@@ -25,15 +28,18 @@ import { App } from "../common/app";
2528import { bqrsToResultSet } from "../common/bqrs-raw-results-mapper" ;
2629import { RawResultSet } from "../common/raw-result-types" ;
2730import {
31+ CompareQueryInfo ,
2832 findCommonResultSetNames ,
2933 findResultSetNames ,
34+ getResultSetNames ,
3035} from "./result-set-names" ;
36+ import { compareInterpretedResults } from "./interpreted-results" ;
3137
3238interface ComparePair {
3339 from : CompletedLocalQueryInfo ;
34- fromSchemas : BqrsInfo ;
40+ fromInfo : CompareQueryInfo ;
3541 to : CompletedLocalQueryInfo ;
36- toSchemas : BqrsInfo ;
42+ toInfo : CompareQueryInfo ;
3743
3844 commonResultSetNames : readonly string [ ] ;
3945}
@@ -62,23 +68,48 @@ export class CompareView extends AbstractWebview<
6268 to : CompletedLocalQueryInfo ,
6369 selectedResultSetName ?: string ,
6470 ) {
65- const fromSchemas = await this . cliServer . bqrsInfo (
66- from . completedQuery . query . resultsPaths . resultsPath ,
67- ) ;
68- const toSchemas = await this . cliServer . bqrsInfo (
69- to . completedQuery . query . resultsPaths . resultsPath ,
70- ) ;
71+ const [ fromSchemas , toSchemas ] = await Promise . all ( [
72+ this . cliServer . bqrsInfo (
73+ from . completedQuery . query . resultsPaths . resultsPath ,
74+ ) ,
75+ this . cliServer . bqrsInfo ( to . completedQuery . query . resultsPaths . resultsPath ) ,
76+ ] ) ;
7177
72- const commonResultSetNames = await findCommonResultSetNames (
73- fromSchemas ,
74- toSchemas ,
78+ const [ fromSchemaNames , toSchemaNames ] = await Promise . all ( [
79+ getResultSetNames (
80+ fromSchemas ,
81+ from . completedQuery . query . metadata ,
82+ from . completedQuery . query . resultsPaths . interpretedResultsPath ,
83+ ) ,
84+ getResultSetNames (
85+ toSchemas ,
86+ to . completedQuery . query . metadata ,
87+ to . completedQuery . query . resultsPaths . interpretedResultsPath ,
88+ ) ,
89+ ] ) ;
90+
91+ const commonResultSetNames = findCommonResultSetNames (
92+ fromSchemaNames ,
93+ toSchemaNames ,
7594 ) ;
7695
7796 this . comparePair = {
7897 from,
79- fromSchemas,
98+ fromInfo : {
99+ schemas : fromSchemas ,
100+ schemaNames : fromSchemaNames ,
101+ metadata : from . completedQuery . query . metadata ,
102+ interpretedResultsPath :
103+ from . completedQuery . query . resultsPaths . interpretedResultsPath ,
104+ } ,
80105 to,
81- toSchemas,
106+ toInfo : {
107+ schemas : toSchemas ,
108+ schemaNames : toSchemaNames ,
109+ metadata : to . completedQuery . query . metadata ,
110+ interpretedResultsPath :
111+ to . completedQuery . query . resultsPaths . interpretedResultsPath ,
112+ } ,
82113 commonResultSetNames,
83114 } ;
84115
@@ -119,16 +150,28 @@ export class CompareView extends AbstractWebview<
119150 panel . reveal ( undefined , true ) ;
120151
121152 await this . waitForPanelLoaded ( ) ;
122- const { currentResultSetDisplayName, fromResultSet, toResultSet } =
123- await this . findResultSetsToCompare (
124- this . comparePair ,
125- selectedResultSetName ,
126- ) ;
153+ const {
154+ currentResultSetName,
155+ currentResultSetDisplayName,
156+ fromResultSetName,
157+ toResultSetName,
158+ } = await this . findResultSetsToCompare (
159+ this . comparePair ,
160+ selectedResultSetName ,
161+ ) ;
127162 if ( currentResultSetDisplayName ) {
128- let result : RawQueryCompareResult | undefined ;
163+ let result : QueryCompareResult | undefined ;
129164 let message : string | undefined ;
130165 try {
131- result = this . compareResults ( fromResultSet , toResultSet ) ;
166+ if ( currentResultSetName === ALERTS_TABLE_NAME ) {
167+ result = await this . compareInterpretedResults ( this . comparePair ) ;
168+ } else {
169+ result = await this . compareResults (
170+ this . comparePair ,
171+ fromResultSetName ,
172+ toResultSetName ,
173+ ) ;
174+ }
132175 } catch ( e ) {
133176 message = getErrorMessage ( e ) ;
134177 }
@@ -205,31 +248,27 @@ export class CompareView extends AbstractWebview<
205248 }
206249
207250 private async findResultSetsToCompare (
208- { from , fromSchemas , to , toSchemas , commonResultSetNames } : ComparePair ,
251+ { fromInfo , toInfo , commonResultSetNames } : ComparePair ,
209252 selectedResultSetName : string | undefined ,
210253 ) {
211- const { currentResultSetDisplayName, fromResultSetName, toResultSetName } =
212- await findResultSetNames (
213- fromSchemas ,
214- toSchemas ,
215- commonResultSetNames ,
216- selectedResultSetName ,
217- ) ;
218-
219- const fromResultSet = await this . getResultSet (
220- fromSchemas ,
254+ const {
255+ currentResultSetName,
256+ currentResultSetDisplayName,
221257 fromResultSetName,
222- from . completedQuery . query . resultsPaths . resultsPath ,
223- ) ;
224- const toResultSet = await this . getResultSet (
225- toSchemas ,
226258 toResultSetName,
227- to . completedQuery . query . resultsPaths . resultsPath ,
259+ } = await findResultSetNames (
260+ fromInfo ,
261+ toInfo ,
262+ commonResultSetNames ,
263+ selectedResultSetName ,
228264 ) ;
265+
229266 return {
267+ commonResultSetNames,
268+ currentResultSetName,
230269 currentResultSetDisplayName,
231- fromResultSet ,
232- toResultSet ,
270+ fromResultSetName ,
271+ toResultSetName ,
233272 } ;
234273 }
235274
@@ -252,12 +291,37 @@ export class CompareView extends AbstractWebview<
252291 return bqrsToResultSet ( schema , chunk ) ;
253292 }
254293
255- private compareResults (
256- fromResults : RawResultSet ,
257- toResults : RawResultSet ,
258- ) : RawQueryCompareResult {
259- // Only compare columns that have the same name
260- return resultsDiff ( fromResults , toResults ) ;
294+ private async compareResults (
295+ { from, fromInfo, to, toInfo } : ComparePair ,
296+ fromResultSetName : string ,
297+ toResultSetName : string ,
298+ ) : Promise < RawQueryCompareResult > {
299+ const [ fromResultSet , toResultSet ] = await Promise . all ( [
300+ this . getResultSet (
301+ fromInfo . schemas ,
302+ fromResultSetName ,
303+ from . completedQuery . query . resultsPaths . resultsPath ,
304+ ) ,
305+ this . getResultSet (
306+ toInfo . schemas ,
307+ toResultSetName ,
308+ to . completedQuery . query . resultsPaths . resultsPath ,
309+ ) ,
310+ ] ) ;
311+
312+ return resultsDiff ( fromResultSet , toResultSet ) ;
313+ }
314+
315+ private async compareInterpretedResults ( {
316+ from,
317+ to,
318+ } : ComparePair ) : Promise < InterpretedQueryCompareResult > {
319+ return compareInterpretedResults (
320+ this . databaseManager ,
321+ this . cliServer ,
322+ from ,
323+ to ,
324+ ) ;
261325 }
262326
263327 private async openQuery ( kind : "from" | "to" ) {
0 commit comments