File tree Expand file tree Collapse file tree 2 files changed +20
-9
lines changed
packages/cubejs-schema-compiler Expand file tree Collapse file tree 2 files changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -64,18 +64,15 @@ export class SqlParser {
6464 protected static sqlUpperCase ( sql ) {
6565 let result = '' ;
6666 let openChar ;
67- let inComment = false ;
68- let commentType = '' ;
67+ let commentType : ( '--' | '/*' | '' ) = '' ;
6968
7069 for ( let i = 0 ; i < sql . length ; i ++ ) {
71- if ( inComment ) {
70+ if ( commentType ) {
7271 if ( commentType === '--' && ( sql [ i ] === '\n' || sql [ i ] === '\r' ) ) {
73- inComment = false ;
7472 commentType = '' ;
7573 } else if ( commentType === '/*' && sql [ i ] === '*' && sql [ i + 1 ] === '/' ) {
7674 result += sql [ i ] ;
7775 i ++ ;
78- inComment = false ;
7976 commentType = '' ;
8077 }
8178 result += sql [ i ] ;
@@ -89,18 +86,16 @@ export class SqlParser {
8986 result += sql [ i ] ;
9087 } else if ( sql [ i ] === '-' && sql [ i + 1 ] === '-' ) {
9188 // Check for start of single-line comment
92- inComment = true ;
9389 commentType = '--' ;
9490 result += sql [ i ] ;
9591 } else if ( sql [ i ] === '/' && sql [ i + 1 ] === '*' ) {
9692 // Check for start of multi-line comment
97- inComment = true ;
9893 commentType = '/*' ;
9994 result += sql [ i ] ;
10095 } else if ( sql [ i ] === '\'' || sql [ i ] === '"' || sql [ i ] === '`' ) {
10196 // Check for string literals
10297 openChar = sql [ i ] ;
103- result += sql [ i ] . toUpperCase ( ) ;
98+ result += sql [ i ] ;
10499 } else {
105100 // Regular character - convert to uppercase
106101 result += sql [ i ] . toUpperCase ( ) ;
Original file line number Diff line number Diff line change @@ -109,7 +109,23 @@ describe('SqlParser', () => {
109109 } ) ;
110110
111111 it ( 'sql with multiline comment containing question mark' , ( ) => {
112- const sqlParser = new SqlParser ( 'SELECT 1 as test FROM table_name /* this is comment that kaputs Cube -> ? */' ) ;
112+ const sqlParser = new SqlParser ( `SELECT 1 as test FROM table_name
113+ /* this is a real
114+ multiline comment that
115+ contains ? character */` ) ;
113116 expect ( sqlParser . canParse ( ) ) . toEqual ( true ) ;
114117 } ) ;
118+
119+ it ( 'numeric literal in SELECT with table alias extraction' , ( ) => {
120+ const sqlParser = new SqlParser ( `SELECT 1 as test_literal, 2.5 as decimal_literal
121+ FROM users u
122+ WHERE u.status = 'active' AND u.created_at > '2024-01-01'` ) ;
123+
124+ expect ( sqlParser . canParse ( ) ) . toEqual ( true ) ;
125+ expect ( sqlParser . isSimpleAsteriskQuery ( ) ) . toEqual ( false ) ;
126+
127+ // Verify table alias extraction still works after grammar changes
128+ const extractedConditions = sqlParser . extractWhereConditions ( 't' ) ;
129+ expect ( extractedConditions ) . toEqual ( `t.status = 'active' AND t.created_at > '2024-01-01'` ) ;
130+ } ) ;
115131} ) ;
You can’t perform that action at this time.
0 commit comments