You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2016/08/24 08:48:59 UTC
[07/19] ignite git commit: Review.
Review.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/4c960071
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/4c960071
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/4c960071
Branch: refs/heads/ignite-3716
Commit: 4c960071b25fb2846e272923175740cb523729ab
Parents: 59a734a
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Mon Aug 22 18:58:53 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Mon Aug 22 18:58:53 2016 +0300
----------------------------------------------------------------------
.../odbc/escape/OdbcEscapeSequenceParser.java | 65 ++++++++++----------
1 file changed, 34 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/4c960071/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/escape/OdbcEscapeSequenceParser.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/escape/OdbcEscapeSequenceParser.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/escape/OdbcEscapeSequenceParser.java
index cfaa7c0..911aede 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/escape/OdbcEscapeSequenceParser.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/escape/OdbcEscapeSequenceParser.java
@@ -15,41 +15,15 @@ public class OdbcEscapeSequenceParser {
* @param sql - sql query text
* @return - processed sql query text
*/
+ // TODO: Set static.
public String parse(String sql) {
- T2<Integer, String> val = parseInternal(sql, 0, false);
+ // TODO: The whole string could be escape sequence. Need to check it here, not simply pass false.
+ T2<Integer, String> val = parse0(sql, 0, false);
return val.get2();
}
/**
- * Parse escape sequence using appropriate parser.
- * Supports:
- * - Scalar function escape sequence. Example: "{fn func(arg1, arg2)}"
- *
- * @param sql - sql query text
- * @param startPosition - parser start position
- * @return pair of end of processed sequence position and parse result
- */
- private T2<Integer, String> parseEscapeSqeuence(String sql, int startPosition) {
- assert sql.charAt(startPosition) == '{';
-
- int pos = sql.indexOf(' ', startPosition + 1);
-
- if (pos == -1)
- throw new IllegalStateException("Escape sequence parsing error at (" + startPosition + "): " + sql);
-
- String esType = sql.substring(startPosition + 1, pos);
-
- switch (esType) {
- case "fn":
- return parseInternal(sql, pos + 1, true);
-
- default:
- throw new IllegalStateException("Unsupported escape sequence found at (" + startPosition + "): " + sql);
- }
- }
-
- /**
* Process ODBC escape sequences in sql query.
*
* @param sql - sql query text
@@ -57,7 +31,8 @@ public class OdbcEscapeSequenceParser {
* @param insideEscapeSeq - inside escape sequence flag
* @return pair of end of processed sequence position and parse result
*/
- @NotNull private T2<Integer, String> parseInternal(String sql, int startPosition, boolean insideEscapeSeq) {
+ // TODO: Do not use T2, create separate class instead.
+ @NotNull private T2<Integer, String> parse0(String sql, int startPosition, boolean insideEscapeSeq) {
StringBuffer sb = null;
int off = startPosition;
@@ -68,6 +43,7 @@ public class OdbcEscapeSequenceParser {
for (int i = startPosition; i < sql.length(); i++) {
char ch = sql.charAt(i);
+ // TODO: This should be implemented as separate parsers.
if ((ch == '\'' || ch == '"') && (i == 0 || sql.charAt(i - 1) != '\\')) {
if (quoted == 0)
quoted = ch;
@@ -88,7 +64,7 @@ public class OdbcEscapeSequenceParser {
}
// Inner escape sequence starts
else if (ch == '{') {
- T2<Integer, String> res = parseEscapeSqeuence(sql, i);
+ T2<Integer, String> res = processEscapeSequence(sql, i);
if (sb == null)
sb = new StringBuffer();
@@ -123,4 +99,31 @@ public class OdbcEscapeSequenceParser {
return new T2<>(seqEndPos, sb.toString());
}
+ /**
+ * Parse escape sequence using appropriate parser.
+ * Supports:
+ * - Scalar function escape sequence. Example: "{fn func(arg1, arg2)}"
+ *
+ * @param sql - sql query text
+ * @param startPosition - parser start position
+ * @return pair of end of processed sequence position and parse result
+ */
+ private T2<Integer, String> processEscapeSequence(String sql, int startPosition) {
+ assert sql.charAt(startPosition) == '{';
+
+ int pos = sql.indexOf(' ', startPosition + 1);
+
+ if (pos == -1)
+ throw new IllegalStateException("Escape sequence parsing error at (" + startPosition + "): " + sql);
+
+ String esType = sql.substring(startPosition + 1, pos);
+
+ switch (esType) {
+ case "fn":
+ return parse0(sql, pos + 1, true);
+
+ default:
+ throw new IllegalStateException("Unsupported escape sequence found at (" + startPosition + "): " + sql);
+ }
+ }
}