-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[feat] Support for JSON_TABLE #2328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ANeumann82
wants to merge
3
commits into
JSQLParser:master
Choose a base branch
from
ANeumann82:json_table_support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/net/sf/jsqlparser/expression/JsonOnEmptyType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /*- | ||
| * #%L | ||
| * JSQLParser library | ||
| * %% | ||
| * Copyright (C) 2004 - 2021 JSQLParser | ||
| * %% | ||
| * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 | ||
| * #L% | ||
| */ | ||
| /* | ||
| * Copyright (C) 2021 JSQLParser. | ||
| * | ||
| * This library is free software; you can redistribute it and/or modify it under the terms of the | ||
| * GNU Lesser General Public License as published by the Free Software Foundation; either version | ||
| * 2.1 of the License, or (at your option) any later version. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | ||
| * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public License along with this library; | ||
| * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA | ||
| */ | ||
|
|
||
| package net.sf.jsqlparser.expression; | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| public enum JsonOnEmptyType { | ||
| ERROR("ERROR"), NULL("NULL"), EMPTY("EMPTY"), EMPTY_ARRAY("EMPTY ARRAY"), EMPTY_OBJECT( | ||
| "EMPTY OBJECT"), TRUE("TRUE"), FALSE("FALSE"), DEFAULT("DEFAULT"); | ||
|
|
||
| private final String value; | ||
|
|
||
| JsonOnEmptyType(String value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public String getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| public static JsonOnEmptyType from(String type) { | ||
| return Enum.valueOf(JsonOnEmptyType.class, type.toUpperCase()); | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
src/main/java/net/sf/jsqlparser/expression/JsonOnErrorType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /*- | ||
| * #%L | ||
| * JSQLParser library | ||
| * %% | ||
| * Copyright (C) 2004 - 2021 JSQLParser | ||
| * %% | ||
| * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 | ||
| * #L% | ||
| */ | ||
| /* | ||
| * Copyright (C) 2021 JSQLParser. | ||
| * | ||
| * This library is free software; you can redistribute it and/or modify it under the terms of the | ||
| * GNU Lesser General Public License as published by the Free Software Foundation; either version | ||
| * 2.1 of the License, or (at your option) any later version. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | ||
| * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public License along with this library; | ||
| * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA | ||
| */ | ||
|
|
||
| package net.sf.jsqlparser.expression; | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| public enum JsonOnErrorType { | ||
| ERROR("ERROR"), NULL("NULL"), EMPTY("EMPTY"), EMPTY_ARRAY("EMPTY ARRAY"), EMPTY_OBJECT( | ||
| "EMPTY OBJECT"), TRUE("TRUE"), FALSE("FALSE"), DEFAULT("DEFAULT"); | ||
|
|
||
| private final String value; | ||
|
|
||
| JsonOnErrorType(String value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public String getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| public static JsonOnErrorType from(String type) { | ||
| return Enum.valueOf(JsonOnErrorType.class, type.toUpperCase()); | ||
| } | ||
| } |
74 changes: 74 additions & 0 deletions
74
src/main/java/net/sf/jsqlparser/expression/JsonQueryWrapperType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /*- | ||
| * #%L | ||
| * JSQLParser library | ||
| * %% | ||
| * Copyright (C) 2004 - 2021 JSQLParser | ||
| * %% | ||
| * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 | ||
| * #L% | ||
| */ | ||
| /* | ||
| * Copyright (C) 2021 JSQLParser. | ||
| * | ||
| * This library is free software; you can redistribute it and/or modify it under the terms of the | ||
| * GNU Lesser General Public License as published by the Free Software Foundation; either version | ||
| * 2.1 of the License, or (at your option) any later version. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | ||
| * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public License along with this library; | ||
| * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA | ||
| */ | ||
|
|
||
| package net.sf.jsqlparser.expression; | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| public enum JsonQueryWrapperType { | ||
| WITHOUT_WRAPPER("WITHOUT WRAPPER"), WITHOUT_ARRAY_WRAPPER( | ||
ANeumann82 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "WITHOUT ARRAY WRAPPER"), WITH_WRAPPER("WITH WRAPPER"), WITH_ARRAY_WRAPPER( | ||
| "WITH ARRAY WRAPPER"), WITH_UNCONDITIONAL_WRAPPER( | ||
| "WITH UNCONDITIONAL WRAPPER"), WITH_UNCONDITIONAL_ARRAY_WRAPPER( | ||
| "WITH UNCONDITIONAL ARRAY WRAPPER"), WITH_CONDITIONAL_WRAPPER( | ||
| "WITH CONDITIONAL WRAPPER"), WITH_CONDITIONAL_ARRAY_WRAPPER( | ||
| "WITH CONDITIONAL ARRAY WRAPPER"); | ||
|
|
||
| private final String value; | ||
|
|
||
| JsonQueryWrapperType(String value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public String getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| public static JsonQueryWrapperType from(String type) { | ||
| return Enum.valueOf(JsonQueryWrapperType.class, type.toUpperCase()); | ||
| } | ||
|
|
||
| public static JsonQueryWrapperType fromWithParts(boolean isArray, boolean isConditional, | ||
| boolean isUnconditional) { | ||
| if (isArray) { | ||
| if (isConditional) { | ||
| return JsonQueryWrapperType.WITH_CONDITIONAL_ARRAY_WRAPPER; | ||
| } else if (isUnconditional) { | ||
| return JsonQueryWrapperType.WITH_UNCONDITIONAL_ARRAY_WRAPPER; | ||
| } else { | ||
| return JsonQueryWrapperType.WITH_ARRAY_WRAPPER; | ||
| } | ||
| } else { | ||
| if (isConditional) { | ||
| return JsonQueryWrapperType.WITH_CONDITIONAL_WRAPPER; | ||
| } else if (isUnconditional) { | ||
| return JsonQueryWrapperType.WITH_UNCONDITIONAL_WRAPPER; | ||
| } else { | ||
| return JsonQueryWrapperType.WITH_WRAPPER; | ||
| } | ||
| } | ||
| } | ||
| } | ||
71 changes: 71 additions & 0 deletions
71
src/main/java/net/sf/jsqlparser/expression/JsonReturnClause.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package net.sf.jsqlparser.expression; | ||
|
|
||
| import net.sf.jsqlparser.parser.ASTNodeAccessImpl; | ||
|
|
||
| public class JsonReturnClause extends ASTNodeAccessImpl { | ||
|
|
||
| private JsonReturnType type; | ||
|
|
||
| private Long varcharSize; | ||
|
|
||
| public JsonReturnClause() {} | ||
|
|
||
| public JsonReturnClause(JsonReturnType type) { | ||
| this.type = type; | ||
| } | ||
|
|
||
| public JsonReturnType getType() { | ||
| return type; | ||
| } | ||
|
|
||
| public void setType(JsonReturnType type) { | ||
| this.type = type; | ||
| } | ||
|
|
||
| public JsonReturnClause withType(JsonReturnType type) { | ||
| setType(type); | ||
| return this; | ||
| } | ||
|
|
||
| public Long getVarcharSize() { | ||
| return varcharSize; | ||
| } | ||
|
|
||
| public void setVarcharSize(Long varcharSize) { | ||
| this.varcharSize = varcharSize; | ||
| } | ||
|
|
||
| public JsonReturnClause withVarcharSize(Long varcharSize) { | ||
| setVarcharSize(varcharSize); | ||
| return this; | ||
| } | ||
|
|
||
| public StringBuilder append(StringBuilder builder) { | ||
| builder.append(" "); | ||
| builder.append(type.getValue()); | ||
| switch (type) { | ||
| case VARCHAR2: | ||
| case VARCHAR2_BYTE: | ||
| case VARCHAR2_CHAR: | ||
| if (varcharSize != null) { | ||
| builder.append("("); | ||
| builder.append(varcharSize); | ||
| switch (type) { | ||
| case VARCHAR2_BYTE: | ||
| builder.append(" BYTE"); | ||
| break; | ||
| case VARCHAR2_CHAR: | ||
| builder.append(" CHAR"); | ||
| break; | ||
| } | ||
| builder.append(")"); | ||
| } | ||
| break; | ||
| default: | ||
| // Nothing to do | ||
| break; | ||
| } | ||
| return builder; | ||
| } | ||
|
|
||
| } |
73 changes: 73 additions & 0 deletions
73
src/main/java/net/sf/jsqlparser/expression/JsonReturnType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /*- | ||
| * #%L | ||
| * JSQLParser library | ||
| * %% | ||
| * Copyright (C) 2004 - 2021 JSQLParser | ||
| * %% | ||
| * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 | ||
| * #L% | ||
| */ | ||
| /* | ||
| * Copyright (C) 2021 JSQLParser. | ||
| * | ||
| * This library is free software; you can redistribute it and/or modify it under the terms of the | ||
| * GNU Lesser General Public License as published by the Free Software Foundation; either version | ||
| * 2.1 of the License, or (at your option) any later version. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | ||
| * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public License along with this library; | ||
| * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA | ||
| */ | ||
|
|
||
| package net.sf.jsqlparser.expression; | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| public enum JsonReturnType { | ||
| VARCHAR2("VARCHAR2"), CLOB("CLOB"), BLOB("BLOB"), NUMBER("NUMBER"), DATE("DATE"), TIMESTAMP( | ||
| "TIMESTAMP"), TIMESTAMP_WITH_TIMEZONE( | ||
| "TIMESTAMP WITH TIMEZONE"), BOOLEAN("BOOLEAN"), VECTOR("VECTOR"), JSON("JSON"), | ||
|
|
||
| // VARCHAR2( x BYTE) | ||
| VARCHAR2_BYTE("VARCHAR2"), | ||
|
|
||
| // VARCHAR2( x CHAR) | ||
| VARCHAR2_CHAR("VARCHAR2"), | ||
| ; | ||
|
|
||
| private final String value; | ||
|
|
||
| JsonReturnType(String value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public String getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| public static JsonReturnType from(String type) { | ||
| return Enum.valueOf(JsonReturnType.class, type.toUpperCase()); | ||
| } | ||
|
|
||
| /** | ||
| * @see "https://docs.oracle.com/en/database/oracle/oracle-database/26/sqlrf/JSON_QUERY.html#GUID-6D396EC4-D2AA-43D2-8F5D-08D646A4A2D9__CJADJIIJ" | ||
| */ | ||
| public boolean isValidForJsonQueryReturnType() { | ||
| switch (this) { | ||
| case VARCHAR2: | ||
| case CLOB: | ||
| case BLOB: | ||
| case JSON: | ||
| case VECTOR: | ||
| return true; | ||
| default: | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.