org.apache.nifi.attribute.expression.language.Query类的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(77)

本文整理了Java中org.apache.nifi.attribute.expression.language.Query类的一些代码示例,展示了Query类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query类的具体详情如下:
包路径:org.apache.nifi.attribute.expression.language.Query
类名称:Query

Query介绍

[英]Class used for creating and evaluating NiFi Expression Language. Once a Query has been created, it may be evaluated using the evaluate methods exactly once.
[中]用于创建和评估NiFi表达式语言的类。一旦创建了一个查询,就可以使用evaluate方法对其进行一次计算。

代码示例

代码示例来源:origin: apache/nifi

@Override
public boolean isExpressionLanguagePresent(final String value) {
  if (value == null) {
    return false;
  }
  final List<Range> elRanges = Query.extractExpressionRanges(value);
  return (elRanges != null && !elRanges.isEmpty());
}

代码示例来源:origin: apache/nifi

public StandardPropertyValue(final String rawValue, final ControllerServiceLookup serviceLookup, final VariableRegistry variableRegistry) {
  this(rawValue, serviceLookup, Query.prepare(rawValue), variableRegistry);
}

代码示例来源:origin: apache/nifi

static String evaluateExpression(final Tree tree, final String queryText, final Map<String, String> valueMap, final AttributeValueDecorator decorator,
                 final Map<String, String> stateVariables) throws ProcessException {
  final Object evaluated = Query.fromTree(tree, queryText).evaluate(valueMap, stateVariables).getValue();
  if (evaluated == null) {
    return null;
  }
  final String value = evaluated.toString();
  return decorator == null ? value : decorator.decorate(value);
}

代码示例来源:origin: apache/nifi

public static ResultType getResultType(final String value) throws AttributeExpressionLanguageParsingException {
  return Query.compile(value).getResultType();
}

代码示例来源:origin: apache/nifi

public static List<ResultType> extractResultTypes(final String value) throws AttributeExpressionLanguageParsingException {
  final List<ResultType> types = new ArrayList<>();
  for (final Range range : extractExpressionRanges(value)) {
    final String text = value.substring(range.getStart(), range.getEnd() + 1);
    types.add(getResultType(text));
  }
  return types;
}

代码示例来源:origin: apache/nifi

final List<Range> ranges = extractExpressionRanges(query);
  return new EmptyPreparedQuery(unescape(query));
    final String treeText = unescapeLeadingDollarSigns(query.substring(range.getStart(), range.getEnd() + 1));
    final CompiledExpression compiledExpression = compiler.compile(treeText);
      String substring = unescapeLeadingDollarSigns(query.substring(lastIndex, range.getStart()));
        substring = unescapeTrailingDollarSigns(substring, false);
    final String treeText = unescapeLeadingDollarSigns(query.substring(lastRange.getEnd() + 1));
    expressions.add(new StringLiteralExpression(treeText));

代码示例来源:origin: apache/nifi

/**
 * @param value expression to validate
 * @param allowSurroundingCharacters whether to allow surrounding chars
 * @throws AttributeExpressionLanguageParsingException if problems parsing given expression
 */
public static void validateExpression(final String value, final boolean allowSurroundingCharacters) throws AttributeExpressionLanguageParsingException {
  if (!allowSurroundingCharacters) {
    final List<Range> ranges = extractExpressionRanges(value);
    if (ranges.size() > 1) {
      throw new AttributeExpressionLanguageParsingException("Found multiple Expressions but expected only 1");
    }
    if (ranges.isEmpty()) {
      throw new AttributeExpressionLanguageParsingException("No Expressions found");
    }
    final Range range = ranges.get(0);
    final String expression = value.substring(range.getStart(), range.getEnd() + 1);
    Query.compile(expression);
    if (range.getStart() > 0 || range.getEnd() < value.length() - 1) {
      throw new AttributeExpressionLanguageParsingException("Found characters outside of Expression");
    }
  } else {
    for (final Range range : extractExpressionRanges(value)) {
      final String expression = value.substring(range.getStart(), range.getEnd() + 1);
      Query.compile(expression);
    }
  }
}

代码示例来源:origin: apache/nifi

@Override
  public String evaluate(final FlowFile flowFile, final AttributeValueDecorator decorator) throws ProcessException {
    final ValueLookup lookup = new ValueLookup(variableRegistry, flowFile);
    final Object evaluationResult = query.evaluate(lookup).getValue();
    if (evaluationResult == null) {
      return "";
    }

    String result = evaluationResult.toString();
    if (decorator != null) {
      result = decorator.decorate(result);
    }
    return Query.unescape(result);
  }
}

代码示例来源:origin: stackoverflow.com

OCL ocl = OCL.newInstance(new PivotEnvironmentFactory());
OCLHelper helper = ocl.createOCLHelper(EXTLibraryPackage.Literals.LIBRARY);
ExpressionInOCL invariant = helper.createInvariant(
  "books->forAll(b1, b2 | b1 <> b2 implies b1.title <> b2.title)");
ExpressionInOCL query = helper.createQuery(
  "books->collect(b : Book | b.category)->asSet()");

// create a Query to evaluate our query expression
Query queryEval = ocl.createQuery(query);
// create another to check our constraint
Query constraintEval = ocl.createQuery(invariant);

List<Library> libraries = getLibraries();  // hypothetical source of libraries
// only print the set of book categories for valid libraries
for (Library next : libraries) {
  if (constraintEval.check(next)) {
   // the OCL result type of our query expression is Set(BookCategory)
   @SuppressWarnings("unchecked")
   Set<BookCategory> categories = (Set<BookCategory>) queryEval.evaluate(next);

   System.out.printf("%s: %s%n", next.getName(), categories);
  }
}

代码示例来源:origin: apache/nifi

QueryResult<?> evaluate(final Map<String, String> map) {
  return evaluate(map, null);
}

代码示例来源:origin: apache/nifi

public static Query fromTree(final Tree tree, final String text) {
  final ExpressionCompiler compiler = new ExpressionCompiler();
  return new Query(text, tree, compiler.buildEvaluator(tree));
}

代码示例来源:origin: apache/nifi

@Override
  public String evaluate(final Map<String, String> variables, final AttributeValueDecorator decorator, final Map<String, String> stateVariables) {
    return Query.evaluateExpression(getTree(), expression, variables, decorator, stateVariables);
  }
}

代码示例来源:origin: apache/nifi

@Override
public AttributeExpression compile(final String expression) throws IllegalArgumentException {
  try {
    return new StandardAttributeExpression(Query.compile(expression),variableRegistry);
  } catch (final AttributeExpressionLanguageParsingException e) {
    throw new IllegalArgumentException(e.getMessage());
  }
}

代码示例来源:origin: apache/nifi

public static Query compile(final String query) throws AttributeExpressionLanguageParsingException {
  try {
    final ExpressionCompiler compiler = new ExpressionCompiler();
    final CompiledExpression compiledExpression = compiler.compile(query);
    return new Query(compiledExpression.getExpression(), compiledExpression.getTree(), compiledExpression.getRootEvaluator());
  } catch (final AttributeExpressionLanguageParsingException e) {
    throw e;
  } catch (final Exception e) {
    throw new AttributeExpressionLanguageParsingException(e);
  }
}

代码示例来源:origin: apache/nifi

@Override
public boolean isExpressionLanguagePresent(final String value) {
  if (value == null) {
    return false;
  }
  final List<Range> elRanges = Query.extractExpressionRanges(value);
  return (elRanges != null && !elRanges.isEmpty());
}

代码示例来源:origin: apache/nifi

public StandardPropertyValue(final String rawValue, final ControllerServiceLookup serviceLookup) {
  this(rawValue, serviceLookup, Query.prepare(rawValue), VariableRegistry.EMPTY_REGISTRY);
}

代码示例来源:origin: apache/nifi

@Override
public boolean isExpressionLanguagePresent(final String value) {
  if (value == null) {
    return false;
  }
  final List<Range> elRanges = Query.extractExpressionRanges(value);
  return (elRanges != null && !elRanges.isEmpty());
}

代码示例来源:origin: apache/nifi

static String evaluateExpressions(final String rawValue, Map<String, String> expressionMap, final AttributeValueDecorator decorator, final Map<String, String> stateVariables)
    throws ProcessException {
  return Query.prepare(rawValue).evaluateExpressions(expressionMap, decorator, stateVariables);
}

代码示例来源:origin: apache/nifi

@Override
  public boolean isExpressionLanguagePresent() {
    if (!Boolean.TRUE.equals(expectExpressions)) {
      return false;
    }

    final List<Range> elRanges = Query.extractExpressionRanges(rawValue);
    return (elRanges != null && !elRanges.isEmpty());
  }
}

代码示例来源:origin: apache/nifi

@Override
public PropertyValue newPropertyValue(final String rawValue) {
  return new StandardPropertyValue(rawValue, controllerServiceProvider, Query.prepare(rawValue), variableRegistry);
}

相关文章