com.google.common.collect.SetMultimap Java Examples

The following examples show how to use com.google.common.collect.SetMultimap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: presto   Author: prestosql   File: UniformNodeSelector.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * The method selects and removes a split from the fromNode and assigns it to the toNode. There is an attempt to
 * redistribute a Non-local split if possible. This case is possible when there are multiple queries running
 * simultaneously. If a Non-local split cannot be found in the maxNode, any split is selected randomly and reassigned.
 */
@VisibleForTesting
public static void redistributeSplit(Multimap<InternalNode, Split> assignment, InternalNode fromNode, InternalNode toNode, SetMultimap<InetAddress, InternalNode> nodesByHost)
{
    Iterator<Split> splitIterator = assignment.get(fromNode).iterator();
    Split splitToBeRedistributed = null;
    while (splitIterator.hasNext()) {
        Split split = splitIterator.next();
        // Try to select non-local split for redistribution
        if (!split.getAddresses().isEmpty() && !isSplitLocal(split.getAddresses(), fromNode.getHostAndPort(), nodesByHost)) {
            splitToBeRedistributed = split;
            break;
        }
    }
    // Select any split if maxNode has no non-local splits in the current batch of assignment
    if (splitToBeRedistributed == null) {
        splitIterator = assignment.get(fromNode).iterator();
        splitToBeRedistributed = splitIterator.next();
    }
    splitIterator.remove();
    assignment.put(toNode, splitToBeRedistributed);
}
 
Example #2
Source Project: bazel-buildfarm   Author: bazelbuild   File: WorkerQueuesTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void gpuConfig_validProvisionsEnqueued() {

  // Arrange
  WorkerQueues queues = WorkerQueueConfigurations.gpu();

  // Act
  Operation operation = Operation.newBuilder().build();
  SetMultimap<String, String> provisions = HashMultimap.create();
  provisions.put("foo", "bar");
  provisions.put("gpu_required", "only key matters");
  provisions.put("another", "provision");
  boolean success = queues.enqueueOperation(operation, provisions);

  // Assert
  assertThat(success).isTrue();
  assertThat(queues.queueSize("GPU")).isEqualTo(1);
}
 
Example #3
Source Project: bazel   Author: bazelbuild   File: ConditionalEdges.java    License: Apache License 2.0 6 votes vote down vote up
/** Builds ConditionalEdges from given graph. */
public ConditionalEdges(Digraph<Target> graph) {
  this.map = new HashMap<>();

  for (Node<Target> node : graph.getNodes()) {
    Rule rule = node.getLabel().getAssociatedRule();
    if (rule == null) {
      // rule is null for source files and package groups. Skip them.
      continue;
    }

    SetMultimap<Label, Label> conditions = getAllConditions(rule, RawAttributeMapper.of(rule));
    if (conditions.isEmpty()) {
      // bail early for most common case of no conditions in the rule.
      continue;
    }

    Label nodeLabel = node.getLabel().getLabel();
    for (Node<Target> succ : node.getSuccessors()) {
      Label successorLabel = succ.getLabel().getLabel();
      if (conditions.containsKey(successorLabel)) {
        insert(nodeLabel, successorLabel, conditions.get(successorLabel));
      }
    }
  }
}
 
Example #4
Source Project: yangtools   Author: opendaylight   File: SchemaContextFactoryDeviationsTest.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private static ListenableFuture<EffectiveModelContext> createSchemaContext(
        final SetMultimap<QNameModule, QNameModule> modulesWithSupportedDeviations, final String... resources)
        throws Exception {
    final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository(
            "shared-schema-repo-with-deviations-test");

    final Collection<SourceIdentifier> requiredSources = new ArrayList<>();
    for (final String resource : resources) {
        final SettableSchemaProvider<ASTSchemaSource> yangSource = getImmediateYangSourceProviderFromResource(
                resource);
        yangSource.register(sharedSchemaRepository);
        yangSource.setResult();
        requiredSources.add(yangSource.getId());
    }

    final SchemaContextFactoryConfiguration config = SchemaContextFactoryConfiguration.builder()
            .setModulesDeviatedByModules(modulesWithSupportedDeviations).build();
    return sharedSchemaRepository.createEffectiveModelContextFactory(config).createEffectiveModelContext(
        requiredSources);
}
 
Example #5
Source Project: pushfish-android   Author: PushFish   File: TaskSelector.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
public TaskSelection getSelection(String path) {
    SetMultimap<String, TaskSelectionResult> tasksByName;
    ProjectInternal project = gradle.getDefaultProject();
    ResolvedTaskPath taskPath = taskPathResolver.resolvePath(path, project);

    if (taskPath.isQualified()) {
        tasksByName = taskNameResolver.select(taskPath.getTaskName(), taskPath.getProject());
    } else {
        tasksByName = taskNameResolver.selectAll(taskPath.getTaskName(), taskPath.getProject());
    }

    Set<TaskSelectionResult> tasks = tasksByName.get(taskPath.getTaskName());
    if (!tasks.isEmpty()) {
        // An exact match
        return new TaskSelection(path, tasks);
    }

    NameMatcher matcher = new NameMatcher();
    String actualName = matcher.find(taskPath.getTaskName(), tasksByName.keySet());
    if (actualName != null) {
        return new TaskSelection(taskPath.getPrefix() + actualName, tasksByName.get(actualName));
    }

    throw new TaskSelectionException(matcher.formatErrorMessage("task", taskPath.getProject()));
}
 
Example #6
Source Project: xtext-eclipse   Author: eclipse   File: BuilderParticipant.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.12
 */
protected Map<OutputConfiguration, Iterable<IMarker>> buildGeneratorMarkersReverseLookupMap(Map<OutputConfiguration, Iterable<IMarker>> generatorMarkers) {
	SetMultimap<String, IFile> reverseLookupMap = HashMultimap.create();
	for (java.util.Map.Entry<OutputConfiguration, Iterable<IMarker>> entry : generatorMarkers.entrySet()) {
		OutputConfiguration outputConfiguration = entry.getKey();
		if (outputConfiguration.isCleanUpDerivedResources()) {
			for (IMarker marker : entry.getValue()) {
				String source = derivedResourceMarkers.getSource(marker);
				if (source != null) {
					reverseLookupMap.put(source, (IFile) marker.getResource());
				}
			}
		}
	}
	return new DerivedResourcesLookupMap(generatorMarkers, reverseLookupMap);
}
 
Example #7
Source Project: sqlitemagic   Author: SiimKinks   File: Environment.java    License: Apache License 2.0 6 votes vote down vote up
private static void getLocalAndInheritedMethods(PackageElement pkg,
                                                TypeElement type,
                                                SetMultimap<String, ExecutableElement> methods,
                                                ConditionCallback<ExecutableElement> includeMethodCallback) {
  for (TypeMirror superInterface : type.getInterfaces()) {
    final TypeElement superInterfaceElement = asTypeElement(superInterface);
    final String interfaceName = superInterfaceElement.getSimpleName().toString();
    if (interfaceName.startsWith("Parcelable")) continue;

    getLocalAndInheritedMethods(pkg, superInterfaceElement, methods, includeMethodCallback);
  }
  if (type.getSuperclass().getKind() != TypeKind.NONE) {
    // Visit the superclass after superinterfaces so we will always see the implementation of a
    // method after any interfaces that declared it.
    getLocalAndInheritedMethods(pkg, asTypeElement(type.getSuperclass()), methods, includeMethodCallback);
  }
  for (ExecutableElement method : ElementFilter.methodsIn(type.getEnclosedElements())) {
    if (includeMethodCallback.call(method)
        && visibleFromPackage(method, pkg)) {
      methods.put(method.getSimpleName().toString(), method);
    }
  }
}
 
Example #8
Source Project: bioasq   Author: oaqa   File: ChoiceCavGenerator.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public List<CandidateAnswerVariant> generate(JCas jcas) throws AnalysisEngineProcessException {
  List<Token> tokens = TypeUtil.getOrderedTokens(jcas);
  SetMultimap<Token, Token> head2children = CavUtil.getHeadTokenMap(tokens);
  Token orToken;
  try {
    orToken = tokens.stream().filter(t -> OR_LEMMA.equals(t.getLemmaForm())).findAny().get();
  } catch (NoSuchElementException e) {
    return new ArrayList<>();
  }
  // identify head tokens for choices from the question
  Token mainToken = orToken.getHead();
  List<Token> alternativeTokens = head2children.get(mainToken).stream()
          .filter(t -> CONJ_DEP_LABEL.equals(t.getDepLabel())).collect(toList());
  List<CandidateAnswerVariant> cavs = Stream
          .concat(Stream.of(mainToken), alternativeTokens.stream())
          .map(token -> CavUtil.createCandidateAnswerVariant(jcas, token)).collect(toList());
  // find CAVs from evidence passages
  Stream.concat(Stream.of(mainToken), alternativeTokens.stream())
          .map(token -> JCasUtil.selectCovering(ConceptMention.class, token))
          .flatMap(Collection::stream).map(ConceptMention::getConcept)
          .map(concept -> CavUtil.createCandidateAnswerVariant(jcas, concept)).forEach(cavs::add);
  return cavs;
}
 
Example #9
Source Project: consultant   Author: Magnetme   File: Consultant.java    License: Apache License 2.0 6 votes vote down vote up
private Consultant(ScheduledExecutorService executor, ObjectMapper mapper, URI consulUri,
		ServiceIdentifier identifier, SetMultimap<String, SettingListener> settingListeners,
		Set<ConfigListener> configListeners, ConfigValidator validator, CloseableHttpClient http,
		boolean pullConfig, String healthEndpoint, String kvPrefix, long whenLocatingServicesCacheResultsFor) {

	this.registered = new AtomicBoolean();
	this.settingListeners = Multimaps.synchronizedSetMultimap(settingListeners);
	this.configListeners = Sets.newConcurrentHashSet(configListeners);
	this.serviceInstanceBackend = new ServiceInstanceBackend(identifier.getDatacenter(), consulUri, mapper, http,
			whenLocatingServicesCacheResultsFor);

	this.mapper = mapper;
	this.validator = validator;
	this.executor = executor;
	this.consulUri = consulUri;
	this.id = identifier;
	this.pullConfig = pullConfig;
	this.validated = new Properties();
	this.healthEndpoint = healthEndpoint;
	this.http = http;
	this.kvPrefix = kvPrefix;
}
 
Example #10
Source Project: batfish   Author: batfish   File: IpsecUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns all {@link IpsecPeerConfigId}s whose local IP is equal to any of the IPs behind
 * destinationIp after NAT
 */
@Nonnull
private static Set<IpsecPeerConfigId> getCandidatePeersBehindNat(
    @Nonnull Ip destinationIp,
    @Nonnull SetMultimap<Ip, IpWildcardSetIpSpace> privateIpsByPublicIp,
    @Nonnull Map<Ip, Set<IpsecPeerConfigId>> localIpsAndIpsecPeers) {
  ImmutableSet.Builder<IpsecPeerConfigId> candidateNeighbors = ImmutableSet.builder();
  Set<IpWildcardSetIpSpace> privateIpsBehindDestIp = privateIpsByPublicIp.get(destinationIp);
  if (privateIpsBehindDestIp == null) {
    return candidateNeighbors.build();
  }
  for (IpWildcardSetIpSpace ipWildcardSetIpSpace : privateIpsBehindDestIp) {
    for (Entry<Ip, Set<IpsecPeerConfigId>> entry : localIpsAndIpsecPeers.entrySet()) {
      if (ipWildcardSetIpSpace.containsIp(entry.getKey(), ImmutableMap.of())) {
        candidateNeighbors.addAll(entry.getValue());
      }
    }
  }
  return candidateNeighbors.build();
}
 
Example #11
Source Project: FreeBuilder   Author: inferred   File: SetMultimapPropertyTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGet_returnsLiveView() {
  behaviorTester
      .with(new Processor(features))
      .with(dataType)
      .with(testBuilder()
          .addLine("DataType.Builder builder = new DataType.Builder();")
          .addLine("%s<%s, %s> itemsView = builder.%s;",
              SetMultimap.class, key.type(), value.type(), convention.get("items"))
          .addLine("assertThat(itemsView).isEmpty();")
          .addLine("builder.putItems(%s, %s);", key.example(0), value.example(1))
          .addLine("assertThat(itemsView).contains(%s, %s).andNothingElse();",
              key.example(0), value.example(1))
          .addLine("builder.clearItems();")
          .addLine("assertThat(itemsView).isEmpty();")
          .addLine("builder.putItems(%s, %s);", key.example(2), value.example(3))
          .addLine("assertThat(itemsView).contains(%s, %s).andNothingElse();",
              key.example(2), value.example(3))
          .build())
      .runTest();
}
 
Example #12
Source Project: ProjectAres   Author: OvercastNetwork   File: DisableDamageModule.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
public static DisableDamageModule parse(MapModuleContext context, Logger logger, Document doc) throws InvalidXMLException {
    SetMultimap<DamageCause, PlayerRelation> causes = HashMultimap.create();
    for(Element damageCauseElement : doc.getRootElement().getChildren("disabledamage")) {
        for(Element damageEl : damageCauseElement.getChildren("damage")) {
            DamageCause cause = XMLUtils.parseEnum(damageEl, DamageCause.class, "damage type");
            for(PlayerRelation damagerType : PlayerRelation.values()) {
                // Legacy syntax used "other" instead of "neutral"
                String attrName = damagerType.name().toLowerCase();
                Node attr = damagerType == PlayerRelation.NEUTRAL ? Node.fromAttr(damageEl, attrName, "other")
                                                                  : Node.fromAttr(damageEl, attrName);
                if(XMLUtils.parseBoolean(attr, true)) {
                    causes.put(cause, damagerType);

                    // Bukkit 1.7.10 changed TNT from BLOCK_EXPLOSION to ENTITY_EXPLOSION,
                    // so we include them both to keep old maps working.
                    if(cause == DamageCause.BLOCK_EXPLOSION) {
                        causes.put(DamageCause.ENTITY_EXPLOSION, damagerType);
                    }
                }
            }
        }
    }
    return new DisableDamageModule(causes);
}
 
Example #13
Source Project: ProjectAres   Author: OvercastNetwork   File: TargetedEventBusImpl.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@Inject TargetedEventBusImpl(ExceptionHandler exceptionHandler, EventRegistry eventRegistry, TargetedEventHandlerScanner eventHandlerScanner, TypeMap<Object, TargetedEventRouter<?>> routers) {
    this.exceptionHandler = exceptionHandler;
    this.eventRegistry = eventRegistry;
    this.routers = routers;

    // Cache of handler methods per listener type
    this.listenerCache = CacheUtils.newCache(listener -> {
        final SetMultimap<EventKey<? extends Event>, EventHandlerInfo<? extends Event>> handlers = eventHandlerScanner.findEventHandlers(listener);
        for(EventHandlerInfo<? extends Event> info : handlers.values()) {
            if(this.routers.allAssignableFrom(info.event()).isEmpty()) {
                throw new InvalidMemberException(
                    info.method(),
                    "No router registered for targeted event type " + info.event().getName()
                );
            }
        }
        return handlers;
    });
}
 
Example #14
Source Project: glowroot   Author: glowroot   File: ClasspathCache.java    License: Apache License 2.0 6 votes vote down vote up
synchronized void updateCache() {
    Multimap<String, Location> newClassNameLocations = HashMultimap.create();
    for (ClassLoader loader : getKnownClassLoaders()) {
        updateCache(loader, newClassNameLocations);
    }
    updateCacheWithClasspathClasses(newClassNameLocations);
    updateCacheWithBootstrapClasses(newClassNameLocations);
    if (!newClassNameLocations.isEmpty()) {
        // multimap that sorts keys and de-dups values while maintains value ordering
        SetMultimap<String, Location> newMap =
                MultimapBuilder.treeKeys().linkedHashSetValues().build();
        newMap.putAll(classNameLocations);
        newMap.putAll(newClassNameLocations);
        classNameLocations = ImmutableMultimap.copyOf(newMap);
    }
}
 
Example #15
Source Project: cm_ext   Author: cloudera   File: ReferenceValidatorImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void beforeNode(Object obj, DescriptorPath path) {
  Preconditions.checkState(!refsStack.containsKey(path));

  SetMultimap<ReferenceType, String> refs = getRelatedPaths(obj, path);
  SetMultimap<ReferenceType, String> newRefs = LinkedHashMultimap.create();

  for (Map.Entry<ReferenceType, Collection<String>> entry : refs.asMap().entrySet()) {
    ReferenceType type = entry.getKey();
    for (String reference : entry.getValue()) {
      if (!allowedRefs.containsEntry(type, reference)) {
        newRefs.put(type, reference);
        allowedRefs.put(type, reference);
      }
    }
  }

  // consolidate into the singleton if it's empty
  newRefs = newRefs.size() == 0 ? ImmutableSetMultimap
      .<ReferenceType, String> of() : newRefs;
  refsStack.put(path, newRefs);

  callReferenceConstraints(obj, path);
}
 
Example #16
Source Project: brooklyn-server   Author: apache   File: FunctionFeed.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void preStart() {
    SetMultimap<FunctionPollIdentifier, FunctionPollConfig<?, ?>> polls = getConfig(POLLS);
    for (final FunctionPollIdentifier pollInfo : polls.keySet()) {
        Set<FunctionPollConfig<?,?>> configs = polls.get(pollInfo);
        long minPeriod = Integer.MAX_VALUE;
        Set<AttributePollHandler<?>> handlers = Sets.newLinkedHashSet();

        for (FunctionPollConfig<?,?> config : configs) {
            handlers.add(new AttributePollHandler(config, entity, this));
            if (config.getPeriod() > 0) minPeriod = Math.min(minPeriod, config.getPeriod());
        }
        
        getPoller().scheduleAtFixedRate(
                (Callable)pollInfo.job,
                new DelegatingPollHandler(handlers), 
                minPeriod);
    }
}
 
Example #17
Source Project: docker-java   Author: docker-java   File: DefaultDockerCmdExecFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public DefaultWebTarget queryParamsSet(String name, Set<?> values) {
    SetMultimap<String, String> newQueryParams = HashMultimap.create(queryParams);
    newQueryParams.replaceValues(name, values.stream().filter(Objects::nonNull).map(Object::toString).collect(Collectors.toSet()));

    return new DefaultWebTarget(path, newQueryParams);
}
 
Example #18
Source Project: EclipseCodeFormatter   Author: krasa   File: XBAR.java    License: Apache License 2.0 5 votes vote down vote up
public static void bar() {
	new XAAA();
	aaa();
	new XFOO();
	foo();

	SetMultimap<Object, Object> objectObjectSetMultimap = forMap(new HashMap<Object, Object>());
	IMocksControl control = createControl();
	List s = new ArrayList();

}
 
Example #19
Source Project: gef   Author: eclipse   File: SetMultimapExpression.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void clear() {
	final SetMultimap<K, V> setMultimap = get();
	if (setMultimap == null) {
		EMPTY_SETMULTIMAP.clear();
	} else {
		setMultimap.clear();
	}
}
 
Example #20
Source Project: glowroot   Author: glowroot   File: Transaction.java    License: Apache License 2.0 5 votes vote down vote up
public SetMultimap<String, String> getAttributes() {
    synchronized (attributesLock) {
        if (attributes == null) {
            return ImmutableSetMultimap.of();
        }
        SetMultimap<String, String> orderedAttributes = TreeMultimap.create();
        orderedAttributes.putAll(attributes);
        return orderedAttributes;
    }
}
 
Example #21
Source Project: presto   Author: prestosql   File: TestRaptorIntegrationSmokeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testShardingByTemporalDateColumn()
{
    // Make sure we have at least 2 different orderdate.
    assertEquals(computeActual("SELECT count(DISTINCT orderdate) >= 2 FROM orders WHERE orderdate < date '1992-02-08'").getOnlyValue(), true);

    assertUpdate("CREATE TABLE test_shard_temporal_date " +
                    "WITH (temporal_column = 'orderdate') AS " +
                    "SELECT orderdate, orderkey " +
                    "FROM orders " +
                    "WHERE orderdate < date '1992-02-08'",
            "SELECT count(*) " +
                    "FROM orders " +
                    "WHERE orderdate < date '1992-02-08'");

    MaterializedResult results = computeActual("SELECT orderdate, \"$shard_uuid\" FROM test_shard_temporal_date");

    // Each shard will only contain data of one date.
    SetMultimap<String, LocalDate> shardDateMap = HashMultimap.create();
    for (MaterializedRow row : results.getMaterializedRows()) {
        shardDateMap.put((String) row.getField(1), (LocalDate) row.getField(0));
    }

    for (Collection<LocalDate> dates : shardDateMap.asMap().values()) {
        assertEquals(dates.size(), 1);
    }

    // Make sure we have all the rows
    assertQuery("SELECT orderdate, orderkey FROM test_shard_temporal_date",
            "SELECT orderdate, orderkey FROM orders WHERE orderdate < date '1992-02-08'");
}
 
Example #22
Source Project: presto   Author: prestosql   File: TestRaptorIntegrationSmokeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testShardingByTemporalDateColumnBucketed()
{
    // Make sure we have at least 2 different orderdate.
    assertEquals(computeActual("SELECT count(DISTINCT orderdate) >= 2 FROM orders WHERE orderdate < date '1992-02-08'").getOnlyValue(), true);

    assertUpdate("CREATE TABLE test_shard_temporal_date_bucketed " +
                    "WITH (temporal_column = 'orderdate', bucket_count = 10, bucketed_on = ARRAY ['orderkey']) AS " +
                    "SELECT orderdate, orderkey " +
                    "FROM orders " +
                    "WHERE orderdate < date '1992-02-08'",
            "SELECT count(*) " +
                    "FROM orders " +
                    "WHERE orderdate < date '1992-02-08'");

    MaterializedResult results = computeActual("SELECT orderdate, \"$shard_uuid\" FROM test_shard_temporal_date_bucketed");

    // Each shard will only contain data of one date.
    SetMultimap<String, LocalDate> shardDateMap = HashMultimap.create();
    for (MaterializedRow row : results.getMaterializedRows()) {
        shardDateMap.put((String) row.getField(1), (LocalDate) row.getField(0));
    }

    for (Collection<LocalDate> dates : shardDateMap.asMap().values()) {
        assertEquals(dates.size(), 1);
    }

    // Make sure we have all the rows
    assertQuery("SELECT orderdate, orderkey FROM test_shard_temporal_date_bucketed",
            "SELECT orderdate, orderkey FROM orders WHERE orderdate < date '1992-02-08'");
}
 
Example #23
Source Project: presto   Author: prestosql   File: TestRaptorIntegrationSmokeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testShardingByTemporalTimestampColumnBucketed()
{
    assertUpdate("" +
            "CREATE TABLE test_shard_temporal_timestamp_bucketed(col1 BIGINT, col2 TIMESTAMP) " +
            "WITH (temporal_column = 'col2', bucket_count = 3, bucketed_on = ARRAY ['col1'])");

    int rows = 100;
    StringJoiner joiner = new StringJoiner(", ", "INSERT INTO test_shard_temporal_timestamp_bucketed VALUES ", "");
    for (int i = 0; i < rows; i++) {
        joiner.add(format("(%s, TIMESTAMP '2016-08-08 01:00' + interval '%s' hour)", i, i));
    }

    assertUpdate(joiner.toString(), format("VALUES(%s)", rows));

    MaterializedResult results = computeActual("" +
            "SELECT format_datetime(col2 AT TIME ZONE 'UTC', 'yyyyMMdd'), \"$shard_uuid\" " +
            "FROM test_shard_temporal_timestamp_bucketed");

    assertEquals(results.getRowCount(), rows);

    // Each shard will only contain data of one date.
    SetMultimap<String, String> shardDateMap = HashMultimap.create();
    for (MaterializedRow row : results.getMaterializedRows()) {
        shardDateMap.put((String) row.getField(1), (String) row.getField(0));
    }

    for (Collection<String> dates : shardDateMap.asMap().values()) {
        assertEquals(dates.size(), 1);
    }

    // Ensure one shard can contain different timestamps from the same day
    assertLessThan(shardDateMap.size(), rows);
}
 
Example #24
Source Project: incubator-pinot   Author: apache   File: TimeSeriesResponseConverter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Convert the response to a Map<DimensionKey, MetricTimeSeries>. DimensionKey is generated based
 * off of schemaDimensions, while the MetricTimeSeries objects are generated based on the rows
 * within the response input. The metrics returned in the MetricTimeSeries instances correspond to
 * the metric names as opposed to the full metric function (eg __COUNT instead of SUM(__COUNT))
 */
public static Map<DimensionKey, MetricTimeSeries> toMap(TimeSeriesResponse response,
    List<String> schemaDimensions) {
  DimensionKeyGenerator dimensionKeyGenerator = new DimensionKeyGenerator(schemaDimensions);

  List<String> metrics = new ArrayList<>(response.getMetrics());
  Set<String> metricSet = new HashSet<>(metrics);
  List<MetricType> types = Collections.nCopies(metrics.size(), MetricType.DOUBLE);
  MetricSchema metricSchema = new MetricSchema(metrics, types);

  SetMultimap<DimensionKey, TimeSeriesRow> dimensionKeyToRows = HashMultimap.create();
  // group the rows by their dimension key
  for (int i = 0; i < response.getNumRows(); i++) {
    TimeSeriesRow row = response.getRow(i);
    DimensionKey dimensionKey =
        dimensionKeyGenerator.get(row.getDimensionNames(), row.getDimensionValues());
    dimensionKeyToRows.put(dimensionKey, row);
  }

  Map<DimensionKey, MetricTimeSeries> result = new HashMap<>();
  for (Entry<DimensionKey, Collection<TimeSeriesRow>> entry : dimensionKeyToRows.asMap()
      .entrySet()) {
    DimensionKey key = entry.getKey();
    MetricTimeSeries metricTimeSeries = new MetricTimeSeries(metricSchema);
    result.put(key, metricTimeSeries);
    for (TimeSeriesRow timeSeriesRow : entry.getValue()) {
      long timestamp = timeSeriesRow.getStart();
      for (TimeSeriesMetric metric : timeSeriesRow.getMetrics()) {
        String metricName = metric.getMetricName();
        // Only add the row metric if it's listed in the response object. The row metric may
        // contain additional info, eg the raw metrics required for calculating derived ones.
        if (metricSet.contains(metricName)) {
          Double value = metric.getValue();
          metricTimeSeries.increment(timestamp, metricName, value);
        }
      }
    }
  }
  return result;
}
 
Example #25
Source Project: grakn   Author: graknlabs   File: RelationAtomValidator.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Set<String> validateAsRuleBody(RelationAtom atom, Label ruleLabel, ReasoningContext ctx) {
    Set<String> errors = new HashSet<>();
    SchemaConcept type = atom.getSchemaConcept();
    if (type != null && !type.isRelationType()) {
        errors.add(ErrorMessage.VALIDATION_RULE_INVALID_RELATION_TYPE.getMessage(ruleLabel, type.label()));
        return errors;
    }

    //check role-type compatibility
    SetMultimap<Variable, Type> varTypeMap = atom.getParentQuery().getVarTypeMap();
    for (Map.Entry<Role, Collection<Variable>> e : atom.getRoleVarMap().asMap().entrySet()) {
        Role role = e.getKey();
        if (!Schema.MetaSchema.isMetaLabel(role.label())) {
            //check whether this role can be played in this relation
            if (type != null && type.asRelationType().roles().noneMatch(r -> r.equals(role))) {
                errors.add(ErrorMessage.VALIDATION_RULE_ROLE_CANNOT_BE_PLAYED.getMessage(ruleLabel, role.label(), type.label()));
            }

            //check whether the role player's type allows playing this role
            for (Variable player : e.getValue()) {
                varTypeMap.get(player).stream()
                        .filter(playerType -> playerType.playing().noneMatch(plays -> plays.equals(role)))
                        .forEach(playerType ->
                                errors.add(ErrorMessage.VALIDATION_RULE_TYPE_CANNOT_PLAY_ROLE.getMessage(ruleLabel, playerType.label(), role.label(), type == null ? "" : type.label()))
                        );
            }
        }
    }
    return errors;
}
 
Example #26
Source Project: bazel-buildfarm   Author: bazelbuild   File: WorkerQueuesTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void noConfig_emptyProvisionNotEnqueued() {

  // Arrange
  WorkerQueues queues = new WorkerQueues();

  // Act
  Operation operation = Operation.newBuilder().build();
  SetMultimap<String, String> provisions = HashMultimap.create();
  boolean success = queues.enqueueOperation(operation, provisions);

  // Assert
  assertThat(success).isFalse();
}
 
Example #27
Source Project: tracing-framework   Author: brownsys   File: BaggageImpl.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Returns a set view of the keys in the specified namespace that have 1 or more values assigned
 * 
 * @param namespace the namespace to look up
 * @return all the distinct keys under the given namespace with values assigned */
public Set<ByteString> keys(ByteString namespace) {
    if (namespace != null) {
        SetMultimap<ByteString, ByteString> namespaceData = contents.get(namespace);
        if (namespaceData != null) {
            return namespaceData.keySet();
        }
    }
    return Collections.emptySet();
}
 
Example #28
Source Project: qconfig   Author: qunarcorp   File: RegisterServiceImpl.java    License: MIT License 5 votes vote down vote up
private CurrentServers initCurrentServer() {
    List<QConfigServer> availableServers = serverStore.getAvailableServers();
    SetMultimap<String, QConfigServer> roomProServerMap = HashMultimap.create();
    SetMultimap<String, QConfigServer> roomTestServerMap = HashMultimap.create();
    for (QConfigServer server : availableServers) {
        if (testEnvIpSet.contains(server.getIp())) {
            roomTestServerMap.put(server.getRoom(), server);
        } else {
            roomProServerMap.put(server.getRoom(), server);
        }
    }
    return new CurrentServers(roomProServerMap, roomTestServerMap);
}
 
Example #29
Source Project: PeerWasp   Author: PeerWasp   File: InitialState.java    License: MIT License 5 votes vote down vote up
private void addComponentToMoveTargetCandidates() {
	if(action.getFile().getPath().toString().contains("CONFLICT")){
		logger.trace("Workaround: Don't add conflict file {} to move target candidates",
				action.getFile().getPath());
		return;
	}
	if(action.getFile().isFile()){
		SetMultimap<String, FileComponent> createdByContentHash = action.getFileEventManager().getFileTree().getCreatedByContentHash();
		logger.trace("Put file {} with content hash {}", action.getFile().getPath(), action.getFile().getContentHash());
		createdByContentHash.put(action.getFile().getContentHash(), action.getFile());
	} else {
		SetMultimap<String, FolderComposite> createdByStructureHash = action.getFileEventManager().getFileTree().getCreatedByStructureHash();
		createdByStructureHash.put(((FolderComposite)action.getFile()).getStructureHash(), (FolderComposite)action.getFile());
	}
}
 
Example #30
Source Project: tracing-framework   Author: brownsys   File: BaggageImpl.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Construct a baggage instance from the provided BaggageMessage. If the provided message is invalid, null, or
 * empty, this method will return null
 * 
 * @param message A baggagemessage protobuf
 * @return A baggage instance if the provided message is valid and has contents, null otherwise */
static BaggageImpl create(BaggageMessage message) {
    // Check the message is not null and has some namespaces
    if (message == null || message.getNamespaceCount() == 0) {
        return null;
    }

    // Construct the baggage from the received message
    Map<ByteString, SetMultimap<ByteString, ByteString>> data = Maps.newHashMapWithExpectedSize(message.getNamespaceCount());
    for (NamespaceData namespaceData : message.getNamespaceList()) {
        SetMultimap<ByteString, ByteString> namespace = HashMultimap.create(namespaceData.getBagCount(), 1);
        for (BagData bag : namespaceData.getBagList()) {
            namespace.putAll(bag.getKey(), bag.getValueList());
        }
        if (!namespace.isEmpty()) {
            data.put(namespaceData.getKey(), namespace);
        }
    }

    // If there was no data after all, return null
    if (data.isEmpty()) {
        return null;
    }

    BaggageImpl impl = new BaggageImpl(data);
    Handlers.postDeserialize(impl);
    return impl;
}