@@ -336,6 +336,7 @@ TEST(SelectJoin) {
336336 ASSERT_STREQ (outer_join->condition ->expr ->name , " product_id" );
337337 ASSERT_STREQ (outer_join->condition ->expr2 ->table , " Product" );
338338 ASSERT_STREQ (outer_join->condition ->expr2 ->name , " id" );
339+ ASSERT_FALSE (outer_join->namedColumns );
339340
340341 // Joins are are left associative.
341342 // So the second join should be on the left.
@@ -347,6 +348,7 @@ TEST(SelectJoin) {
347348 ASSERT_STREQ (inner_join->left ->name , " fact" );
348349 ASSERT_EQ (inner_join->right ->type , kTableName );
349350 ASSERT_STREQ (inner_join->right ->name , " City" );
351+ ASSERT_FALSE (inner_join->namedColumns );
350352
351353 ASSERT_EQ (inner_join->condition ->opType , kOpEquals );
352354 ASSERT_STREQ (inner_join->condition ->expr ->table , " fact" );
@@ -355,6 +357,106 @@ TEST(SelectJoin) {
355357 ASSERT_STREQ (inner_join->condition ->expr2 ->name , " id" );
356358}
357359
360+ TEST (SelectJoinUsing) {
361+ TEST_PARSE_SQL_QUERY (
362+ " SELECT * FROM foo INNER JOIN bar USING (a, b);"
363+ " SELECT a, b, c FROM foo LEFT JOIN bar USING (a);"
364+ " SELECT b FROM foo AS baz JOIN bar USING (a);" ,
365+ result, 3 );
366+
367+ auto stmt = (SelectStatement*)result.getStatement (0 );
368+ // SELECT * ...
369+ ASSERT_TRUE (stmt->selectList );
370+ ASSERT_EQ (stmt->selectList ->size (), 1 );
371+ ASSERT_EQ (stmt->selectList ->front ()->type , kExprStar );
372+
373+ // ... FROM foo INNER JOIN bar ...
374+ ASSERT_TRUE (stmt->fromTable );
375+ ASSERT_EQ (stmt->fromTable ->type , kTableJoin );
376+ ASSERT_TRUE (stmt->fromTable ->join );
377+ ASSERT_EQ (stmt->fromTable ->join ->type , kJoinInner );
378+ ASSERT_TRUE (stmt->fromTable ->join ->left );
379+ ASSERT_EQ (stmt->fromTable ->join ->left ->type , kTableName );
380+ ASSERT_TRUE (stmt->fromTable ->join ->left ->name );
381+ ASSERT_STREQ (stmt->fromTable ->join ->left ->name , " foo" );
382+ ASSERT_TRUE (stmt->fromTable ->join ->right );
383+ ASSERT_EQ (stmt->fromTable ->join ->right ->type , kTableName );
384+ ASSERT_TRUE (stmt->fromTable ->join ->right ->name );
385+ ASSERT_STREQ (stmt->fromTable ->join ->right ->name , " bar" );
386+
387+ // ... USING a, b;
388+ ASSERT_FALSE (stmt->fromTable ->join ->condition );
389+ ASSERT_TRUE (stmt->fromTable ->join ->namedColumns );
390+ ASSERT_EQ (stmt->fromTable ->join ->namedColumns ->size (), 2 );
391+ ASSERT_STREQ (stmt->fromTable ->join ->namedColumns ->at (0 ), " a" );
392+ ASSERT_STREQ (stmt->fromTable ->join ->namedColumns ->at (1 ), " b" );
393+
394+ stmt = (SelectStatement*)result.getStatement (1 );
395+ // SELECT a, b, c ...
396+ ASSERT_TRUE (stmt->selectList );
397+ ASSERT_EQ (stmt->selectList ->size (), 3 );
398+ ASSERT_EQ (stmt->selectList ->at (0 )->type , kExprColumnRef );
399+ ASSERT_TRUE (stmt->selectList ->at (0 )->name );
400+ ASSERT_STREQ (stmt->selectList ->at (0 )->name , " a" );
401+ ASSERT_EQ (stmt->selectList ->at (1 )->type , kExprColumnRef );
402+ ASSERT_TRUE (stmt->selectList ->at (1 )->name );
403+ ASSERT_STREQ (stmt->selectList ->at (1 )->name , " b" );
404+ ASSERT_EQ (stmt->selectList ->at (2 )->type , kExprColumnRef );
405+ ASSERT_TRUE (stmt->selectList ->at (2 )->name );
406+ ASSERT_STREQ (stmt->selectList ->at (2 )->name , " c" );
407+
408+ // ... FROM foo LEFT JOIN bar ...
409+ ASSERT_TRUE (stmt->fromTable );
410+ ASSERT_EQ (stmt->fromTable ->type , kTableJoin );
411+ ASSERT_TRUE (stmt->fromTable ->join );
412+ ASSERT_EQ (stmt->fromTable ->join ->type , kJoinLeft );
413+ ASSERT_TRUE (stmt->fromTable ->join ->left );
414+ ASSERT_EQ (stmt->fromTable ->join ->left ->type , kTableName );
415+ ASSERT_TRUE (stmt->fromTable ->join ->left ->name );
416+ ASSERT_STREQ (stmt->fromTable ->join ->left ->name , " foo" );
417+ ASSERT_TRUE (stmt->fromTable ->join ->right );
418+ ASSERT_EQ (stmt->fromTable ->join ->right ->type , kTableName );
419+ ASSERT_TRUE (stmt->fromTable ->join ->right ->name );
420+ ASSERT_STREQ (stmt->fromTable ->join ->right ->name , " bar" );
421+
422+ // ... USING a;
423+ ASSERT_FALSE (stmt->fromTable ->join ->condition );
424+ ASSERT_TRUE (stmt->fromTable ->join ->namedColumns );
425+ ASSERT_EQ (stmt->fromTable ->join ->namedColumns ->size (), 1 );
426+ ASSERT_STREQ (stmt->fromTable ->join ->namedColumns ->at (0 ), " a" );
427+
428+ stmt = (SelectStatement*)result.getStatement (2 );
429+ // SELECT b ...
430+ ASSERT_TRUE (stmt->selectList );
431+ ASSERT_EQ (stmt->selectList ->size (), 1 );
432+ ASSERT_EQ (stmt->selectList ->at (0 )->type , kExprColumnRef );
433+ ASSERT_TRUE (stmt->selectList ->at (0 )->name );
434+ ASSERT_STREQ (stmt->selectList ->at (0 )->name , " b" );
435+
436+ // ... FROM foo as baz JOIN bar ...
437+ ASSERT_TRUE (stmt->fromTable );
438+ ASSERT_EQ (stmt->fromTable ->type , kTableJoin );
439+ ASSERT_TRUE (stmt->fromTable ->join );
440+ ASSERT_EQ (stmt->fromTable ->join ->type , kJoinInner );
441+ ASSERT_TRUE (stmt->fromTable ->join ->left );
442+ ASSERT_EQ (stmt->fromTable ->join ->left ->type , kTableName );
443+ ASSERT_TRUE (stmt->fromTable ->join ->left ->name );
444+ ASSERT_STREQ (stmt->fromTable ->join ->left ->name , " foo" );
445+ ASSERT_TRUE (stmt->fromTable ->join ->left ->alias );
446+ ASSERT_TRUE (stmt->fromTable ->join ->left ->alias ->name );
447+ ASSERT_STREQ (stmt->fromTable ->join ->left ->alias ->name , " baz" );
448+ ASSERT_TRUE (stmt->fromTable ->join ->right );
449+ ASSERT_EQ (stmt->fromTable ->join ->right ->type , kTableName );
450+ ASSERT_TRUE (stmt->fromTable ->join ->right ->name );
451+ ASSERT_STREQ (stmt->fromTable ->join ->right ->name , " bar" );
452+
453+ // ... USING a;
454+ ASSERT_FALSE (stmt->fromTable ->join ->condition );
455+ ASSERT_TRUE (stmt->fromTable ->join ->namedColumns );
456+ ASSERT_EQ (stmt->fromTable ->join ->namedColumns ->size (), 1 );
457+ ASSERT_STREQ (stmt->fromTable ->join ->namedColumns ->at (0 ), " a" );
458+ }
459+
358460TEST (SelectColumnOrder) {
359461 TEST_PARSE_SINGLE_SQL (
360462 " SELECT *\
@@ -490,36 +592,47 @@ TEST(JoinTypes) {
490592
491593 stmt = (SelectStatement*)result.getStatement (0 );
492594 ASSERT_EQ (stmt->fromTable ->join ->type , kJoinInner );
595+ ASSERT_FALSE (stmt->fromTable ->join ->namedColumns );
493596
494597 stmt = (SelectStatement*)result.getStatement (1 );
495598 ASSERT_EQ (stmt->fromTable ->join ->type , kJoinInner );
599+ ASSERT_FALSE (stmt->fromTable ->join ->namedColumns );
496600
497601 stmt = (SelectStatement*)result.getStatement (2 );
498602 ASSERT_EQ (stmt->fromTable ->join ->type , kJoinLeft );
603+ ASSERT_FALSE (stmt->fromTable ->join ->namedColumns );
499604
500605 stmt = (SelectStatement*)result.getStatement (3 );
501606 ASSERT_EQ (stmt->fromTable ->join ->type , kJoinLeft );
607+ ASSERT_FALSE (stmt->fromTable ->join ->namedColumns );
502608
503609 stmt = (SelectStatement*)result.getStatement (4 );
504610 ASSERT_EQ (stmt->fromTable ->join ->type , kJoinRight );
611+ ASSERT_FALSE (stmt->fromTable ->join ->namedColumns );
505612
506613 stmt = (SelectStatement*)result.getStatement (5 );
507614 ASSERT_EQ (stmt->fromTable ->join ->type , kJoinRight );
615+ ASSERT_FALSE (stmt->fromTable ->join ->namedColumns );
508616
509617 stmt = (SelectStatement*)result.getStatement (6 );
510618 ASSERT_EQ (stmt->fromTable ->join ->type , kJoinFull );
619+ ASSERT_FALSE (stmt->fromTable ->join ->namedColumns );
511620
512621 stmt = (SelectStatement*)result.getStatement (7 );
513622 ASSERT_EQ (stmt->fromTable ->join ->type , kJoinFull );
623+ ASSERT_FALSE (stmt->fromTable ->join ->namedColumns );
514624
515625 stmt = (SelectStatement*)result.getStatement (8 );
516626 ASSERT_EQ (stmt->fromTable ->join ->type , kJoinFull );
627+ ASSERT_FALSE (stmt->fromTable ->join ->namedColumns );
517628
518629 stmt = (SelectStatement*)result.getStatement (9 );
519630 ASSERT_EQ (stmt->fromTable ->join ->type , kJoinNatural );
631+ ASSERT_FALSE (stmt->fromTable ->join ->namedColumns );
520632
521633 stmt = (SelectStatement*)result.getStatement (10 );
522634 ASSERT_EQ (stmt->fromTable ->join ->type , kJoinCross );
635+ ASSERT_FALSE (stmt->fromTable ->join ->namedColumns );
523636
524637 stmt = (SelectStatement*)result.getStatement (11 );
525638 ASSERT_NULL (stmt->fromTable ->join );
@@ -699,7 +812,7 @@ TEST(WithClauseSingle) {
699812 ASSERT_STREQ (stmt->withDescriptions ->at (0 )->alias , " a" );
700813
701814 // with_description – select stmt
702- ASSERT_EQ (stmt->withDescriptions ->at (0 )->select ->selectList ->size (), 1 )
815+ ASSERT_EQ (stmt->withDescriptions ->at (0 )->select ->selectList ->size (), 1 );
703816 ASSERT_STREQ (stmt->withDescriptions ->at (0 )->select ->selectList ->at (0 )->name , std::string (" name" ));
704817 ASSERT_STREQ (stmt->withDescriptions ->at (0 )->select ->fromTable ->name , std::string (" peopleA" ));
705818
@@ -725,9 +838,9 @@ TEST(WithClauseDouble) {
725838 ASSERT_STREQ (stmt->withDescriptions ->at (1 )->alias , " b" );
726839
727840 // with_description – select stmts
728- ASSERT_EQ (stmt->withDescriptions ->at (0 )->select ->selectList ->size (), 1 )
841+ ASSERT_EQ (stmt->withDescriptions ->at (0 )->select ->selectList ->size (), 1 );
729842 ASSERT_STREQ (stmt->withDescriptions ->at (0 )->select ->fromTable ->name , " peopleA" );
730- ASSERT_EQ (stmt->withDescriptions ->at (1 )->select ->selectList ->size (), 2 )
843+ ASSERT_EQ (stmt->withDescriptions ->at (1 )->select ->selectList ->size (), 2 );
731844 ASSERT_STREQ (stmt->withDescriptions ->at (1 )->select ->fromTable ->name , " peopleB" );
732845
733846 // main select
@@ -990,7 +1103,6 @@ TEST(MultipleLockingClause) {
9901103}
9911104
9921105TEST (WindowFunctions) {
993- SelectStatement* stmt;
9941106 TEST_PARSE_SQL_QUERY (
9951107 " SELECT t2, 1 / avg(t1) OVER(), rank() OVER(ORDER BY t1 DESC) rnk FROM t;"
9961108 " SELECT avg(t1) OVER(PARTITION BY t2, t3 ORDER BY t4, t5 ROWS UNBOUNDED PRECEDING) FROM t;"
@@ -1000,7 +1112,7 @@ TEST(WindowFunctions) {
10001112 " SELECT rank() OVER(PARTITION BY t1 ORDER BY t2 GROUPS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM t;" ,
10011113 result, 5 );
10021114
1003- stmt = (SelectStatement*)result.getStatement (0 );
1115+ auto stmt = (SelectStatement*)result.getStatement (0 );
10041116 ASSERT_TRUE (stmt->selectList );
10051117 ASSERT_EQ (stmt->selectList ->size (), 3 );
10061118 ASSERT_TRUE (stmt->fromTable );
0 commit comments