Ejemplo n.º 1
0
 /**
  * Returns a list of saved queries
  *
  * @param criteria a multivalued map that has the filter criteria
  * @param start Displacement from the start of the search result
  * @param count Count of number of records required
  * @return list of saved queries
  * @throws LensException
  */
 public ListResponse getList(MultivaluedMap<String, String> criteria, long start, long count)
     throws LensException {
   final StringBuilder selectQueryBuilder =
       new StringBuilder("select * from " + SAVED_QUERY_TABLE_NAME);
   final Set<String> availableFilterKeys = FILTER_KEYS.keySet();
   final Sets.SetView<String> intersection =
       Sets.intersection(availableFilterKeys, criteria.keySet());
   if (intersection.size() > 0) {
     final StringBuilder whereClauseBuilder = new StringBuilder(" where ");
     final List<String> predicates = Lists.newArrayList();
     for (String colName : intersection) {
       predicates.add(
           FILTER_KEYS.get(colName).resolveFilterExpression(colName, criteria.getFirst(colName)));
     }
     Joiner.on(" and ").skipNulls().appendTo(whereClauseBuilder, predicates);
     selectQueryBuilder.append(whereClauseBuilder.toString());
   }
   final String listCountQuery =
       "select count(*) as "
           + VALUE_ALIAS
           + " from ("
           + selectQueryBuilder.toString()
           + ") tmp_table";
   selectQueryBuilder.append(" limit ").append(start).append(", ").append(count);
   final String listQuery = selectQueryBuilder.toString();
   try {
     return new ListResponse(
         start,
         runner.query(listCountQuery, new SingleValuedResultHandler()),
         runner.query(listQuery, new SavedQueryResultSetHandler()));
   } catch (SQLException e) {
     throw new LensException("List query failed!", e);
   }
 }
Ejemplo n.º 2
0
  private static void mergeConfigMaps(
      final Map<String, String> source, final HashMap<String, String> destination) {
    checkNotNull(source, "source");
    checkNotNull(destination, "destination");

    if (source.isEmpty()) {
      return;
    }

    final Sets.SetView<String> sharedKeys =
        Sets.intersection(source.keySet(), destination.keySet());
    final Sets.SetView<String> newKeys = Sets.difference(source.keySet(), destination.keySet());

    // skip empty values in the source map
    // if they are already in the destination in order to
    // prevent overwrites of populated keys with empty ones
    sharedKeys
        .stream()
        .filter(key -> !source.get(key).trim().isEmpty() && !key.startsWith("#"))
        .forEach(key -> destination.put(key, source.get(key)));

    // Add new keys regardless of whether or not they're empty
    newKeys
        .stream()
        .filter(key -> !key.startsWith("#"))
        .forEach(key -> destination.put(key, source.get(key).trim()));
  }
 @Test
 @SuppressWarnings("unchecked")
 public void testExtraction() {
   StreamsDatum datum = new StreamsDatum(activity, "Test");
   List<StreamsDatum> result = new RegexHashtagExtractor().process(datum);
   assertThat(result.size(), is(equalTo(1)));
   Activity output = (Activity) result.get(0).getDocument();
   Set<String> extracted =
       (Set) ExtensionUtil.ensureExtensions(output).get(RegexHashtagExtractor.EXTENSION_KEY);
   Sets.SetView<String> diff = Sets.difference(extracted, hashtags);
   assertThat(diff.size(), is(equalTo(0)));
 }
Ejemplo n.º 4
0
  @Test
  public void testInitializationWithReservedFields() throws Exception {
    // This is madness!
    final Sets.SetView<String> fields =
        Sets.difference(Message.RESERVED_FIELDS, Message.RESERVED_SETTABLE_FIELDS);
    int errors = 0;

    for (String field : fields) {
      try {
        new TestExtractor.Builder().targetField(field).build();
      } catch (Extractor.ReservedFieldException e) {
        errors++;
      }
    }

    assertThat(errors).isEqualTo(fields.size());
  }
Ejemplo n.º 5
0
 private static Iterator<String> listCorruptTopologies() {
   Set<String> blobStoreTopologyIds =
       nimbusBlobStore.filterAndListKeys(
           new KeyFilter<String>() {
             @Override
             public String filter(String key) {
               return ConfigUtils.getIdFromBlobKey(key);
             }
           });
   Set<String> activeTopologyIds = new HashSet<>(stormClusterState.activeStorms());
   Sets.SetView<String> diffTopology = Sets.difference(activeTopologyIds, blobStoreTopologyIds);
   LOG.info(
       "active-topology-ids [{}] blob-topology-ids [{}] diff-topology [{}]",
       activeTopologyIds.toString(),
       blobStoreTopologyIds.toString(),
       diffTopology.toString());
   return diffTopology.iterator();
 }
    public Optional<Pair<RuleKey, ImmutableSet<SourcePath>>> build(
        Optional<ImmutableSet<SourcePath>> possibleDepFileSourcePaths,
        ImmutableList<DependencyFileEntry> depFileEntries)
        throws IOException {
      // TODO(jkeljo): Make this use possibleDepFileSourcePaths all the time
      Iterable<SourcePath> inputsSoFar = builder.getIterableInputsSoFar();
      // Dep file paths come as a sorted set, which does binary search instead of hashing for
      // lookups, so we re-create it as a hashset.
      ImmutableSet<SourcePath> fastPossibleSourcePaths =
          possibleDepFileSourcePaths.isPresent()
              ? ImmutableSet.copyOf(possibleDepFileSourcePaths.get())
              : ImmutableSet.copyOf(inputsSoFar);

      ImmutableSet<DependencyFileEntry> depFileEntriesSet = ImmutableSet.copyOf(depFileEntries);

      final ImmutableSet.Builder<SourcePath> depFileSourcePathsBuilder = ImmutableSet.builder();
      final ImmutableSet.Builder<DependencyFileEntry> filesAccountedFor = ImmutableSet.builder();

      // Each input path falls into one of three categories:
      // 1) It's not covered by dep files, so we need to consider it part of the rule key
      // 2) It's covered by dep files and present in the dep file, so we consider it
      //    part of the rule key
      // 3) It's covered by dep files but not present in the dep file, so we don't include it in
      //    the rule key (the benefit of dep file support is that lots of things fall in this
      //    category, so we can avoid rebuilds that would have happened with input-based rule keys)
      for (SourcePath input : inputsSoFar) {
        if (!fastPossibleSourcePaths.contains(input)) {
          // If this path is not a dep file path, then add it to the builder directly
          builder.addToRuleKey(input);
        } else {
          // If this input path is covered by the dep paths, check to see if it was declared
          // as a real dependency by the dep file entries
          DependencyFileEntry entry = DependencyFileEntry.fromSourcePath(input, pathResolver);
          if (depFileEntriesSet.contains(entry)) {
            builder.addToRuleKey(input);
            depFileSourcePathsBuilder.add(input);
            filesAccountedFor.add(entry);
          }
        }
      }

      Sets.SetView<DependencyFileEntry> filesUnaccountedFor =
          Sets.difference(depFileEntriesSet, filesAccountedFor.build());
      // If we don't find actual inputs in one of the rules that corresponded to the input, this
      // likely means that the rule changed to no longer use the input. In this case we need to
      // throw a `NoSuchFileException` so that the build engine handles this as a signal that the
      // dep file rule key cannot be used.
      if (!filesUnaccountedFor.isEmpty()) {
        throw new NoSuchFileException(
            String.format(
                "%s: could not find any inputs matching the relative paths [%s]",
                rule.getBuildTarget(), Joiner.on(',').join(filesUnaccountedFor)));
      }

      Optional<RuleKey> ruleKey = builder.build();
      if (ruleKey.isPresent()) {
        return Optional.of(new Pair<>(ruleKey.get(), depFileSourcePathsBuilder.build()));
      } else {
        return Optional.empty();
      }
    }