File tree Expand file tree Collapse file tree 6 files changed +41
-2
lines changed
jjtree/net/sf/jsqlparser/parser
test/java/net/sf/jsqlparser/statement/select Expand file tree Collapse file tree 6 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ public class ParserKeywordsUtils {
63
63
{"CURRENT" , RESTRICTED_JSQLPARSER },
64
64
{"DEFAULT" , RESTRICTED_ALIAS },
65
65
{"DISTINCT" , RESTRICTED_SQL2016 },
66
+ {"DISTINCTROW" , RESTRICTED_SQL2016 },
66
67
{"DOUBLE" , RESTRICTED_ALIAS },
67
68
{"ELSE" , RESTRICTED_JSQLPARSER },
68
69
{"EXCEPT" , RESTRICTED_SQL2016 },
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ public class Distinct implements Serializable {
20
20
21
21
private List <SelectItem <?>> onSelectItems ;
22
22
private boolean useUnique = false ;
23
+ private boolean useDistinctRow = false ;
23
24
24
25
public Distinct () {}
25
26
@@ -43,9 +44,18 @@ public void setUseUnique(boolean useUnique) {
43
44
this .useUnique = useUnique ;
44
45
}
45
46
47
+ public boolean isUseDistinctRow () {
48
+ return useDistinctRow ;
49
+ }
50
+
51
+ public void setUseDistinctRow (boolean useDistinctRow ) {
52
+ this .useDistinctRow = useDistinctRow ;
53
+ }
54
+
46
55
@ Override
47
56
public String toString () {
48
- String sql = useUnique ? "UNIQUE" : "DISTINCT" ;
57
+ String distinctIdentifier = useDistinctRow ? "DISTINCTROW" : "DISTINCT" ;
58
+ String sql = useUnique ? "UNIQUE" : distinctIdentifier ;
49
59
50
60
if (onSelectItems != null && !onSelectItems .isEmpty ()) {
51
61
sql += " ON (" + PlainSelect .getStringList (onSelectItems ) + ")" ;
Original file line number Diff line number Diff line change @@ -397,6 +397,8 @@ protected void deparseDistinctClause(Distinct distinct) {
397
397
if (distinct != null ) {
398
398
if (distinct .isUseUnique ()) {
399
399
builder .append ("UNIQUE " );
400
+ } else if (distinct .isUseDistinctRow ()) {
401
+ builder .append ("DISTINCTROW " );
400
402
} else {
401
403
builder .append ("DISTINCT " );
402
404
}
Original file line number Diff line number Diff line change @@ -316,6 +316,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
316
316
| <K_DISCARD : "DISCARD">
317
317
| <K_DISCONNECT:"DISCONNECT">
318
318
| <K_DISTINCT:"DISTINCT">
319
+ | <K_DISTINCTROW:"DISTINCTROW">
319
320
| <K_DIV:"DIV">
320
321
| <K_DDL:"DDL">
321
322
| <K_DML:"DML">
@@ -3147,7 +3148,9 @@ PlainSelect PlainSelect() #PlainSelect:
3147
3148
[ LOOKAHEAD(2) "ON" "(" distinctOn=SelectItemsList() { plainSelect.getDistinct().setOnSelectItems(distinctOn); } ")" ]
3148
3149
)
3149
3150
|
3150
- <K_UNIQUE> { distinct = new Distinct(true); plainSelect.setDistinct(distinct); }
3151
+ <K_DISTINCTROW> { distinct = new Distinct(); distinct.setUseDistinctRow(true); plainSelect.setDistinct(distinct); }
3152
+ |
3153
+ <K_UNIQUE> { distinct = new Distinct(true); plainSelect.setDistinct(distinct); }
3151
3154
|
3152
3155
<K_SQL_CALC_FOUND_ROWS> { plainSelect.setMySqlSqlCalcFoundRows(true); }
3153
3156
|
Original file line number Diff line number Diff line change @@ -43,6 +43,8 @@ The following Keywords are **restricted** in JSQLParser-|JSQLPARSER_VERSION| and
43
43
+----------------------+-------------+-----------+
44
44
| DISTINCT | Yes | Yes |
45
45
+----------------------+-------------+-----------+
46
+ | DISTINCTROW | Yes | Yes |
47
+ +----------------------+-------------+-----------+
46
48
| DOUBLE | Yes | |
47
49
+----------------------+-------------+-----------+
48
50
| ELSE | Yes | Yes |
Original file line number Diff line number Diff line change @@ -1058,6 +1058,27 @@ public void testDistinct() throws JSQLParserException {
1058
1058
.getExpression ()).getColumnName ());
1059
1059
}
1060
1060
1061
+ @ Test
1062
+ public void testDistinctRow () throws JSQLParserException {
1063
+ String statement =
1064
+ "SELECT DISTINCTROW col1, col2 FROM mytable WHERE mytable.col = 9" ;
1065
+ Select select = (Select ) TestUtils .assertSqlCanBeParsedAndDeparsed (statement , true );
1066
+
1067
+ assertInstanceOf (PlainSelect .class , select );
1068
+
1069
+ PlainSelect plainSelect = (PlainSelect ) select ;
1070
+ Distinct distinct = plainSelect .getDistinct ();
1071
+
1072
+ assertNotNull (distinct );
1073
+ assertTrue (distinct .isUseDistinctRow ());
1074
+ assertNull (distinct .getOnSelectItems ());
1075
+
1076
+ assertEquals ("col1" , ((Column ) (plainSelect .getSelectItems ().get (0 ))
1077
+ .getExpression ()).getColumnName ());
1078
+ assertEquals ("col2" , ((Column ) (plainSelect .getSelectItems ().get (1 ))
1079
+ .getExpression ()).getColumnName ());
1080
+ }
1081
+
1061
1082
@ Test
1062
1083
public void testIsDistinctFrom () throws JSQLParserException {
1063
1084
String stmt = "SELECT name FROM tbl WHERE name IS DISTINCT FROM foo" ;
You can’t perform that action at this time.
0 commit comments