@@ -1513,7 +1513,7 @@ protected static function create_impl($p, $options)
15131513 $ s .= " FINAL " ;
15141514 }
15151515 if (@$ p ["ARRAYJOIN " ]) {
1516- if (@$ p ["OPTION_SELECT_DISTINCT " ]) {
1516+ if (@$ p ["OPTION_ARRAYJOIN_LEFT " ]) {
15171517 $ s .= " LEFT " ;
15181518 }
15191519 $ s .= " ARRAY JOIN " ;
@@ -2384,8 +2384,17 @@ protected static function get_next_select($tokens, $index)
23842384 if (self ::is_token_of ($ token , "USING " )) {
23852385 $ expr ["using " ] = array ();
23862386 $ index ++;
2387- for (;;) {
2388- list ($ expr2 , $ index ) = self ::get_next_expr ($ tokens , $ index , 0 );
2387+ $ token = @$ tokens [$ index ];
2388+ for ($ quote_cnt = 0 ; ;) {
2389+ if (!self ::is_token_of ($ token , "( " )) {
2390+ break ;
2391+ }
2392+ $ index ++;
2393+ $ token = @$ tokens [$ index ];
2394+ $ quote_cnt ++;
2395+ }
2396+ for (; ;) {
2397+ list ($ expr2 , $ index ) = self ::get_next_expr ($ tokens , $ index , 0 , false );
23892398 $ expr ["using " ][] = $ expr2 ;
23902399 $ token = @$ tokens [$ index ];
23912400 if ($ token === ", " ) {
@@ -2394,9 +2403,36 @@ protected static function get_next_select($tokens, $index)
23942403 break ;
23952404 }
23962405 }
2406+ for (; $ quote_cnt > 0 ;) {
2407+ if (!self ::is_token_of ($ token , ") " )) {
2408+ throw new ClickHouseSQLParserParseError ("expect ')' got " . self ::token_to_string ($ token ));
2409+ }
2410+ $ index ++;
2411+ $ token = @$ tokens [$ index ];
2412+ $ quote_cnt --;
2413+ }
23972414 } elseif (self ::is_token_of ($ token , "ON " )) {
2398- list ($ expr2 , $ index ) = self ::get_next_expr ($ tokens , $ index + 1 , 0 );
2415+ $ index ++;
2416+ $ token = @$ tokens [$ index ];
2417+ for ($ quote_cnt = 0 ; ;) {
2418+ if (!self ::is_token_of ($ token , "( " )) {
2419+ break ;
2420+ }
2421+ $ index ++;
2422+ $ token = @$ tokens [$ index ];
2423+ $ quote_cnt ++;
2424+ }
2425+ list ($ expr2 , $ index ) = self ::get_next_expr ($ tokens , $ index , 0 , false );
2426+ $ token = @$ tokens [$ index ];
23992427 $ expr ["on " ] = $ expr2 ;
2428+ for (; $ quote_cnt > 0 ;) {
2429+ if (!self ::is_token_of ($ token , ") " )) {
2430+ throw new ClickHouseSQLParserParseError ("expect ')' got " . self ::token_to_string ($ token ));
2431+ }
2432+ $ index ++;
2433+ $ token = @$ tokens [$ index ];
2434+ $ quote_cnt --;
2435+ }
24002436 } else {
24012437 throw new \ErrorException ("expect 'USING' or 'ON' after ' {$ join ["type " ]}' got " . self ::token_to_string ($ token ));
24022438 }
0 commit comments