@@ -26,6 +26,7 @@ import {
2626import { telemetryListener } from "../common/vscode/telemetry" ;
2727import { redactableError } from "../common/errors" ;
2828import { App } from "../common/app" ;
29+ import { findResultSetNames } from "./result-set-names" ;
2930
3031interface ComparePair {
3132 from : CompletedLocalQueryInfo ;
@@ -170,53 +171,33 @@ export class CompareView extends AbstractWebview<
170171 to : CompletedLocalQueryInfo ,
171172 selectedResultSetName : string | undefined ,
172173 ) : Promise < [ string [ ] , string , RawResultSet , RawResultSet ] > {
173- const fromSchemas = await this . cliServer . bqrsInfo (
174- from . completedQuery . query . resultsPaths . resultsPath ,
175- ) ;
176- const toSchemas = await this . cliServer . bqrsInfo (
177- to . completedQuery . query . resultsPaths . resultsPath ,
178- ) ;
179- const fromSchemaNames = fromSchemas [ "result-sets" ] . map (
180- ( schema ) => schema . name ,
181- ) ;
182- const toSchemaNames = toSchemas [ "result-sets" ] . map ( ( schema ) => schema . name ) ;
183- const commonResultSetNames = fromSchemaNames . filter ( ( name ) =>
184- toSchemaNames . includes ( name ) ,
185- ) ;
186-
187- // Fall back on the default result set names if there are no common ones.
188- const defaultFromResultSetName = fromSchemaNames . find ( ( name ) =>
189- name . startsWith ( "#" ) ,
190- ) ;
191- const defaultToResultSetName = toSchemaNames . find ( ( name ) =>
192- name . startsWith ( "#" ) ,
174+ const {
175+ commonResultSetNames,
176+ currentResultSetDisplayName,
177+ fromSchemas,
178+ fromResultSetName,
179+ toSchemas,
180+ toResultSetName,
181+ } = await findResultSetNames (
182+ this . cliServer ,
183+ from ,
184+ to ,
185+ selectedResultSetName ,
193186 ) ;
194187
195- if (
196- commonResultSetNames . length === 0 &&
197- ! ( defaultFromResultSetName || defaultToResultSetName )
198- ) {
199- throw new Error (
200- "No common result sets found between the two queries. Please check that the queries are compatible." ,
201- ) ;
202- }
203-
204- const currentResultSetName =
205- selectedResultSetName || commonResultSetNames [ 0 ] ;
206188 const fromResultSet = await this . getResultSet (
207189 fromSchemas ,
208- currentResultSetName || defaultFromResultSetName ! ,
190+ fromResultSetName ,
209191 from . completedQuery . query . resultsPaths . resultsPath ,
210192 ) ;
211193 const toResultSet = await this . getResultSet (
212194 toSchemas ,
213- currentResultSetName || defaultToResultSetName ! ,
195+ toResultSetName ,
214196 to . completedQuery . query . resultsPaths . resultsPath ,
215197 ) ;
216198 return [
217199 commonResultSetNames ,
218- currentResultSetName ||
219- `${ defaultFromResultSetName } <-> ${ defaultToResultSetName } ` ,
200+ currentResultSetDisplayName ,
220201 fromResultSet ,
221202 toResultSet ,
222203 ] ;
0 commit comments