import { isFieldQuery } from 'compassql/build/src/query/encoding' ; import { Query } from 'compassql/build/src/query/query' ; import { QueryCreator } from './base' ; import { makeWildcard } from './common' ; export const summaries = { type : 'summaries' , title : 'Related Summaries' , filterSpecifiedView : true , createQuery ( query ) { const { spec } = query ; const newSpec = { ... spec , mark : makeWildcard ( spec . mark ) , encodings : spec . encodings . reduce ( ( encodings , encQ ) => { if ( isFieldQuery ( encQ ) ) { switch ( encQ . type ) { case 'quantitative' : if ( encQ . aggregate === 'count' ) { return encodings ; } else { return encodings . concat ( { ... encQ , aggregate : makeWildcard ( encQ . aggregate ) , bin : makeWildcard ( encQ . bin as any ) , hasFn : true } ) ; } case 'temporal' : return encodings . concat ( { ... encQ , timeUnit : makeWildcard ( encQ . timeUnit ) } ) ; case 'nominal' : case 'ordinal' : case 'key' : return encodings . concat ( encQ ) ; } throw new Error ( 'Unsupported type in related summaries query creator.' ) ; } return encodings ; } , [ ] ) } ; return { spec : newSpec , groupBy : 'fieldTransform' , orderBy : [ 'fieldOrder' , 'aggregationQuality' , 'effectiveness' ] , chooseBy : [ 'aggregationQuality' , 'effectiveness' ] , config : { autoAddCount : true , omitRaw : true } } ; } } ;