Adjust Table Join Types

Consolidate LeftOuter/Left and RightOuter/Right as they are
by definition the same.
Similar consolidate FullOuter/Outer/Full ... with Outer (as in the
parser) not part of standard, but "full" missing. Allowing all three.

This commit potentially breaks other programs as kJoinLeftOuter and kJoinRightOuter
are eliminated
This commit is contained in:
javrucebo 2018-01-22 20:44:33 +01:00
parent 9872603fe7
commit 66688f7199
3 changed files with 62 additions and 7 deletions

View File

@ -993,9 +993,11 @@ join_clause:
opt_join_type: opt_join_type:
INNER { $$ = kJoinInner; } INNER { $$ = kJoinInner; }
| OUTER { $$ = kJoinOuter; } | FULL OUTER { $$ = kJoinFull; }
| LEFT OUTER { $$ = kJoinLeftOuter; } | LEFT OUTER { $$ = kJoinLeft; }
| RIGHT OUTER { $$ = kJoinRightOuter; } | RIGHT OUTER { $$ = kJoinRight; }
| OUTER { $$ = kJoinFull; }
| FULL { $$ = kJoinFull; }
| LEFT { $$ = kJoinLeft; } | LEFT { $$ = kJoinLeft; }
| RIGHT { $$ = kJoinRight; } | RIGHT { $$ = kJoinRight; }
| CROSS { $$ = kJoinCross; } | CROSS { $$ = kJoinCross; }

View File

@ -49,11 +49,9 @@ namespace hsql {
// Possible types of joins. // Possible types of joins.
enum JoinType { enum JoinType {
kJoinInner, kJoinInner,
kJoinOuter, kJoinFull,
kJoinLeft, kJoinLeft,
kJoinRight, kJoinRight,
kJoinLeftOuter,
kJoinRightOuter,
kJoinCross, kJoinCross,
kJoinNatural kJoinNatural
}; };

View File

@ -298,7 +298,7 @@ TEST(SelectJoin) {
const TableRef* table = stmt->fromTable; const TableRef* table = stmt->fromTable;
const JoinDefinition* outer_join = table->join; const JoinDefinition* outer_join = table->join;
ASSERT_EQ(table->type, kTableJoin); ASSERT_EQ(table->type, kTableJoin);
ASSERT_EQ(outer_join->type, kJoinOuter); ASSERT_EQ(outer_join->type, kJoinFull);
ASSERT_EQ(outer_join->right->type, kTableName); ASSERT_EQ(outer_join->right->type, kTableName);
ASSERT_STREQ(outer_join->right->name, "Product"); ASSERT_STREQ(outer_join->right->name, "Product");
@ -347,3 +347,58 @@ TEST(SelectColumnOrder) {
ASSERT_STREQ(stmt->fromTable->list->at(2)->alias, "c"); ASSERT_STREQ(stmt->fromTable->list->at(2)->alias, "c");
ASSERT_STREQ(stmt->fromTable->list->at(3)->alias, "d"); ASSERT_STREQ(stmt->fromTable->list->at(3)->alias, "d");
} }
TEST(JoinTypes) {
SelectStatement* stmt;
SQLParserResult result;
SQLParser::parse("SELECT * FROM x join y on a=b; \
SELECT * FROM x inner join y on a=b; \
SELECT * FROM x left join y on a=b; \
SELECT * FROM x left outer join y on a=b; \
SELECT * FROM x right join y on a=b; \
SELECT * FROM x right outer join y on a=b; \
SELECT * FROM x full join y on a=b; \
SELECT * FROM x outer join y on a=b; \
SELECT * FROM x full outer join y on a=b; \
SELECT * FROM x natural join y; \
SELECT * FROM x cross join y on a=b; \
SELECT * FROM x, y where a = b;", &result);
stmt = (SelectStatement*) result.getStatement(0);
ASSERT_EQ(stmt->fromTable->join->type, kJoinInner);
stmt = (SelectStatement*) result.getStatement(1);
ASSERT_EQ(stmt->fromTable->join->type, kJoinInner);
stmt = (SelectStatement*) result.getStatement(2);
ASSERT_EQ(stmt->fromTable->join->type, kJoinLeft);
stmt = (SelectStatement*) result.getStatement(3);
ASSERT_EQ(stmt->fromTable->join->type, kJoinLeft);
stmt = (SelectStatement*) result.getStatement(4);
ASSERT_EQ(stmt->fromTable->join->type, kJoinRight);
stmt = (SelectStatement*) result.getStatement(5);
ASSERT_EQ(stmt->fromTable->join->type, kJoinRight);
stmt = (SelectStatement*) result.getStatement(6);
ASSERT_EQ(stmt->fromTable->join->type, kJoinFull);
stmt = (SelectStatement*) result.getStatement(7);
ASSERT_EQ(stmt->fromTable->join->type, kJoinFull);
stmt = (SelectStatement*) result.getStatement(8);
ASSERT_EQ(stmt->fromTable->join->type, kJoinFull);
stmt = (SelectStatement*) result.getStatement(9);
ASSERT_EQ(stmt->fromTable->join->type, kJoinNatural);
stmt = (SelectStatement*) result.getStatement(10);
ASSERT_EQ(stmt->fromTable->join->type, kJoinCross);
stmt = (SelectStatement*) result.getStatement(11);
ASSERT_NULL(stmt->fromTable->join);
}