org.apache.nifi.provenance.search.Query类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(12.9k)|赞(0)|评价(0)|浏览(275)

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

Query介绍

暂无

代码示例

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

  1. @Override
  2. public Optional<List<Long>> evaluate(final Query query) {
  3. if (latestRecords.getSize() < query.getMaxResults()) {
  4. return Optional.empty();
  5. }
  6. if (query.getSearchTerms().isEmpty() && query.getStartDate() == null && query.getEndDate() == null) {
  7. final List<Long> eventList = latestRecords.asList();
  8. if (eventList.size() > query.getMaxResults()) {
  9. return Optional.of(eventList.subList(0, query.getMaxResults()));
  10. } else {
  11. return Optional.of(eventList);
  12. }
  13. } else {
  14. return Optional.empty();
  15. }
  16. }

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

  1. @Override
  2. public String getQueryIdentifier() {
  3. return query.getIdentifier();
  4. }

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

  1. private void validate(final Query query) {
  2. final int numQueries = querySubmissionMap.size();
  3. if (numQueries > MAX_UNDELETED_QUERY_RESULTS) {
  4. purgeObsoleteQueries();
  5. if (querySubmissionMap.size() > MAX_UNDELETED_QUERY_RESULTS) {
  6. throw new IllegalStateException("Cannot process query because there are currently " + numQueries + " queries whose results have not "
  7. + "been deleted due to poorly behaving clients not issuing DELETE requests. Please try again later.");
  8. }
  9. }
  10. if (query.getEndDate() != null && query.getStartDate() != null && query.getStartDate().getTime() > query.getEndDate().getTime()) {
  11. throw new IllegalArgumentException("Query End Time cannot be before Query Start Time");
  12. }
  13. }

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

  1. requestDto.setStartDate(query.getStartDate());
  2. requestDto.setEndDate(query.getEndDate());
  3. requestDto.setMinimumFileSize(query.getMinFileSize());
  4. requestDto.setMaximumFileSize(query.getMaxFileSize());
  5. requestDto.setMaxResults(query.getMaxResults());
  6. if (query.getSearchTerms() != null) {
  7. final Map<String, String> searchTerms = new HashMap<>();
  8. for (final SearchTerm searchTerm : query.getSearchTerms()) {
  9. searchTerms.put(searchTerm.getSearchableField().getFriendlyName(), searchTerm.getValue());
  10. provenanceDto.setId(query.getIdentifier());
  11. provenanceDto.setSubmissionTime(querySubmission.getSubmissionTime());
  12. provenanceDto.setExpiration(queryResult.getExpiration());

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

  1. public static org.apache.lucene.search.Query convertQuery(final org.apache.nifi.provenance.search.Query query) {
  2. if (query.getStartDate() == null && query.getEndDate() == null && query.getSearchTerms().isEmpty()) {
  3. return new MatchAllDocsQuery();
  4. }
  5. final BooleanQuery luceneQuery = new BooleanQuery();
  6. for (final SearchTerm searchTerm : query.getSearchTerms()) {
  7. final String searchValue = searchTerm.getValue();
  8. if (searchValue == null) {
  9. throw new IllegalArgumentException("Empty search value not allowed (for term '" + searchTerm.getSearchableField().getFriendlyName() + "')");
  10. }
  11. if (searchValue.contains("*") || searchValue.contains("?")) {
  12. luceneQuery.add(new BooleanClause(new WildcardQuery(new Term(searchTerm.getSearchableField().getSearchableFieldName(), searchTerm.getValue().toLowerCase())), Occur.MUST));
  13. } else {
  14. luceneQuery.add(new BooleanClause(new TermQuery(new Term(searchTerm.getSearchableField().getSearchableFieldName(), searchTerm.getValue().toLowerCase())), Occur.MUST));
  15. }
  16. }
  17. final Long minBytes = query.getMinFileSize() == null ? null : DataUnit.parseDataSize(query.getMinFileSize(), DataUnit.B).longValue();
  18. final Long maxBytes = query.getMaxFileSize() == null ? null : DataUnit.parseDataSize(query.getMaxFileSize(), DataUnit.B).longValue();
  19. if (minBytes != null || maxBytes != null) {
  20. luceneQuery.add(NumericRangeQuery.newLongRange(SearchableFields.FileSize.getSearchableFieldName(), minBytes, maxBytes, true, true), Occur.MUST);
  21. }
  22. final Long minDateTime = query.getStartDate() == null ? null : query.getStartDate().getTime();
  23. final Long maxDateTime = query.getEndDate() == null ? null : query.getEndDate().getTime();
  24. if (maxDateTime != null || minDateTime != null) {
  25. luceneQuery.add(NumericRangeQuery.newLongRange(SearchableFields.EventTime.getSearchableFieldName(), minDateTime, maxDateTime, true, true), Occur.MUST);
  26. }
  27. return luceneQuery;
  28. }

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

  1. public StandardQueryResult search(final org.apache.nifi.provenance.search.Query provenanceQuery, final NiFiUser user, final AtomicInteger retrievedCount,
  2. final long firstEventTimestamp) throws IOException {
  3. if (retrievedCount.get() >= provenanceQuery.getMaxResults()) {
  4. final StandardQueryResult sqr = new StandardQueryResult(provenanceQuery, 1);
  5. sqr.update(Collections.<ProvenanceEventRecord> emptyList(), 0L);
  6. indexDirectory, provenanceQuery, provenanceQuery.getMaxResults());
  7. if (provenanceQuery.getStartDate() == null || provenanceQuery.getStartDate().getTime() < firstEventTimestamp) {
  8. provenanceQuery.setStartDate(new Date(firstEventTimestamp));
  9. if (provenanceQuery.getEndDate() == null) {
  10. provenanceQuery.setEndDate(new Date());
  11. final TopDocs topDocs = searcher.getIndexSearcher().search(luceneQuery, provenanceQuery.getMaxResults());
  12. final long finishSearch = System.nanoTime();
  13. final long searchNanos = finishSearch - searchStartNanos;
  14. provenanceQuery.getMaxResults(), maxAttributeChars);

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

  1. @Override
  2. public boolean isFinished() {
  3. readLock.lock();
  4. try {
  5. return numCompletedSteps >= numSteps || canceled || matchingRecords.size() >= query.getMaxResults();
  6. } finally {
  7. readLock.unlock();
  8. }
  9. }

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

  1. final Query query = new Query(provenanceDto.getId());
  2. field = SearchableFields.newSearchableAttribute(searchTerm.getKey());
  3. query.addSearchTerm(SearchTerms.newSearchTerm(field, searchTerm.getValue()));
  4. query.setStartDate(requestDto.getStartDate());
  5. query.setEndDate(requestDto.getEndDate());
  6. query.setMinFileSize(requestDto.getMinimumFileSize());
  7. query.setMaxFileSize(requestDto.getMaximumFileSize());
  8. query.setMaxResults(requestDto.getMaxResults());

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

  1. if (query.getStartDate() != null && query.getStartDate().getTime() > event.getEventTime()) {
  2. return false;
  3. if (query.getEndDate() != null && query.getEndDate().getTime() < event.getEventTime()) {
  4. return false;
  5. if (query.getMaxFileSize() != null) {
  6. final long maxFileSize = DataUnit.parseDataSize(query.getMaxFileSize(), DataUnit.B).longValue();
  7. if (event.getFileSize() > maxFileSize) {
  8. return false;
  9. if (query.getMinFileSize() != null) {
  10. final long minFileSize = DataUnit.parseDataSize(query.getMinFileSize(), DataUnit.B).longValue();
  11. if (event.getFileSize() < minFileSize) {
  12. return false;
  13. for (final SearchTerm searchTerm : query.getSearchTerms()) {
  14. final SearchableField searchableField = searchTerm.getSearchableField();
  15. final String searchValue = searchTerm.getValue();

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

  1. @Override
  2. public long getTotalHitCount() {
  3. readLock.lock();
  4. try {
  5. // Because we filter the results based on the user's permissions,
  6. // we don't want to indicate that the total hit count is 1,000+ when we
  7. // have 0 matching records, for instance. So, if we have fewer matching
  8. // records than the max specified by the query, it is either the case that
  9. // we truly don't have enough records to reach the max results, or that
  10. // the user is not authorized to see some of the results. Either way,
  11. // we want to report the number of events that we find AND that the user
  12. // is allowed to see, so we report matching record count, or up to max results.
  13. if (matchingRecords.size() < query.getMaxResults()) {
  14. return matchingRecords.size();
  15. } else {
  16. return query.getMaxResults();
  17. }
  18. } finally {
  19. readLock.unlock();
  20. }
  21. }

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

  1. @Override
  2. public QuerySubmission submitQuery(final Query query, final NiFiUser user) {
  3. if (query.getEndDate() != null && query.getStartDate() != null && query.getStartDate().getTime() > query.getEndDate().getTime()) {
  4. throw new IllegalArgumentException("Query End Time cannot be before Query Start Time");
  5. }
  6. final String userId = user == null ? null : user.getIdentity();
  7. if (query.getSearchTerms().isEmpty() && query.getStartDate() == null && query.getEndDate() == null) {
  8. final AsyncQuerySubmission result = new AsyncQuerySubmission(query, 1, userId);
  9. queryExecService.submit(new QueryRunnable(ringBuffer, createFilter(query, user), query.getMaxResults(), result));
  10. querySubmissionMap.put(query.getIdentifier(), result);
  11. return result;
  12. }
  13. final AsyncQuerySubmission result = new AsyncQuerySubmission(query, 1, userId);
  14. querySubmissionMap.put(query.getIdentifier(), result);
  15. queryExecService.submit(new QueryRunnable(ringBuffer, createFilter(query, user), query.getMaxResults(), result));
  16. return result;
  17. }

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

  1. if (matchingRecords.size() > query.getMaxResults()) {
  2. final Iterator<ProvenanceEventRecord> itr = matchingRecords.iterator();
  3. for (int i = 0; i < query.getMaxResults(); i++) {
  4. itr.next();
  5. updateExpiration();
  6. if (numCompletedSteps >= numSteps || this.matchingRecords.size() >= query.getMaxResults()) {
  7. final long searchNanos = System.nanoTime() - creationNanos;
  8. queryTime = TimeUnit.MILLISECONDS.convert(searchNanos, TimeUnit.NANOSECONDS);

代码示例来源:origin: org.apache.nifi/nifi-data-provenance-utils

  1. @Override
  2. public String getQueryIdentifier() {
  3. return query.getIdentifier();
  4. }

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

  1. @Override
  2. public Optional<List<Long>> evaluate(final Query query) {
  3. if (query.getMaxResults() > 1000) {
  4. // If query max results > 1000 then we know we don't have enough results. So just return empty.
  5. return Optional.empty();
  6. }
  7. final List<SearchTerm> terms = query.getSearchTerms();
  8. if (terms.size() != 1) {
  9. return Optional.empty();
  10. }
  11. final SearchTerm term = terms.get(0);
  12. if (!COMPONENT_ID_FIELD_NAME.equals(term.getSearchableField().getSearchableFieldName())) {
  13. return Optional.empty();
  14. }
  15. if (query.getEndDate() != null || query.getStartDate() != null) {
  16. return Optional.empty();
  17. }
  18. final RingBuffer<Long> ringBuffer = latestRecords.get(term.getValue());
  19. if (ringBuffer == null || ringBuffer.getSize() < query.getMaxResults()) {
  20. return Optional.empty();
  21. }
  22. List<Long> eventIds = ringBuffer.asList();
  23. if (eventIds.size() > query.getMaxResults()) {
  24. eventIds = eventIds.subList(0, query.getMaxResults());
  25. }
  26. return Optional.of(eventIds);
  27. }

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

  1. final int maxResults = query.getMaxResults();
  2. final long startIndex = Math.max(maxEventId - query.getMaxResults(), 0L);

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

  1. if (query.getEndDate() != null && query.getStartDate() != null && query.getStartDate().getTime() > query.getEndDate().getTime()) {
  2. throw new IllegalArgumentException("Query End Time cannot be before Query Start Time");
  3. if (query.getSearchTerms().isEmpty() && query.getStartDate() == null && query.getEndDate() == null) {
  4. final AsyncQuerySubmission result = new AsyncQuerySubmission(query, 1, userId);
  5. if (latestRecords.getSize() >= query.getMaxResults()) {
  6. final List<ProvenanceEventRecord> latestList = filterUnauthorizedEvents(latestRecords.asList(), user);
  7. final List<ProvenanceEventRecord> trimmed;
  8. if (latestList.size() > query.getMaxResults()) {
  9. trimmed = latestList.subList(latestList.size() - query.getMaxResults(), latestList.size());
  10. } else {
  11. trimmed = latestList;
  12. querySubmissionMap.put(query.getIdentifier(), result);
  13. return result;
  14. query.getStartDate() == null ? null : query.getStartDate().getTime(),
  15. query.getEndDate() == null ? null : query.getEndDate().getTime());
  16. final AsyncQuerySubmission result = new AsyncQuerySubmission(query, indexDirectories.size(), userId);
  17. querySubmissionMap.put(query.getIdentifier(), result);

代码示例来源:origin: org.apache.nifi/nifi-data-provenance-utils

  1. @Override
  2. public boolean isFinished() {
  3. readLock.lock();
  4. try {
  5. return numCompletedSteps >= numSteps || canceled || matchingRecords.size() >= query.getMaxResults();
  6. } finally {
  7. readLock.unlock();
  8. }
  9. }

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

  1. if (eventIdListOption.isPresent()) {
  2. final AsyncQuerySubmission submission = new AsyncQuerySubmission(query, 1, userId);
  3. querySubmissionMap.put(query.getIdentifier(), submission);
  4. query.getStartDate() == null ? null : query.getStartDate().getTime(),
  5. query.getEndDate() == null ? null : query.getEndDate().getTime());
  6. querySubmissionMap.put(query.getIdentifier(), submission);
  7. logger.debug("Submitting query {} with identifier {} against index directories {}", luceneQuery, query.getIdentifier(), indexDirectories);
  8. queryExecutor.submit(new QueryTask(luceneQuery, submission.getResult(), query.getMaxResults(), indexManager, indexDir,
  9. eventStore, authorizer, EventTransformer.EMPTY_TRANSFORMER));

代码示例来源:origin: org.apache.nifi/nifi-data-provenance-utils

  1. @Override
  2. public long getTotalHitCount() {
  3. readLock.lock();
  4. try {
  5. // Because we filter the results based on the user's permissions,
  6. // we don't want to indicate that the total hit count is 1,000+ when we
  7. // have 0 matching records, for instance. So, if we have fewer matching
  8. // records than the max specified by the query, it is either the case that
  9. // we truly don't have enough records to reach the max results, or that
  10. // the user is not authorized to see some of the results. Either way,
  11. // we want to report the number of events that we find AND that the user
  12. // is allowed to see, so we report matching record count, or up to max results.
  13. if (matchingRecords.size() < query.getMaxResults()) {
  14. return matchingRecords.size();
  15. } else {
  16. return query.getMaxResults();
  17. }
  18. } finally {
  19. readLock.unlock();
  20. }
  21. }

代码示例来源:origin: org.apache.nifi/nifi-data-provenance-utils

  1. if (matchingRecords.size() > query.getMaxResults()) {
  2. final Iterator<ProvenanceEventRecord> itr = matchingRecords.iterator();
  3. for (int i = 0; i < query.getMaxResults(); i++) {
  4. itr.next();
  5. updateExpiration();
  6. if (numCompletedSteps >= numSteps || this.matchingRecords.size() >= query.getMaxResults()) {
  7. final long searchNanos = System.nanoTime() - creationNanos;
  8. queryTime = TimeUnit.MILLISECONDS.convert(searchNanos, TimeUnit.NANOSECONDS);

相关文章