You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ma...@apache.org on 2014/12/10 17:47:05 UTC
incubator-nifi git commit: NIFI-52: Created new implementation of
PreparedQuery so that we can still prepare a query even if the expression is
invalid
Repository: incubator-nifi
Updated Branches:
refs/heads/develop cce36335e -> 8254b7543
NIFI-52: Created new implementation of PreparedQuery so that we can still prepare a query even if the expression is invalid
Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/8254b754
Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/8254b754
Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/8254b754
Branch: refs/heads/develop
Commit: 8254b75437a5b5a168259c7e46460ee3a7bc52f0
Parents: cce3633
Author: Mark Payne <ma...@hotmail.com>
Authored: Wed Dec 10 11:47:00 2014 -0500
Committer: Mark Payne <ma...@hotmail.com>
Committed: Wed Dec 10 11:47:00 2014 -0500
----------------------------------------------------------------------
.../language/InvalidPreparedQuery.java | 71 ++++++++++++++++++++
.../attribute/expression/language/Query.java | 44 ++++++------
.../exception/IllegalAttributeException.java | 1 +
3 files changed, 96 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/8254b754/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/InvalidPreparedQuery.java
----------------------------------------------------------------------
diff --git a/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/InvalidPreparedQuery.java b/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/InvalidPreparedQuery.java
new file mode 100644
index 0000000..e23bcc0
--- /dev/null
+++ b/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/InvalidPreparedQuery.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.attribute.expression.language;
+
+import java.util.Map;
+
+import org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageException;
+import org.apache.nifi.expression.AttributeValueDecorator;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.exception.ProcessException;
+
+
+/**
+ * An implementation of PreparedQuery that throws an {@link AttributeExpressionLanguageException} when attempting
+ * to evaluate the query. This allows a PreparedQuery to be created, even though it can't
+ * be evaluated.
+ */
+public class InvalidPreparedQuery implements PreparedQuery {
+ private final String query;
+ private final String explanation;
+
+ public InvalidPreparedQuery(final String query, final String explanation) {
+ this.query = query;
+ this.explanation = explanation;
+ }
+
+ @Override
+ public String evaluateExpressions(final FlowFile flowFile, final AttributeValueDecorator decorator) throws ProcessException {
+ throw new AttributeExpressionLanguageException("Invalid Expression: " + query + " due to " + explanation);
+ }
+
+ @Override
+ public String evaluateExpressions() throws ProcessException {
+ throw new AttributeExpressionLanguageException("Invalid Expression: " + query + " due to " + explanation);
+ }
+
+ @Override
+ public String evaluateExpressions(final AttributeValueDecorator decorator) throws ProcessException {
+ throw new AttributeExpressionLanguageException("Invalid Expression: " + query + " due to " + explanation);
+ }
+
+ @Override
+ public String evaluateExpressions(final FlowFile flowFile) throws ProcessException {
+ throw new AttributeExpressionLanguageException("Invalid Expression: " + query + " due to " + explanation);
+ }
+
+ @Override
+ public String evaluateExpressions(final Map<String, String> attributes) throws ProcessException {
+ throw new AttributeExpressionLanguageException("Invalid Expression: " + query + " due to " + explanation);
+ }
+
+ @Override
+ public String evaluateExpressions(final Map<String, String> attributes, final AttributeValueDecorator decorator) throws ProcessException {
+ throw new AttributeExpressionLanguageException("Invalid Expression: " + query + " due to " + explanation);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/8254b754/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/Query.java
----------------------------------------------------------------------
diff --git a/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/Query.java b/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/Query.java
index 6d9cc91..f4c1c0d 100644
--- a/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/Query.java
+++ b/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/Query.java
@@ -569,29 +569,33 @@ public class Query {
return new EmptyPreparedQuery(query.replace("$$", "$"));
}
- final List<String> substrings = new ArrayList<>();
- final Map<String, Tree> trees = new HashMap<>();
-
- int lastIndex = 0;
- for (final Range range : ranges) {
- if (range.getStart() > lastIndex) {
- substrings.add(query.substring(lastIndex, range.getStart()).replace("$$", "$"));
+ try {
+ final List<String> substrings = new ArrayList<>();
+ final Map<String, Tree> trees = new HashMap<>();
+
+ int lastIndex = 0;
+ for (final Range range : ranges) {
+ if (range.getStart() > lastIndex) {
+ substrings.add(query.substring(lastIndex, range.getStart()).replace("$$", "$"));
+ lastIndex = range.getEnd() + 1;
+ }
+
+ final String treeText = query.substring(range.getStart(), range.getEnd() + 1).replace("$$", "$");
+ substrings.add(treeText);
+ trees.put(treeText, Query.compileTree(treeText));
lastIndex = range.getEnd() + 1;
}
-
- final String treeText = query.substring(range.getStart(), range.getEnd() + 1).replace("$$", "$");
- substrings.add(treeText);
- trees.put(treeText, Query.compileTree(treeText));
- lastIndex = range.getEnd() + 1;
- }
-
- final Range lastRange = ranges.get(ranges.size() - 1);
- if (lastRange.getEnd() + 1 < query.length()) {
- final String treeText = query.substring(lastRange.getEnd() + 1).replace("$$", "$");
- substrings.add(treeText);
+
+ final Range lastRange = ranges.get(ranges.size() - 1);
+ if (lastRange.getEnd() + 1 < query.length()) {
+ final String treeText = query.substring(lastRange.getEnd() + 1).replace("$$", "$");
+ substrings.add(treeText);
+ }
+
+ return new StandardPreparedQuery(substrings, trees);
+ } catch (final AttributeExpressionLanguageParsingException e) {
+ return new InvalidPreparedQuery(query, e.getMessage());
}
-
- return new StandardPreparedQuery(substrings, trees);
}
public static Query compile(final String query) throws AttributeExpressionLanguageParsingException {
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/8254b754/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/exception/IllegalAttributeException.java
----------------------------------------------------------------------
diff --git a/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/exception/IllegalAttributeException.java b/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/exception/IllegalAttributeException.java
index 4a9a9c5..f6f32ca 100644
--- a/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/exception/IllegalAttributeException.java
+++ b/commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/exception/IllegalAttributeException.java
@@ -17,6 +17,7 @@
package org.apache.nifi.attribute.expression.language.exception;
public class IllegalAttributeException extends RuntimeException {
+ private static final long serialVersionUID = 12348721897342L;
public IllegalAttributeException() {
super();