mirror of https://github.com/apache/nifi.git
NIFI-271 checkpoint
This commit is contained in:
parent
6d728406de
commit
afb4fe52b9
|
@ -27,6 +27,7 @@ import org.apache.nifi.provenance.lineage.LineageComputationType;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class AsyncLineageSubmission implements ComputeLineageSubmission {
|
public class AsyncLineageSubmission implements ComputeLineageSubmission {
|
||||||
|
|
||||||
private final String lineageIdentifier = UUID.randomUUID().toString();
|
private final String lineageIdentifier = UUID.randomUUID().toString();
|
||||||
private final Date submissionTime = new Date();
|
private final Date submissionTime = new Date();
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,6 @@ import java.util.concurrent.TimeUnit;
|
||||||
import org.apache.nifi.provenance.search.Query;
|
import org.apache.nifi.provenance.search.Query;
|
||||||
import org.apache.nifi.provenance.search.QuerySubmission;
|
import org.apache.nifi.provenance.search.QuerySubmission;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class AsyncQuerySubmission implements QuerySubmission {
|
public class AsyncQuerySubmission implements QuerySubmission {
|
||||||
|
|
||||||
public static final int TTL = (int) TimeUnit.MILLISECONDS.convert(60, TimeUnit.SECONDS);
|
public static final int TTL = (int) TimeUnit.MILLISECONDS.convert(60, TimeUnit.SECONDS);
|
||||||
|
@ -40,8 +37,8 @@ public class AsyncQuerySubmission implements QuerySubmission {
|
||||||
* number of steps, indicating how many results must be added to this
|
* number of steps, indicating how many results must be added to this
|
||||||
* AsyncQuerySubmission before it is considered finished
|
* AsyncQuerySubmission before it is considered finished
|
||||||
*
|
*
|
||||||
* @param query
|
* @param query the query to execute
|
||||||
* @param numSteps
|
* @param numSteps how many steps to include
|
||||||
*/
|
*/
|
||||||
public AsyncQuerySubmission(final Query query, final int numSteps) {
|
public AsyncQuerySubmission(final Query query, final int numSteps) {
|
||||||
this.query = query;
|
this.query = query;
|
||||||
|
|
|
@ -41,14 +41,21 @@ public class SearchableFields {
|
||||||
public static final SearchableField Details = new NamedSearchableField("Details", "details", "Details", false, SearchableFieldType.STRING);
|
public static final SearchableField Details = new NamedSearchableField("Details", "details", "Details", false, SearchableFieldType.STRING);
|
||||||
public static final SearchableField Relationship = new NamedSearchableField("Relationship", "relationship", "Relationship", false, SearchableFieldType.STRING);
|
public static final SearchableField Relationship = new NamedSearchableField("Relationship", "relationship", "Relationship", false, SearchableFieldType.STRING);
|
||||||
|
|
||||||
public static final SearchableField LineageStartDate = new NamedSearchableField("LineageStartDate", "lineageStartDate", "Lineage Start Date", false, SearchableFieldType.DATE);
|
public static final SearchableField LineageStartDate
|
||||||
public static final SearchableField LineageIdentifier = new NamedSearchableField("LineageIdentifiers", "lineageIdentifier", "Lineage Identifier", false, SearchableFieldType.STRING);
|
= new NamedSearchableField("LineageStartDate", "lineageStartDate", "Lineage Start Date", false, SearchableFieldType.DATE);
|
||||||
|
public static final SearchableField LineageIdentifier
|
||||||
|
= new NamedSearchableField("LineageIdentifiers", "lineageIdentifier", "Lineage Identifier", false, SearchableFieldType.STRING);
|
||||||
|
|
||||||
public static final SearchableField ContentClaimSection = new NamedSearchableField("ContentClaimSection", "contentClaimSection", "Content Claim Section", false, SearchableFieldType.STRING);
|
public static final SearchableField ContentClaimSection
|
||||||
public static final SearchableField ContentClaimContainer = new NamedSearchableField("ContentClaimContainer", "contentClaimContainer", "Content Claim Container", false, SearchableFieldType.STRING);
|
= new NamedSearchableField("ContentClaimSection", "contentClaimSection", "Content Claim Section", false, SearchableFieldType.STRING);
|
||||||
public static final SearchableField ContentClaimIdentifier = new NamedSearchableField("ContentClaimIdentifier", "contentClaimIdentifier", "Content Claim Identifier", false, SearchableFieldType.STRING);
|
public static final SearchableField ContentClaimContainer
|
||||||
public static final SearchableField ContentClaimOffset = new NamedSearchableField("ContentClaimOffset", "contentClaimOffset", "Content Claim Offset", false, SearchableFieldType.LONG);
|
= new NamedSearchableField("ContentClaimContainer", "contentClaimContainer", "Content Claim Container", false, SearchableFieldType.STRING);
|
||||||
public static final SearchableField SourceQueueIdentifier = new NamedSearchableField("SourceQueueIdentifier", "sourceQueueIdentifier", "Source Queue Identifier", false, SearchableFieldType.STRING);
|
public static final SearchableField ContentClaimIdentifier
|
||||||
|
= new NamedSearchableField("ContentClaimIdentifier", "contentClaimIdentifier", "Content Claim Identifier", false, SearchableFieldType.STRING);
|
||||||
|
public static final SearchableField ContentClaimOffset
|
||||||
|
= new NamedSearchableField("ContentClaimOffset", "contentClaimOffset", "Content Claim Offset", false, SearchableFieldType.LONG);
|
||||||
|
public static final SearchableField SourceQueueIdentifier
|
||||||
|
= new NamedSearchableField("SourceQueueIdentifier", "sourceQueueIdentifier", "Source Queue Identifier", false, SearchableFieldType.STRING);
|
||||||
|
|
||||||
private static final Map<String, SearchableField> standardFields;
|
private static final Map<String, SearchableField> standardFields;
|
||||||
|
|
||||||
|
|
|
@ -266,7 +266,8 @@ public class StandardLineageResult implements ComputeLineageResult {
|
||||||
final FlowFileNode childNode = new FlowFileNode(childUuid, record.getEventTime());
|
final FlowFileNode childNode = new FlowFileNode(childUuid, record.getEventTime());
|
||||||
final boolean isNewFlowFile = nodes.add(childNode);
|
final boolean isNewFlowFile = nodes.add(childNode);
|
||||||
if (!isNewFlowFile) {
|
if (!isNewFlowFile) {
|
||||||
final String msg = "Unable to generate Lineage Graph because multiple events were registered claiming to have generated the same FlowFile (UUID = " + childNode.getFlowFileUuid() + ")";
|
final String msg = "Unable to generate Lineage Graph because multiple "
|
||||||
|
+ "events were registered claiming to have generated the same FlowFile (UUID = " + childNode.getFlowFileUuid() + ")";
|
||||||
logger.error(msg);
|
logger.error(msg);
|
||||||
setError(msg);
|
setError(msg);
|
||||||
return;
|
return;
|
||||||
|
@ -293,7 +294,8 @@ public class StandardLineageResult implements ComputeLineageResult {
|
||||||
final LineageNode flowFileNode = new FlowFileNode(record.getFlowFileUuid(), record.getEventTime());
|
final LineageNode flowFileNode = new FlowFileNode(record.getFlowFileUuid(), record.getEventTime());
|
||||||
final boolean isNewFlowFile = nodes.add(flowFileNode);
|
final boolean isNewFlowFile = nodes.add(flowFileNode);
|
||||||
if (!isNewFlowFile) {
|
if (!isNewFlowFile) {
|
||||||
final String msg = "Found cycle in graph. This indicates that multiple events were registered claiming to have generated the same FlowFile (UUID = " + flowFileNode.getFlowFileUuid() + ")";
|
final String msg = "Found cycle in graph. This indicates that multiple events "
|
||||||
|
+ "were registered claiming to have generated the same FlowFile (UUID = " + flowFileNode.getFlowFileUuid() + ")";
|
||||||
setError(msg);
|
setError(msg);
|
||||||
logger.error(msg);
|
logger.error(msg);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -34,6 +34,13 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<excludes>**/antlr/AttributeExpressionParser.java,**/antlr/AttributeExpressionLexer.java</excludes>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
|
@ -23,13 +23,14 @@ import org.apache.nifi.expression.AttributeValueDecorator;
|
||||||
import org.apache.nifi.flowfile.FlowFile;
|
import org.apache.nifi.flowfile.FlowFile;
|
||||||
import org.apache.nifi.processor.exception.ProcessException;
|
import org.apache.nifi.processor.exception.ProcessException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of PreparedQuery that throws an {@link AttributeExpressionLanguageException} when attempting
|
* An implementation of PreparedQuery that throws an
|
||||||
* to evaluate the query. This allows a PreparedQuery to be created, even though it can't
|
* {@link AttributeExpressionLanguageException} when attempting to evaluate the
|
||||||
* be evaluated.
|
* query. This allows a PreparedQuery to be created, even though it can't be
|
||||||
|
* evaluated.
|
||||||
*/
|
*/
|
||||||
public class InvalidPreparedQuery implements PreparedQuery {
|
public class InvalidPreparedQuery implements PreparedQuery {
|
||||||
|
|
||||||
private final String query;
|
private final String query;
|
||||||
private final String explanation;
|
private final String explanation;
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,6 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.nifi.attribute.expression.language;
|
package org.apache.nifi.attribute.expression.language;
|
||||||
|
|
||||||
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.*;
|
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -116,6 +114,73 @@ import org.antlr.runtime.ANTLRStringStream;
|
||||||
import org.antlr.runtime.CharStream;
|
import org.antlr.runtime.CharStream;
|
||||||
import org.antlr.runtime.CommonTokenStream;
|
import org.antlr.runtime.CommonTokenStream;
|
||||||
import org.antlr.runtime.tree.Tree;
|
import org.antlr.runtime.tree.Tree;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.ALL_ATTRIBUTES;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.ALL_DELINEATED_VALUES;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.ALL_MATCHING_ATTRIBUTES;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.AND;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.ANY_ATTRIBUTE;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.ANY_DELINEATED_VALUE;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.ANY_MATCHING_ATTRIBUTE;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.APPEND;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.ATTRIBUTE_REFERENCE;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.ATTR_NAME;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.CONTAINS;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.COUNT;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.DIVIDE;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.ENDS_WITH;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.EQUALS;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.EQUALS_IGNORE_CASE;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.EXPRESSION;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.FALSE;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.FIND;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.FORMAT;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.GREATER_THAN;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.GREATER_THAN_OR_EQUAL;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.HOSTNAME;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.INDEX_OF;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.IP;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.IS_EMPTY;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.IS_NULL;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.JOIN;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.LAST_INDEX_OF;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.LENGTH;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.LESS_THAN;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.LESS_THAN_OR_EQUAL;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.MATCHES;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.MINUS;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.MOD;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.MULTIPLY;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.MULTI_ATTRIBUTE_REFERENCE;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.NEXT_INT;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.NOT;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.NOT_NULL;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.NOW;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.NUMBER;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.OR;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.PLUS;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.PREPEND;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.REPLACE;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.REPLACE_ALL;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.REPLACE_EMPTY;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.REPLACE_NULL;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.STARTS_WITH;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.STRING_LITERAL;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.SUBSTRING;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.SUBSTRING_AFTER;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.SUBSTRING_AFTER_LAST;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.SUBSTRING_BEFORE;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.SUBSTRING_BEFORE_LAST;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.TO_DATE;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.TO_LOWER;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.TO_NUMBER;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.TO_RADIX;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.TO_STRING;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.TO_UPPER;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.TRIM;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.TRUE;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.URL_DECODE;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.URL_ENCODE;
|
||||||
|
import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.UUID;
|
||||||
import org.apache.nifi.attribute.expression.language.evaluation.selection.MappingEvaluator;
|
import org.apache.nifi.attribute.expression.language.evaluation.selection.MappingEvaluator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -229,11 +294,9 @@ public class Query {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @param value expression to validate
|
||||||
*
|
* @param allowSurroundingCharacters whether to allow surrounding chars
|
||||||
* @param value
|
* @throws AttributeExpressionLanguageParsingException if problems parsing given expression
|
||||||
* @param allowSurroundingCharacters
|
|
||||||
* @throws AttributeExpressionLanguageParsingException
|
|
||||||
*/
|
*/
|
||||||
public static void validateExpression(final String value, final boolean allowSurroundingCharacters) throws AttributeExpressionLanguageParsingException {
|
public static void validateExpression(final String value, final boolean allowSurroundingCharacters) throws AttributeExpressionLanguageParsingException {
|
||||||
if (!allowSurroundingCharacters) {
|
if (!allowSurroundingCharacters) {
|
||||||
|
@ -333,8 +396,8 @@ public class Query {
|
||||||
/**
|
/**
|
||||||
* Un-escapes ${...} patterns that were escaped
|
* Un-escapes ${...} patterns that were escaped
|
||||||
*
|
*
|
||||||
* @param value
|
* @param value to un-escape
|
||||||
* @return
|
* @return un-escaped value
|
||||||
*/
|
*/
|
||||||
public static String unescape(final String value) {
|
public static String unescape(final String value) {
|
||||||
return value.replaceAll("\\$\\$(?=\\$*\\{.*?\\})", "\\$");
|
return value.replaceAll("\\$\\$(?=\\$*\\{.*?\\})", "\\$");
|
||||||
|
|
|
@ -49,9 +49,6 @@ public class GreaterThanEvaluator extends BooleanEvaluator {
|
||||||
return new BooleanQueryResult(subjectValue > comparisonValue);
|
return new BooleanQueryResult(subjectValue > comparisonValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Evaluator<?> getSubjectEvaluator() {
|
public Evaluator<?> getSubjectEvaluator() {
|
||||||
return subject;
|
return subject;
|
||||||
|
|
|
@ -49,9 +49,6 @@ public class GreaterThanOrEqualEvaluator extends BooleanEvaluator {
|
||||||
return new BooleanQueryResult(subjectValue >= comparisonValue);
|
return new BooleanQueryResult(subjectValue >= comparisonValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Evaluator<?> getSubjectEvaluator() {
|
public Evaluator<?> getSubjectEvaluator() {
|
||||||
return subject;
|
return subject;
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.nifi.attribute.expression.language.evaluation.Evaluator;
|
||||||
import org.apache.nifi.attribute.expression.language.evaluation.QueryResult;
|
import org.apache.nifi.attribute.expression.language.evaluation.QueryResult;
|
||||||
|
|
||||||
public class IsEmptyEvaluator extends BooleanEvaluator {
|
public class IsEmptyEvaluator extends BooleanEvaluator {
|
||||||
|
|
||||||
private final Evaluator<?> subjectEvaluator;
|
private final Evaluator<?> subjectEvaluator;
|
||||||
|
|
||||||
public IsEmptyEvaluator(final Evaluator<?> subjectEvaluator) {
|
public IsEmptyEvaluator(final Evaluator<?> subjectEvaluator) {
|
||||||
|
|
|
@ -49,9 +49,6 @@ public class LessThanEvaluator extends BooleanEvaluator {
|
||||||
return new BooleanQueryResult(subjectValue < comparisonValue);
|
return new BooleanQueryResult(subjectValue < comparisonValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Evaluator<?> getSubjectEvaluator() {
|
public Evaluator<?> getSubjectEvaluator() {
|
||||||
return subject;
|
return subject;
|
||||||
|
|
|
@ -49,9 +49,6 @@ public class LessThanOrEqualEvaluator extends BooleanEvaluator {
|
||||||
return new BooleanQueryResult(subjectValue <= comparisonValue);
|
return new BooleanQueryResult(subjectValue <= comparisonValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Evaluator<?> getSubjectEvaluator() {
|
public Evaluator<?> getSubjectEvaluator() {
|
||||||
return subject;
|
return subject;
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.nifi.attribute.expression.language.evaluation.QueryResult;
|
||||||
import org.apache.nifi.attribute.expression.language.evaluation.StringEvaluator;
|
import org.apache.nifi.attribute.expression.language.evaluation.StringEvaluator;
|
||||||
|
|
||||||
public class ReplaceEmptyEvaluator extends StringEvaluator {
|
public class ReplaceEmptyEvaluator extends StringEvaluator {
|
||||||
|
|
||||||
private final StringEvaluator subjectEvaluator;
|
private final StringEvaluator subjectEvaluator;
|
||||||
private final StringEvaluator replacementEvaluator;
|
private final StringEvaluator replacementEvaluator;
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ public class ReplaceEmptyEvaluator extends StringEvaluator {
|
||||||
final QueryResult<String> subjectResult = subjectEvaluator.evaluate(attributes);
|
final QueryResult<String> subjectResult = subjectEvaluator.evaluate(attributes);
|
||||||
final String subjectValue = subjectResult.getValue();
|
final String subjectValue = subjectResult.getValue();
|
||||||
final boolean isEmpty = subjectValue == null || subjectValue.toString().trim().isEmpty();
|
final boolean isEmpty = subjectValue == null || subjectValue.toString().trim().isEmpty();
|
||||||
if ( isEmpty ) {
|
if (isEmpty) {
|
||||||
return replacementEvaluator.evaluate(attributes);
|
return replacementEvaluator.evaluate(attributes);
|
||||||
} else {
|
} else {
|
||||||
return subjectResult;
|
return subjectResult;
|
||||||
|
|
|
@ -36,11 +36,11 @@ public class CountEvaluator extends NumberEvaluator implements ReduceEvaluator<L
|
||||||
@Override
|
@Override
|
||||||
public QueryResult<Long> evaluate(final Map<String, String> attributes) {
|
public QueryResult<Long> evaluate(final Map<String, String> attributes) {
|
||||||
final QueryResult<?> result = subjectEvaluator.evaluate(attributes);
|
final QueryResult<?> result = subjectEvaluator.evaluate(attributes);
|
||||||
if ( result.getValue() == null ) {
|
if (result.getValue() == null) {
|
||||||
return new NumberQueryResult(count);
|
return new NumberQueryResult(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( result.getResultType() == ResultType.BOOLEAN && ((Boolean) result.getValue()).equals(Boolean.FALSE) ) {
|
if (result.getResultType() == ResultType.BOOLEAN && ((Boolean) result.getValue()).equals(Boolean.FALSE)) {
|
||||||
return new NumberQueryResult(count);
|
return new NumberQueryResult(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.nifi.attribute.expression.language.evaluation.StringEvaluator;
|
||||||
import org.apache.nifi.attribute.expression.language.evaluation.StringQueryResult;
|
import org.apache.nifi.attribute.expression.language.evaluation.StringQueryResult;
|
||||||
|
|
||||||
public class JoinEvaluator extends StringEvaluator implements ReduceEvaluator<String> {
|
public class JoinEvaluator extends StringEvaluator implements ReduceEvaluator<String> {
|
||||||
|
|
||||||
private final StringEvaluator subjectEvaluator;
|
private final StringEvaluator subjectEvaluator;
|
||||||
private final StringEvaluator delimiterEvaluator;
|
private final StringEvaluator delimiterEvaluator;
|
||||||
|
|
||||||
|
@ -38,18 +39,18 @@ public class JoinEvaluator extends StringEvaluator implements ReduceEvaluator<St
|
||||||
@Override
|
@Override
|
||||||
public QueryResult<String> evaluate(final Map<String, String> attributes) {
|
public QueryResult<String> evaluate(final Map<String, String> attributes) {
|
||||||
String subject = subjectEvaluator.evaluate(attributes).getValue();
|
String subject = subjectEvaluator.evaluate(attributes).getValue();
|
||||||
if ( subject == null ) {
|
if (subject == null) {
|
||||||
subject = "";
|
subject = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
final String delimiter = delimiterEvaluator.evaluate(attributes).getValue();
|
final String delimiter = delimiterEvaluator.evaluate(attributes).getValue();
|
||||||
if ( evalCount > 0 ) {
|
if (evalCount > 0) {
|
||||||
sb.append(delimiter);
|
sb.append(delimiter);
|
||||||
}
|
}
|
||||||
sb.append(subject);
|
sb.append(subject);
|
||||||
|
|
||||||
evalCount++;
|
evalCount++;
|
||||||
return new StringQueryResult( sb.toString() );
|
return new StringQueryResult(sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.nifi.attribute.expression.language.evaluation.reduce.ReduceEva
|
||||||
import org.apache.nifi.expression.AttributeExpression.ResultType;
|
import org.apache.nifi.expression.AttributeExpression.ResultType;
|
||||||
|
|
||||||
public class MappingEvaluator<T> implements Evaluator<T> {
|
public class MappingEvaluator<T> implements Evaluator<T> {
|
||||||
|
|
||||||
private final ReduceEvaluator<T> mappingEvaluator;
|
private final ReduceEvaluator<T> mappingEvaluator;
|
||||||
private final MultiAttributeEvaluator multiAttributeEvaluator;
|
private final MultiAttributeEvaluator multiAttributeEvaluator;
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ public class MappingEvaluator<T> implements Evaluator<T> {
|
||||||
public QueryResult<T> evaluate(final Map<String, String> attributes) {
|
public QueryResult<T> evaluate(final Map<String, String> attributes) {
|
||||||
QueryResult<T> result = mappingEvaluator.evaluate(attributes);
|
QueryResult<T> result = mappingEvaluator.evaluate(attributes);
|
||||||
|
|
||||||
while ( multiAttributeEvaluator.getEvaluationsRemaining() > 0 ) {
|
while (multiAttributeEvaluator.getEvaluationsRemaining() > 0) {
|
||||||
result = mappingEvaluator.evaluate(attributes);
|
result = mappingEvaluator.evaluate(attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class MultiMatchAttributeEvaluator extends MultiAttributeEvaluator {
|
||||||
/**
|
/**
|
||||||
* Can be called only after the first call to evaluate
|
* Can be called only after the first call to evaluate
|
||||||
*
|
*
|
||||||
* @return
|
* @return number of remaining evaluations
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getEvaluationsRemaining() {
|
public int getEvaluationsRemaining() {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package org.apache.nifi.attribute.expression.language.exception;
|
package org.apache.nifi.attribute.expression.language.exception;
|
||||||
|
|
||||||
public class IllegalAttributeException extends RuntimeException {
|
public class IllegalAttributeException extends RuntimeException {
|
||||||
|
|
||||||
private static final long serialVersionUID = 12348721897342L;
|
private static final long serialVersionUID = 12348721897342L;
|
||||||
|
|
||||||
public IllegalAttributeException() {
|
public IllegalAttributeException() {
|
||||||
|
|
|
@ -78,7 +78,6 @@ public class TestQuery {
|
||||||
Query.validateExpression("${abc:substring(${xyz:length()})}", false);
|
Query.validateExpression("${abc:substring(${xyz:length()})}", false);
|
||||||
Query.isValidExpression("${now():format('yyyy-MM-dd')}");
|
Query.isValidExpression("${now():format('yyyy-MM-dd')}");
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Query.validateExpression("$${attr}", false);
|
Query.validateExpression("$${attr}", false);
|
||||||
Assert.fail("invalid query validated");
|
Assert.fail("invalid query validated");
|
||||||
|
@ -93,13 +92,12 @@ public class TestQuery {
|
||||||
+ ":or( ${filename:startsWith('KYM3ABC')} )}", false);
|
+ ":or( ${filename:startsWith('KYM3ABC')} )}", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCompileEmbedded() {
|
public void testCompileEmbedded() {
|
||||||
final String expression = "${x:equals( ${y} )}";
|
final String expression = "${x:equals( ${y} )}";
|
||||||
final Query query = Query.compile(expression);
|
final Query query = Query.compile(expression);
|
||||||
final Tree tree = query.getTree();
|
final Tree tree = query.getTree();
|
||||||
System.out.println( printTree(tree) );
|
System.out.println(printTree(tree));
|
||||||
|
|
||||||
final Map<String, String> attributes = new HashMap<>();
|
final Map<String, String> attributes = new HashMap<>();
|
||||||
attributes.put("x", "x");
|
attributes.put("x", "x");
|
||||||
|
@ -118,17 +116,17 @@ public class TestQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printTree(final Tree tree, final int spaces, final StringBuilder sb) {
|
private void printTree(final Tree tree, final int spaces, final StringBuilder sb) {
|
||||||
for (int i=0; i < spaces; i++) {
|
for (int i = 0; i < spaces; i++) {
|
||||||
sb.append(" ");
|
sb.append(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( tree.getText().trim().isEmpty() ) {
|
if (tree.getText().trim().isEmpty()) {
|
||||||
sb.append(tree.toString()).append("\n");
|
sb.append(tree.toString()).append("\n");
|
||||||
} else {
|
} else {
|
||||||
sb.append(tree.getText()).append("\n");
|
sb.append(tree.getText()).append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=0; i < tree.getChildCount(); i++) {
|
for (int i = 0; i < tree.getChildCount(); i++) {
|
||||||
printTree(tree.getChild(i), spaces + 2, sb);
|
printTree(tree.getChild(i), spaces + 2, sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,7 +172,6 @@ public class TestQuery {
|
||||||
assertEquals("'My Value", Query.evaluateExpressions("'${attr}", attributes, null));
|
assertEquals("'My Value", Query.evaluateExpressions("'${attr}", attributes, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Depends on TimeZone")
|
@Ignore("Depends on TimeZone")
|
||||||
public void testDateToNumber() {
|
public void testDateToNumber() {
|
||||||
|
@ -216,7 +213,6 @@ public class TestQuery {
|
||||||
assertEquals(formatted, result.getValue());
|
assertEquals(formatted, result.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmbeddedExpressionsAndQuotes() {
|
public void testEmbeddedExpressionsAndQuotes() {
|
||||||
final Map<String, String> attributes = new HashMap<>();
|
final Map<String, String> attributes = new HashMap<>();
|
||||||
|
@ -244,12 +240,11 @@ public class TestQuery {
|
||||||
verifyEquals("${allAttributes( 'x', 'y' ):join(',')}", attributes, ",");
|
verifyEquals("${allAttributes( 'x', 'y' ):join(',')}", attributes, ",");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=AttributeExpressionLanguageException.class)
|
@Test(expected = AttributeExpressionLanguageException.class)
|
||||||
public void testCannotCombineWithNonReducingFunction() {
|
public void testCannotCombineWithNonReducingFunction() {
|
||||||
Query.compileTree("${allAttributes( 'a.1' ):plus(1)}");
|
Query.compileTree("${allAttributes( 'a.1' ):plus(1)}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsEmpty() {
|
public void testIsEmpty() {
|
||||||
final Map<String, String> attributes = new HashMap<>();
|
final Map<String, String> attributes = new HashMap<>();
|
||||||
|
@ -263,7 +258,6 @@ public class TestQuery {
|
||||||
verifyEquals("${d:isEmpty()}", attributes, true);
|
verifyEquals("${d:isEmpty()}", attributes, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReplaceEmpty() {
|
public void testReplaceEmpty() {
|
||||||
final Map<String, String> attributes = new HashMap<>();
|
final Map<String, String> attributes = new HashMap<>();
|
||||||
|
@ -277,8 +271,6 @@ public class TestQuery {
|
||||||
verifyEquals("${d:replaceEmpty('c')}", attributes, "c");
|
verifyEquals("${d:replaceEmpty('c')}", attributes, "c");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCount() {
|
public void testCount() {
|
||||||
final Map<String, String> attributes = new HashMap<>();
|
final Map<String, String> attributes = new HashMap<>();
|
||||||
|
@ -291,10 +283,9 @@ public class TestQuery {
|
||||||
|
|
||||||
verifyEquals("${allMatchingAttributes( '.*' ):count()}", attributes, 6L);
|
verifyEquals("${allMatchingAttributes( '.*' ):count()}", attributes, 6L);
|
||||||
verifyEquals("${allMatchingAttributes( '.*' ):length():gt(2):count()}", attributes, 5L);
|
verifyEquals("${allMatchingAttributes( '.*' ):length():gt(2):count()}", attributes, 5L);
|
||||||
verifyEquals("${allMatchingAttributes( 'n.*' ):plus(1):count()}", attributes, 3L );
|
verifyEquals("${allMatchingAttributes( 'n.*' ):plus(1):count()}", attributes, 3L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCurlyBracesInQuotes() {
|
public void testCurlyBracesInQuotes() {
|
||||||
final Map<String, String> attributes = new HashMap<>();
|
final Map<String, String> attributes = new HashMap<>();
|
||||||
|
@ -304,7 +295,6 @@ public class TestQuery {
|
||||||
assertEquals("Val", evaluateQueryForEscape("${attr:replaceAll(\"My (Val)ue{1,2}\", '$1')}", attributes));
|
assertEquals("Val", evaluateQueryForEscape("${attr:replaceAll(\"My (Val)ue{1,2}\", '$1')}", attributes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String evaluateQueryForEscape(final String queryString, final Map<String, String> attributes) {
|
private String evaluateQueryForEscape(final String queryString, final Map<String, String> attributes) {
|
||||||
FlowFile mockFlowFile = Mockito.mock(FlowFile.class);
|
FlowFile mockFlowFile = Mockito.mock(FlowFile.class);
|
||||||
Mockito.when(mockFlowFile.getAttributes()).thenReturn(attributes);
|
Mockito.when(mockFlowFile.getAttributes()).thenReturn(attributes);
|
||||||
|
@ -316,7 +306,6 @@ public class TestQuery {
|
||||||
return Query.evaluateExpressions(queryString, mockFlowFile);
|
return Query.evaluateExpressions(queryString, mockFlowFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAttributeValue() {
|
public void testGetAttributeValue() {
|
||||||
final Map<String, String> attributes = new HashMap<>();
|
final Map<String, String> attributes = new HashMap<>();
|
||||||
|
@ -370,7 +359,6 @@ public class TestQuery {
|
||||||
verifyEquals("${x:or( ${${abc}:length():equals(1)} )}", attributes, true);
|
verifyEquals("${x:or( ${${abc}:length():equals(1)} )}", attributes, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExtractExpressionRanges() {
|
public void testExtractExpressionRanges() {
|
||||||
List<Range> ranges = Query.extractExpressionRanges("hello");
|
List<Range> ranges = Query.extractExpressionRanges("hello");
|
||||||
|
@ -416,7 +404,6 @@ public class TestQuery {
|
||||||
assertEquals(43, range.getStart());
|
assertEquals(43, range.getStart());
|
||||||
assertEquals(61, range.getEnd());
|
assertEquals(61, range.getEnd());
|
||||||
|
|
||||||
|
|
||||||
ranges = Query.extractExpressionRanges("${hello:equals( ${goodbye} )} or just hi, ${bob}, are you ${bob.age:toNumber()} yet? $$$${bob}");
|
ranges = Query.extractExpressionRanges("${hello:equals( ${goodbye} )} or just hi, ${bob}, are you ${bob.age:toNumber()} yet? $$$${bob}");
|
||||||
assertEquals(3, ranges.size());
|
assertEquals(3, ranges.size());
|
||||||
range = ranges.get(0);
|
range = ranges.get(0);
|
||||||
|
@ -438,7 +425,6 @@ public class TestQuery {
|
||||||
assertEquals(21, range.getEnd());
|
assertEquals(21, range.getEnd());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExtractExpressionTypes() {
|
public void testExtractExpressionTypes() {
|
||||||
List<ResultType> types = Query.extractResultTypes("${hello:equals( ${goodbye} )} or just hi, ${bob}, are you ${bob.age:toNumber()} yet? $$$${bob}");
|
List<ResultType> types = Query.extractResultTypes("${hello:equals( ${goodbye} )} or just hi, ${bob}, are you ${bob.age:toNumber()} yet? $$$${bob}");
|
||||||
|
@ -448,7 +434,6 @@ public class TestQuery {
|
||||||
assertEquals(ResultType.NUMBER, types.get(2));
|
assertEquals(ResultType.NUMBER, types.get(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEqualsEmbedded() {
|
public void testEqualsEmbedded() {
|
||||||
final Map<String, String> attributes = new HashMap<>();
|
final Map<String, String> attributes = new HashMap<>();
|
||||||
|
@ -475,7 +460,6 @@ public class TestQuery {
|
||||||
assertEquals("true", Query.evaluateExpressions("${x:equals( '${y}' )}", attributes, null));
|
assertEquals("true", Query.evaluateExpressions("${x:equals( '${y}' )}", attributes, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testComplicatedEmbeddedExpressions() {
|
public void testComplicatedEmbeddedExpressions() {
|
||||||
final Map<String, String> attributes = new HashMap<>();
|
final Map<String, String> attributes = new HashMap<>();
|
||||||
|
@ -552,7 +536,6 @@ public class TestQuery {
|
||||||
verifyEquals("${'A'}", attributes, "0123456789");
|
verifyEquals("${'A'}", attributes, "0123456789");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImplicitConversions() {
|
public void testImplicitConversions() {
|
||||||
final Map<String, String> attributes = new HashMap<>();
|
final Map<String, String> attributes = new HashMap<>();
|
||||||
|
@ -574,7 +557,6 @@ public class TestQuery {
|
||||||
final String dateString = cal.getTime().toString();
|
final String dateString = cal.getTime().toString();
|
||||||
attributes.put("z", dateString);
|
attributes.put("z", dateString);
|
||||||
|
|
||||||
|
|
||||||
verifyEquals("${A:plus(4)}", attributes, 123456793L);
|
verifyEquals("${A:plus(4)}", attributes, 123456793L);
|
||||||
verifyEquals("${A:plus( ${F} )}", attributes, 123456741L);
|
verifyEquals("${A:plus( ${F} )}", attributes, 123456741L);
|
||||||
|
|
||||||
|
@ -609,14 +591,14 @@ public class TestQuery {
|
||||||
final Map<String, String> attributes = new HashMap<>();
|
final Map<String, String> attributes = new HashMap<>();
|
||||||
attributes.put("abc", "xyz");
|
attributes.put("abc", "xyz");
|
||||||
|
|
||||||
final String expression =
|
final String expression
|
||||||
"# hello, world\n" +
|
= "# hello, world\n"
|
||||||
"${# ref attr\n" +
|
+ "${# ref attr\n"
|
||||||
"\t" +
|
+ "\t"
|
||||||
"abc" +
|
+ "abc"
|
||||||
"\t" +
|
+ "\t"
|
||||||
"#end ref attr\n" +
|
+ "#end ref attr\n"
|
||||||
"}";
|
+ "}";
|
||||||
|
|
||||||
Query query = Query.compile(expression);
|
Query query = Query.compile(expression);
|
||||||
QueryResult<?> result = query.evaluate(attributes);
|
QueryResult<?> result = query.evaluate(attributes);
|
||||||
|
@ -708,7 +690,6 @@ public class TestQuery {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReplaceAllWithOddNumberOfBackslashPairs() {
|
public void testReplaceAllWithOddNumberOfBackslashPairs() {
|
||||||
final Map<String, String> attributes = new HashMap<>();
|
final Map<String, String> attributes = new HashMap<>();
|
||||||
|
@ -805,7 +786,6 @@ public class TestQuery {
|
||||||
verifyEquals("${anyMatchingAttribute('123\\.c.*|a.c'):matches('zzz')}", attributes, true);
|
verifyEquals("${anyMatchingAttribute('123\\.c.*|a.c'):matches('zzz')}", attributes, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAnyDelineatedValue() {
|
public void testAnyDelineatedValue() {
|
||||||
final Map<String, String> attributes = new HashMap<>();
|
final Map<String, String> attributes = new HashMap<>();
|
||||||
|
@ -845,7 +825,6 @@ public class TestQuery {
|
||||||
verifyEquals("${allDelineatedValues(${abc}, ','):equals('a'):not()}", attributes, false);
|
verifyEquals("${allDelineatedValues(${abc}, ','):equals('a'):not()}", attributes, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAllAttributes() {
|
public void testAllAttributes() {
|
||||||
final Map<String, String> attributes = new HashMap<>();
|
final Map<String, String> attributes = new HashMap<>();
|
||||||
|
@ -868,7 +847,6 @@ public class TestQuery {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMathOperators() {
|
public void testMathOperators() {
|
||||||
final Map<String, String> attributes = new HashMap<>();
|
final Map<String, String> attributes = new HashMap<>();
|
||||||
|
@ -887,7 +865,7 @@ public class TestQuery {
|
||||||
attributes.put("hello", "world!");
|
attributes.put("hello", "world!");
|
||||||
attributes.put("123.cba", "hell.o");
|
attributes.put("123.cba", "hell.o");
|
||||||
|
|
||||||
System.out.println( printTree(Query.compile("${allMatchingAttributes('(abc|xyz)'):matches('\\\\d+')}").getTree()) );
|
System.out.println(printTree(Query.compile("${allMatchingAttributes('(abc|xyz)'):matches('\\\\d+')}").getTree()));
|
||||||
|
|
||||||
verifyEquals("${'123.cba':matches('hell\\.o')}", attributes, true);
|
verifyEquals("${'123.cba':matches('hell\\.o')}", attributes, true);
|
||||||
verifyEquals("${allMatchingAttributes('123\\.cba'):equals('hell.o')}", attributes, true);
|
verifyEquals("${allMatchingAttributes('123\\.cba'):equals('hell.o')}", attributes, true);
|
||||||
|
@ -917,7 +895,6 @@ public class TestQuery {
|
||||||
verifyEquals("${dotted:matches('abc\\.xyz')}", attributes, true);
|
verifyEquals("${dotted:matches('abc\\.xyz')}", attributes, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFind() {
|
public void testFind() {
|
||||||
final Map<String, String> attributes = new HashMap<>();
|
final Map<String, String> attributes = new HashMap<>();
|
||||||
|
@ -985,7 +962,6 @@ public class TestQuery {
|
||||||
attributes.put("filename", "file-255");
|
attributes.put("filename", "file-255");
|
||||||
attributes.put("filename2", "file-99999");
|
attributes.put("filename2", "file-99999");
|
||||||
|
|
||||||
|
|
||||||
verifyEquals("${filename:substringAfter('-'):toNumber():toRadix(16):toUpper()}", attributes, "FF");
|
verifyEquals("${filename:substringAfter('-'):toNumber():toRadix(16):toUpper()}", attributes, "FF");
|
||||||
verifyEquals("${filename:substringAfter('-'):toNumber():toRadix(16, 4):toUpper()}", attributes, "00FF");
|
verifyEquals("${filename:substringAfter('-'):toNumber():toRadix(16, 4):toUpper()}", attributes, "00FF");
|
||||||
verifyEquals("${filename:substringAfter('-'):toNumber():toRadix(36, 3):toUpper()}", attributes, "073");
|
verifyEquals("${filename:substringAfter('-'):toNumber():toRadix(36, 3):toUpper()}", attributes, "073");
|
||||||
|
@ -998,7 +974,6 @@ public class TestQuery {
|
||||||
verifyEquals("${blue:toDate('yyyyMMddHHmmss'):format(\"yyyy/MM/dd HH:mm:ss.SSS'Z'\")}", attributes, "2013/09/17 16:26:43.000Z");
|
verifyEquals("${blue:toDate('yyyyMMddHHmmss'):format(\"yyyy/MM/dd HH:mm:ss.SSS'Z'\")}", attributes, "2013/09/17 16:26:43.000Z");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNot() {
|
public void testNot() {
|
||||||
verifyEquals("${ab:notNull():not()}", new HashMap<String, String>(), true);
|
verifyEquals("${ab:notNull():not()}", new HashMap<String, String>(), true);
|
||||||
|
@ -1054,17 +1029,17 @@ public class TestQuery {
|
||||||
attributes.put("filename2", "yabc");
|
attributes.put("filename2", "yabc");
|
||||||
attributes.put("filename 3", "abcxy");
|
attributes.put("filename 3", "abcxy");
|
||||||
|
|
||||||
final String query =
|
final String query
|
||||||
"${" +
|
= "${"
|
||||||
" 'non-existing':notNull():not():and(" + // true AND (
|
+ " 'non-existing':notNull():not():and(" + // true AND (
|
||||||
" ${filename1:startsWith('y')" + // false
|
" ${filename1:startsWith('y')" + // false
|
||||||
" :or(" + // or
|
" :or(" + // or
|
||||||
" ${ filename1:startsWith('x'):and(false) }" + // false
|
" ${ filename1:startsWith('x'):and(false) }" + // false
|
||||||
" ):or(" + // or
|
" ):or(" + // or
|
||||||
" ${ filename2:endsWith('xxxx'):or( ${'filename 3':length():gt(1)} ) }" + // true )
|
" ${ filename2:endsWith('xxxx'):or( ${'filename 3':length():gt(1)} ) }" + // true )
|
||||||
" )}" +
|
" )}"
|
||||||
" )" +
|
+ " )"
|
||||||
"}";
|
+ "}";
|
||||||
|
|
||||||
System.out.println(query);
|
System.out.println(query);
|
||||||
verifyEquals(query, attributes, true);
|
verifyEquals(query, attributes, true);
|
||||||
|
@ -1130,9 +1105,9 @@ public class TestQuery {
|
||||||
Query query = Query.compile(expression);
|
Query query = Query.compile(expression);
|
||||||
QueryResult<?> result = query.evaluate(attributes);
|
QueryResult<?> result = query.evaluate(attributes);
|
||||||
|
|
||||||
if ( expectedResult instanceof Number ) {
|
if (expectedResult instanceof Number) {
|
||||||
assertEquals(ResultType.NUMBER, result.getResultType());
|
assertEquals(ResultType.NUMBER, result.getResultType());
|
||||||
} else if ( expectedResult instanceof Boolean ) {
|
} else if (expectedResult instanceof Boolean) {
|
||||||
assertEquals(ResultType.BOOLEAN, result.getResultType());
|
assertEquals(ResultType.BOOLEAN, result.getResultType());
|
||||||
} else {
|
} else {
|
||||||
assertEquals(ResultType.STRING, result.getResultType());
|
assertEquals(ResultType.STRING, result.getResultType());
|
||||||
|
|
|
@ -52,8 +52,8 @@ public class TestStandardPreparedQuery {
|
||||||
|
|
||||||
final StandardPreparedQuery prepared = (StandardPreparedQuery) Query.prepare("${xx}");
|
final StandardPreparedQuery prepared = (StandardPreparedQuery) Query.prepare("${xx}");
|
||||||
final long start = System.nanoTime();
|
final long start = System.nanoTime();
|
||||||
for (int i=0; i < 10000000; i++) {
|
for (int i = 0; i < 10000000; i++) {
|
||||||
assertEquals( "world", prepared.evaluateExpressions(attrs, null) );
|
assertEquals("world", prepared.evaluateExpressions(attrs, null));
|
||||||
}
|
}
|
||||||
final long nanos = System.nanoTime() - start;
|
final long nanos = System.nanoTime() - start;
|
||||||
System.out.println(TimeUnit.NANOSECONDS.toMillis(nanos));
|
System.out.println(TimeUnit.NANOSECONDS.toMillis(nanos));
|
||||||
|
@ -66,8 +66,8 @@ public class TestStandardPreparedQuery {
|
||||||
attrs.put("xx", "world");
|
attrs.put("xx", "world");
|
||||||
|
|
||||||
final long start = System.nanoTime();
|
final long start = System.nanoTime();
|
||||||
for (int i=0; i < 10000000; i++) {
|
for (int i = 0; i < 10000000; i++) {
|
||||||
assertEquals( "world", Query.evaluateExpressions("${xx}", attrs) );
|
assertEquals("world", Query.evaluateExpressions("${xx}", attrs));
|
||||||
}
|
}
|
||||||
final long nanos = System.nanoTime() - start;
|
final long nanos = System.nanoTime() - start;
|
||||||
System.out.println(TimeUnit.NANOSECONDS.toMillis(nanos));
|
System.out.println(TimeUnit.NANOSECONDS.toMillis(nanos));
|
||||||
|
|
Loading…
Reference in New Issue