@Parameterized.Parameters(name = "{index}: compression={0}, byteOrder={1}")
  public static Iterable<Object[]> compressionStrategies() {
    final Iterable<CompressedObjectStrategy.CompressionStrategy> compressionStrategies =
        Iterables.transform(
            CompressionStrategyTest.compressionStrategies(),
            new Function<Object[], CompressedObjectStrategy.CompressionStrategy>() {
              @Override
              public CompressedObjectStrategy.CompressionStrategy apply(Object[] input) {
                return (CompressedObjectStrategy.CompressionStrategy) input[0];
              }
            });

    Set<List<Object>> combinations =
        Sets.cartesianProduct(
            Sets.newHashSet(compressionStrategies),
            Sets.newHashSet(ByteOrder.BIG_ENDIAN, ByteOrder.LITTLE_ENDIAN));

    return Iterables.transform(
        combinations,
        new Function<List, Object[]>() {
          @Override
          public Object[] apply(List input) {
            return new Object[] {input.get(0), input.get(1)};
          }
        });
  }
Пример #2
0
  private static Set<List<Comparable<?>>> getPartitionKeysSet(
      CassandraTable table, TupleDomain<ColumnHandle> tupleDomain) {
    ImmutableList.Builder<Set<Comparable<?>>> partitionColumnValues = ImmutableList.builder();
    for (CassandraColumnHandle columnHandle : table.getPartitionKeyColumns()) {
      Domain domain = tupleDomain.getDomains().get(columnHandle);

      // if there is no constraint on a partition key, return an empty set
      if (domain == null) {
        return ImmutableSet.of();
      }

      // todo does cassandra allow null partition keys?
      if (domain.isNullAllowed()) {
        return ImmutableSet.of();
      }

      ImmutableSet.Builder<Comparable<?>> columnValues = ImmutableSet.builder();
      for (Range range : domain.getRanges()) {
        // if the range is not a single value, we can not perform partition pruning
        if (!range.isSingleValue()) {
          return ImmutableSet.of();
        }
        Comparable<?> value = range.getSingleValue();

        CassandraType valueType = columnHandle.getCassandraType();
        columnValues.add(valueType.getValueForPartitionKey(value));
      }
      partitionColumnValues.add(columnValues.build());
    }
    return Sets.cartesianProduct(partitionColumnValues.build());
  }
Пример #3
0
  /**
   * Vraci seznam vsech kombinaci pro zadanou strategy
   *
   * @param strategyName jmeno strategie
   * @return {key=cci, value=1;key=ema, value=13} {key=cci, value=2;key=ema, value=13} {key=cci,
   *     value=1;key=ema, value=14} atd...
   */
  public static List<Map<String, Integer>> getParametersCombination(String strategyName) {
    Map<String, Integer> map;
    List<Map<String, Integer>> list = new ArrayList<Map<String, Integer>>();
    // nactu z konfigu seznam vsech klicu
    List<String> keys = PropertyHelper.getAllOptimizationParamsForStrategy(strategyName);
    // naplnim si mapu konfiguracnich dat ex. {key=cci,value=3,4,5},{key=macd_1, value=10,2,20}
    Set[] sets = new Set[keys.size()];
    // sets[0] = ImmutableSet.of(keys);
    int loop = 0;
    for (String string : keys) {
      Integer[] values = PropertyHelper.getIntPropertyForOptimizer(string);
      Integer[] ilist = getAllIntegers(values);
      sets[loop++] = ImmutableSet.of(ilist);
    }
    List<String> reducedKeys = new ArrayList<String>();
    for (int i = 0; i < keys.size(); i++) {
      String s = keys.get(i);
      s = s.split("\\.")[1];
      reducedKeys.add(s);
    }

    Set s = Sets.cartesianProduct(sets);
    System.out.println(s.size());
    Iterator it = s.iterator();
    loop = 0;
    while (it.hasNext()) {
      ImmutableList il = (ImmutableList) it.next();
      Object[] o = il.toArray();
      map = new HashMap<String, Integer>();
      for (int i = 0; i < reducedKeys.size(); i++) {
        map.put(reducedKeys.get(i), (Integer) o[i]);
      }
      list.add(map);
    }
    return list;
    /*map = new  HashMap<String, Integer>();
    map.put("pt", 40);
    map.put("sl", 30);
    map.put("emaslow", 15);
    map.put("emafast", 5);
    map.put("cci", 13);
    map.put("macd_1", 5);
    map.put("macd_2", 40);
    map.put("macd_3", 5);
    list.add(map);

    map = new  HashMap<String, Integer>();
    map.put("pt", 50);
    map.put("sl", 20);
    map.put("emaslow", 13);
    map.put("emafast", 3);
    map.put("cci", 16);
    map.put("macd_1", 5);
    map.put("macd_2", 35);
    map.put("macd_3", 5);
    list.add(map);*/
  }
Пример #4
0
 @SuppressWarnings("unchecked") // varargs!
 public void testCartesianProductTooBig() {
   Set<Integer> set = ContiguousSet.create(Range.closed(0, 10000), DiscreteDomain.integers());
   try {
     Sets.cartesianProduct(set, set, set, set, set);
     fail("Expected IAE");
   } catch (IllegalArgumentException expected) {
   }
 }
Пример #5
0
 @SuppressWarnings("unchecked") // varargs!
 public void testCartesianProduct_contains() {
   Set<List<Integer>> actual = Sets.cartesianProduct(set(1, 2), set(3, 4));
   assertTrue(actual.contains(list(1, 3)));
   assertTrue(actual.contains(list(1, 4)));
   assertTrue(actual.contains(list(2, 3)));
   assertTrue(actual.contains(list(2, 4)));
   assertFalse(actual.contains(list(3, 1)));
 }
Пример #6
0
  @SuppressWarnings("unchecked") // varargs!
  public void testCartesianProduct_unrelatedTypes() {
    Set<Integer> x = set(1, 2);
    Set<String> y = set("3", "4");

    List<Object> exp1 = list((Object) 1, "3");
    List<Object> exp2 = list((Object) 1, "4");
    List<Object> exp3 = list((Object) 2, "3");
    List<Object> exp4 = list((Object) 2, "4");

    assertThat(Sets.<Object>cartesianProduct(x, y))
        .containsExactly(exp1, exp2, exp3, exp4)
        .inOrder();
  }
Пример #7
0
 @SuppressWarnings("unchecked") // varargs!
 public void testCartesianProduct_2x2x2() {
   assertThat(Sets.cartesianProduct(set(0, 1), set(0, 1), set(0, 1)))
       .containsExactly(
           list(0, 0, 0),
           list(0, 0, 1),
           list(0, 1, 0),
           list(0, 1, 1),
           list(1, 0, 0),
           list(1, 0, 1),
           list(1, 1, 0),
           list(1, 1, 1))
       .inOrder();
 }
  @Test
  public void whenCalculateSetsProduct_thenCorrect() {
    final Set<Character> first = ImmutableSet.of('a', 'b');
    final Set<Character> second = ImmutableSet.of('c', 'd');
    final Set<List<Character>> result = Sets.cartesianProduct(ImmutableList.of(first, second));

    final Function<List<Character>, String> func =
        new Function<List<Character>, String>() {
          @Override
          public final String apply(final List<Character> input) {
            return Joiner.on(" ").join(input);
          }
        };

    final Iterable<String> joined = Iterables.transform(result, func);
    assertThat(joined, containsInAnyOrder("a c", "a d", "b c", "b d"));
  }
  /**
   * Creates an iterator that returns an {@link Options} containing each possible parameter set
   * defined by these {@link
   * com.biomatters.plugins.barcoding.validator.research.options.BatchOptions}. Note that the {@link
   * Options} object returned is always the same to save on initializing multiple copies. Each time
   * {@link java.util.Iterator#next()} is called the next parameter set is set on the {@link
   * Options}.
   *
   * @return An iterator that will iterate over all possible parameter sets specified by this {@link
   *     com.biomatters.plugins.barcoding.validator.research.options.BatchOptions}
   * @throws DocumentOperationException if there is a problem creating the {@link Options} object
   */
  public Iterator<T> iterator() throws DocumentOperationException {
    List<Set<OptionToSet>> possibleValues = new ArrayList<Set<OptionToSet>>();

    Map<String, MultiValueOption<?>> multiValueOptions = getMultiValueOptions("", options);
    for (Map.Entry<String, MultiValueOption<?>> entry : multiValueOptions.entrySet()) {
      possibleValues.add(getOptionsToSet(entry.getKey(), entry.getValue()));
    }
    Set<List<OptionToSet>> lists = Sets.cartesianProduct(possibleValues);
    final Iterator<List<OptionToSet>> possibilityIterator = lists.iterator();

    final T template;
    try {
      //noinspection unchecked
      template = (T) options.getClass().newInstance(); // getClass() doesn't return Class<T> :(
      template.valuesFromXML(options.valuesToXML(XMLSerializable.ROOT_ELEMENT_NAME));
    } catch (InstantiationException e) {
      throw new DocumentOperationException("Failed to create Options: " + e.getMessage(), e);
    } catch (IllegalAccessException e) {
      throw new DocumentOperationException("Failed to create Options: " + e.getMessage(), e);
    }

    return new Iterator<T>() {
      @Override
      public boolean hasNext() {
        return possibilityIterator.hasNext();
      }

      @Override
      public T next() {
        List<OptionToSet> possibility = possibilityIterator.next();
        for (OptionToSet optionToSet : possibility) {
          template.setValue(optionToSet.name, optionToSet.value);
        }
        return template;
      }

      @Override
      public void remove() {
        new UnsupportedOperationException();
      }
    };
  }
Пример #10
0
  @Parameterized.Parameters(name = "repetitions={0}, hash={1}")
  public static Iterable<Object[]> data() {
    List<HashAlgorithm> hash =
        ImmutableList.of(
            DefaultHashAlgorithm.FNV1A_64_HASH,
            DefaultHashAlgorithm.KETAMA_HASH,
            MemcachedCache.MURMUR3_128);
    List<Integer> repetitions = Arrays.asList(160, 500, 1000, 2500, 5000);

    Set<List<Object>> values =
        Sets.cartesianProduct(Sets.newLinkedHashSet(hash), Sets.newLinkedHashSet(repetitions));
    return Iterables.transform(
        values,
        new Function<List<Object>, Object[]>() {
          @Nullable
          @Override
          public Object[] apply(List<Object> input) {
            return input.toArray();
          }
        });
  }
  @Override
  public Set<ImmutableMap<InputPort, Data>> makeProduct(
      final StepInputPorts inputPorts, final Multimap<InputPort, Data> inputTokens) {

    checkNotNull(inputPorts, "inputPorts argument cannot be null");
    checkNotNull(inputTokens, "inputTokens argument cannot be null");

    final Set<ImmutableMap<InputPort, Data>> result = new HashSet<>();
    final List<StepInputPort> portsList = Lists.newArrayList(inputPorts.iterator());

    // First create the lists for Sets.cartesianProduct()
    final List<Set<CartesianProductEntry>> sets = new ArrayList<>();
    for (StepInputPort port : portsList) {
      final Set<CartesianProductEntry> s = new HashSet<>();
      for (Data d : inputTokens.get(port)) {
        s.add(new CartesianProductEntry(port, d));
      }
      sets.add(s);
    }

    // Compute cartesian product
    final Set<List<CartesianProductEntry>> cartesianProduct = Sets.cartesianProduct(sets);

    // Now convert result of cartesianProduct() to final result
    for (List<CartesianProductEntry> l : cartesianProduct) {

      final ImmutableMap.Builder<InputPort, Data> imb = ImmutableMap.builder();

      for (CartesianProductEntry e : l) {
        imb.put(e.port, e.data);
      }

      result.add(imb.build());
    }

    return result;
  }
Пример #12
0
  protected void instantiateCandidate(
      OperatorDescriptorSingle dps,
      Channel in,
      List<Set<? extends NamedChannel>> broadcastPlanChannels,
      List<PlanNode> target,
      CostEstimator estimator,
      RequestedGlobalProperties globPropsReq,
      RequestedLocalProperties locPropsReq) {
    final PlanNode inputSource = in.getSource();

    for (List<NamedChannel> broadcastChannelsCombination :
        Sets.cartesianProduct(broadcastPlanChannels)) {

      boolean validCombination = true;
      boolean requiresPipelinebreaker = false;

      // check whether the broadcast inputs use the same plan candidate at the branching point
      for (int i = 0; i < broadcastChannelsCombination.size(); i++) {
        NamedChannel nc = broadcastChannelsCombination.get(i);
        PlanNode bcSource = nc.getSource();

        // check branch compatibility against input
        if (!areBranchCompatible(bcSource, inputSource)) {
          validCombination = false;
          break;
        }

        // check branch compatibility against all other broadcast variables
        for (int k = 0; k < i; k++) {
          PlanNode otherBcSource = broadcastChannelsCombination.get(k).getSource();

          if (!areBranchCompatible(bcSource, otherBcSource)) {
            validCombination = false;
            break;
          }
        }

        // check if there is a common predecessor and whether there is a dam on the way to all
        // common predecessors
        if (in.isOnDynamicPath() && this.hereJoinedBranches != null) {
          for (OptimizerNode brancher : this.hereJoinedBranches) {
            PlanNode candAtBrancher = in.getSource().getCandidateAtBranchPoint(brancher);

            if (candAtBrancher == null) {
              // closed branch between two broadcast variables
              continue;
            }

            SourceAndDamReport res = in.getSource().hasDamOnPathDownTo(candAtBrancher);
            if (res == NOT_FOUND) {
              throw new CompilerException("Bug: Tracing dams for deadlock detection is broken.");
            } else if (res == FOUND_SOURCE) {
              requiresPipelinebreaker = true;
              break;
            } else if (res == FOUND_SOURCE_AND_DAM) {
              // good
            } else {
              throw new CompilerException();
            }
          }
        }
      }

      if (!validCombination) {
        continue;
      }

      if (requiresPipelinebreaker) {
        in.setTempMode(in.getTempMode().makePipelineBreaker());
      }

      final SingleInputPlanNode node = dps.instantiate(in, this);
      node.setBroadcastInputs(broadcastChannelsCombination);

      // compute how the strategy affects the properties
      GlobalProperties gProps = in.getGlobalProperties().clone();
      LocalProperties lProps = in.getLocalProperties().clone();
      gProps = dps.computeGlobalProperties(gProps);
      lProps = dps.computeLocalProperties(lProps);

      // filter by the user code field copies
      gProps =
          gProps.filterBySemanticProperties(getSemanticPropertiesForGlobalPropertyFiltering(), 0);
      lProps =
          lProps.filterBySemanticProperties(getSemanticPropertiesForLocalPropertyFiltering(), 0);

      // apply
      node.initProperties(gProps, lProps);
      node.updatePropertiesWithUniqueSets(getUniqueFields());
      target.add(node);
    }
  }
Пример #13
0
  @SuppressWarnings("unchecked") // varargs!
  public void testCartesianProduct_hashCode() {
    // Run through the same cartesian products we tested above

    Set<List<Integer>> degenerate = Sets.cartesianProduct();
    checkHashCode(degenerate);

    checkHashCode(Sets.cartesianProduct(set(1, 2)));

    int num = Integer.MAX_VALUE / 3 * 2; // tickle overflow-related problems
    checkHashCode(Sets.cartesianProduct(set(1, 2, num)));

    Set<Integer> mt = emptySet();
    checkHashCode(Sets.cartesianProduct(mt, mt));
    checkHashCode(Sets.cartesianProduct(mt, set(num)));
    checkHashCode(Sets.cartesianProduct(set(num), mt));
    checkHashCode(Sets.cartesianProduct(set(num), set(1)));
    checkHashCode(Sets.cartesianProduct(set(1), set(2, num)));
    checkHashCode(Sets.cartesianProduct(set(1, num), set(2, num - 1)));
    checkHashCode(Sets.cartesianProduct(set(1, num), set(2, num - 1), set(3, num + 1)));

    // a bigger one
    checkHashCode(
        Sets.cartesianProduct(set(1, num, num + 1), set(2), set(3, num + 2), set(4, 5, 6, 7, 8)));
  }
Пример #14
0
 /** The 0-ary cartesian product is a single empty list. */
 @SuppressWarnings("unchecked") // varargs!
 public void testCartesianProduct_zeroary() {
   assertThat(Sets.cartesianProduct()).containsExactly(list());
 }
Пример #15
0
 @SuppressWarnings("unchecked") // varargs!
 public void testCartesianProduct_binary2x2() {
   assertThat(Sets.cartesianProduct(set(1, 2), set(3, 4)))
       .containsExactly(list(1, 3), list(1, 4), list(2, 3), list(2, 4))
       .inOrder();
 }
Пример #16
0
 @SuppressWarnings("unchecked") // varargs!
 public void testCartesianProduct_binary1x1() {
   assertThat(Sets.cartesianProduct(set(1), set(2))).contains(list(1, 2));
 }
Пример #17
0
 @SuppressWarnings("unchecked") // varargs!
 public void testCartesianProduct_binary1x0() {
   Set<Integer> mt = emptySet();
   assertEmpty(Sets.cartesianProduct(set(1), mt));
 }