From b166cbbd120fe6dbc2f20dc4b90bf14ae6e52488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E6=9E=B8?= Date: Tue, 24 Dec 2024 19:12:02 +0800 Subject: [PATCH] Support to parse and generate unnest with offset sql. --- .../alibaba/druid/sql/visitor/SQLASTOutputVisitor.java | 9 +++++++-- core/src/test/resources/bvt/parser/bigquery/9.txt | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/alibaba/druid/sql/visitor/SQLASTOutputVisitor.java b/core/src/main/java/com/alibaba/druid/sql/visitor/SQLASTOutputVisitor.java index 3e09e2b881..a77722663a 100644 --- a/core/src/main/java/com/alibaba/druid/sql/visitor/SQLASTOutputVisitor.java +++ b/core/src/main/java/com/alibaba/druid/sql/visitor/SQLASTOutputVisitor.java @@ -4913,7 +4913,7 @@ public boolean visit(SQLSubqueryTableSource x) { final List columns = x.getColumns(); final String alias = x.getAlias(); if (alias != null) { - if (columns.size() > 0) { + if (!columns.isEmpty()) { print0(" AS "); } else { print(' '); @@ -4921,7 +4921,7 @@ public boolean visit(SQLSubqueryTableSource x) { print0(alias); } - if (columns.size() > 0) { + if (!columns.isEmpty()) { print0(" ("); for (int i = 0; i < columns.size(); i++) { if (i != 0) { @@ -4983,6 +4983,11 @@ public boolean visit(SQLUnnestTableSource x) { print(')'); } + if (x.getOffset() != null) { + print0(ucase ? " WITH OFFSET AS " : " with offset as "); + x.getOffset().accept(this); + } + return false; } diff --git a/core/src/test/resources/bvt/parser/bigquery/9.txt b/core/src/test/resources/bvt/parser/bigquery/9.txt index 09df262324..98d2828cd6 100644 --- a/core/src/test/resources/bvt/parser/bigquery/9.txt +++ b/core/src/test/resources/bvt/parser/bigquery/9.txt @@ -98,4 +98,9 @@ x.y.z -------------------- UPDATE a.b.c tbl SET tbl.x1 = oba.x2, tbl.x3 = oba.x4, tbl.x5 = oba.x6, tbl.x7 = oba.x8, tbl.x9 = oba.x10, tbl.x11 = oba.x12, tbl.x13 = oba.x14 -FROM x.y.z \ No newline at end of file +FROM x.y.z +------------------------------------------------------------------------------------------------------------------------ +select b from t, unnest(a) c1 with offset as c2 +-------------------- +SELECT b +FROM t, UNNEST(a) AS c1 WITH OFFSET AS c2 \ No newline at end of file