diff --git a/src/languages/bigquery.formatter.ts b/src/languages/bigquery.formatter.ts index aee9c1609e..6bee4643e6 100644 --- a/src/languages/bigquery.formatter.ts +++ b/src/languages/bigquery.formatter.ts @@ -895,9 +895,9 @@ function combineParameterizedTypes(tokens: Token[]) { const endIndex = findClosingAngleBracketIndex(tokens, i + 1); const typeDefTokens = tokens.slice(i, endIndex + 1); processed.push({ - ...token, - value: typeDefTokens.map(formatTypeDefToken).join(''), - text: typeDefTokens.map(formatTypeDefToken).join(''), + type: TokenType.IDENT, + value: typeDefTokens.map(formatTypeDefToken('value')).join(''), + text: typeDefTokens.map(formatTypeDefToken('text')).join(''), }); i = endIndex; } else { @@ -907,13 +907,15 @@ function combineParameterizedTypes(tokens: Token[]) { return processed; } -function formatTypeDefToken({ type, value, text }: Token): string { - if (type === TokenType.IDENT || value === ',') { - return text + ' '; - } else { - return text; - } -} +const formatTypeDefToken = + (key: 'text' | 'value') => + (token: Token): string => { + if (token.type === TokenType.IDENT || token.value === ',') { + return token[key] + ' '; + } else { + return token[key]; + } + }; function findClosingAngleBracketIndex(tokens: Token[], startIndex: number): number { let level = 0; diff --git a/test/bigquery.test.ts b/test/bigquery.test.ts index d66010ca5b..2fe82b02de 100644 --- a/test/bigquery.test.ts +++ b/test/bigquery.test.ts @@ -131,6 +131,25 @@ describe('BigQueryFormatter', () => { `); }); + it('supports uppercasing of STRUCT', () => { + expect(format('select struct(1,"foo");', { keywordCase: 'upper' })) + .toBe(dedent` + SELECT + STRUCT(1, "foo"); + `); + }); + + // XXX: This is hard to achieve with our current type-parameter processing hack. + // At least we're preserving the case of identifier names here, + // and lowercasing is luckily less used than uppercasing. + it('does not support lowercasing of STRUCT', () => { + expect(format('SELECT STRUCT(1,"foo");', { keywordCase: 'lower' })) + .toBe(dedent` + select + STRUCT(1, "foo"); + `); + }); + it('supports parameterised types', () => { const result = format( `