From c2c81225530fc1363bbf8e2667ecedb78d6dcab0 Mon Sep 17 00:00:00 2001 From: Andreas Reichel Date: Thu, 21 Oct 2021 13:24:04 +0700 Subject: [PATCH] Fixes #1385 and PR#1380 Add another Alias() Keyword related LOOKAHEAD Fix a Keyword Spelling Error in the Deparser Remove UNPIVOT from the PARENTHESIS Deparser, as it was an ugly workaround made obsolete by PR #1380 --- .../util/deparser/SelectDeParser.java | 24 +++++-------------- .../net/sf/jsqlparser/parser/JSqlParserCC.jjt | 2 +- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/SelectDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/SelectDeParser.java index 02ab438df..b53724bd4 100644 --- a/src/main/java/net/sf/jsqlparser/util/deparser/SelectDeParser.java +++ b/src/main/java/net/sf/jsqlparser/util/deparser/SelectDeParser.java @@ -307,10 +307,12 @@ public void visit(UnPivot unpivot) { boolean showOptions = unpivot.getIncludeNullsSpecified(); boolean includeNulls = unpivot.getIncludeNulls(); List unpivotForClause = unpivot.getUnPivotForClause(); - buffer.append(" UNPIVOT").append(showOptions && includeNulls ? " INCLUDE NULLS" : "") - .append(showOptions && !includeNulls ? " EXCULDE NULLS" : "").append(" (") - .append(unpivot.getUnPivotClause()).append(" FOR ") - .append(PlainSelect.getStringList(unpivotForClause, true, + buffer + .append(" UNPIVOT") + .append(showOptions && includeNulls ? " INCLUDE NULLS" : "") + .append(showOptions && !includeNulls ? " EXCLUDE NULLS" : "") + .append(" (").append(unpivot.getUnPivotClause()) + .append(" FOR ").append(PlainSelect.getStringList(unpivotForClause, true, unpivotForClause != null && unpivotForClause.size() > 1)) .append(" IN ").append(PlainSelect.getStringList(unpivot.getUnPivotInClause(), true, true)).append(")"); if (unpivot.getAlias() != null) { @@ -533,20 +535,6 @@ public void visit(ParenthesisFromItem parenthesis) { buffer.append("("); parenthesis.getFromItem().accept(this); - //@todo: investigate, why the Pivot is handled already - // while the UnPivot is NOT handled. - // Something here is wrong and the code below is just a work around - - /* handled already somehow somewhere, see Special Oracle Test "pivot07_Parenthesis.sql" - if (parenthesis.getFromItem().getPivot()!=null) { - parenthesis.getFromItem().getPivot().accept(this); - } - */ - - if (parenthesis.getFromItem().getUnPivot()!=null) { - parenthesis.getFromItem().getUnPivot().accept(this); - } - buffer.append(")"); if (parenthesis.getAlias() != null) { buffer.append(parenthesis.getAlias().toString()); diff --git a/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt b/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt index c30ee1691..33e5c2971 100644 --- a/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt +++ b/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt @@ -2285,7 +2285,7 @@ UnPivot UnPivot(): unpivotInClause = PivotSingleInItems() ")" ")" - [ alias = Alias() ] + [ LOOKAHEAD(2) alias = Alias() ] { retval.setUnPivotClause(unpivotClause); retval.setUnPivotForClause(unpivotForClause);