/**
   * Maps to a sub-region of [0..1]
   *
   * @param min the lower bound
   * @param max the upper bound
   * @return a transformation from [0..1] to [min..max]
   */
  public static TimeModifier sub(float min, float max) {
    Preconditions.checkArgument(min >= 0f);
    Preconditions.checkArgument(max > min);
    Preconditions.checkArgument(max <= 1f);

    float range = max - min;
    return v -> min + (v * range);
  }
 static GoogleClientSecrets getClientCredential() throws IOException {
   if (clientSecrets == null) {
     clientSecrets =
         GoogleClientSecrets.load(
             JSON_FACTORY,
             new InputStreamReader(
                 ServiceUtils.class.getResourceAsStream("/client_secrets.json")));
     Preconditions.checkArgument(
         !clientSecrets.getDetails().getClientId().startsWith("Enter ")
             && !clientSecrets.getDetails().getClientSecret().startsWith("Enter "),
         "Enter Client ID and Secret from https://code.google.com/apis/console/?api=bigquery "
             + "into bigquery-appengine-sample/src/main/resources/client_secrets.json");
   }
   return clientSecrets;
 }
Beispiel #3
0
 private void initializeParser(JsonParser paramJsonParser) throws IOException {
   boolean bool = true;
   if (wrapperKeys.isEmpty()) ;
   while (true) {
     return;
     try {
       if ((paramJsonParser.skipToKey(wrapperKeys) != null)
           && (paramJsonParser.getCurrentToken() != JsonToken.END_OBJECT)) ;
       while (true) {
         Preconditions.checkArgument(
             bool, "wrapper key(s) not found: %s", new Object[] {wrapperKeys});
         if (0 == 0) break;
         paramJsonParser.close();
         return;
         bool = false;
       }
     } finally {
       if (1 != 0) paramJsonParser.close();
     }
   }
 }
 /**
  * Returns the HTTP content length or {@code -1} for unknown.
  *
  * <p>Default value is {@code -1}.
  *
  * @since 1.5
  */
 public MockHttpContent setLength(long length) {
   Preconditions.checkArgument(length >= -1);
   this.length = length;
   return this;
 }
 /**
  * increases the speed by factor <code>times</codes> and restarts from 0.
  * @param times the (positive) multiplication factor
  * @return a mapping function
  */
 public static TimeModifier multiply(float times) {
   Preconditions.checkArgument(times > 0f);
   return v -> (v * times) % 1f;
 }
 /**
  * Always returns the same constant value
  *
  * @param constant the constant value
  * @return a mapping function
  */
 public static TimeModifier constant(float constant) {
   Preconditions.checkArgument(constant >= 0 && constant <= 1);
   return v -> constant;
 }
  @SuppressWarnings({"rawtypes", "unchecked"})
  public static GroupAlsoByWindowsParDoFn create(
      PipelineOptions options,
      CloudObject cloudUserFn,
      String stepName,
      @Nullable List<SideInputInfo> sideInputInfos,
      @Nullable List<MultiOutputInfo> multiOutputInfos,
      Integer numOutputs,
      ExecutionContext executionContext,
      CounterSet.AddCounterMutator addCounterMutator,
      StateSampler sampler /* unused */)
      throws Exception {
    Object windowingStrategyObj;
    byte[] encodedWindowingStrategy = getBytes(cloudUserFn, PropertyNames.SERIALIZED_FN);
    if (encodedWindowingStrategy.length == 0) {
      windowingStrategyObj = WindowingStrategy.globalDefault();
    } else {
      windowingStrategyObj =
          SerializableUtils.deserializeFromByteArray(
              encodedWindowingStrategy, "serialized windowing strategy");
      if (!(windowingStrategyObj instanceof WindowingStrategy)) {
        throw new Exception(
            "unexpected kind of WindowingStrategy: " + windowingStrategyObj.getClass().getName());
      }
    }
    WindowingStrategy windowingStrategy = (WindowingStrategy) windowingStrategyObj;

    byte[] serializedCombineFn = getBytes(cloudUserFn, PropertyNames.COMBINE_FN, null);
    KeyedCombineFn combineFn;
    if (serializedCombineFn != null) {
      Object combineFnObj =
          SerializableUtils.deserializeFromByteArray(serializedCombineFn, "serialized combine fn");
      if (!(combineFnObj instanceof KeyedCombineFn)) {
        throw new Exception(
            "unexpected kind of KeyedCombineFn: " + combineFnObj.getClass().getName());
      }
      combineFn = (KeyedCombineFn) combineFnObj;
    } else {
      combineFn = null;
    }

    Map<String, Object> inputCoderObject = getObject(cloudUserFn, PropertyNames.INPUT_CODER);

    Coder inputCoder = Serializer.deserialize(inputCoderObject, Coder.class);
    if (!(inputCoder instanceof WindowedValueCoder)) {
      throw new Exception(
          "Expected WindowedValueCoder for inputCoder, got: " + inputCoder.getClass().getName());
    }
    Coder elemCoder = ((WindowedValueCoder) inputCoder).getValueCoder();
    if (!(elemCoder instanceof KvCoder)) {
      throw new Exception(
          "Expected KvCoder for inputCoder, got: " + elemCoder.getClass().getName());
    }
    KvCoder kvCoder = (KvCoder) elemCoder;

    boolean isStreamingPipeline = false;
    if (options instanceof StreamingOptions) {
      isStreamingPipeline = ((StreamingOptions) options).isStreaming();
    }

    KeyedCombineFn maybeMergingCombineFn = null;
    if (combineFn != null) {
      String phase = getString(cloudUserFn, PropertyNames.PHASE, CombinePhase.ALL);
      Preconditions.checkArgument(
          phase.equals(CombinePhase.ALL) || phase.equals(CombinePhase.MERGE),
          "Unexpected phase: " + phase);
      if (phase.equals(CombinePhase.MERGE)) {
        maybeMergingCombineFn = new MergingKeyedCombineFn(combineFn);
      } else {
        maybeMergingCombineFn = combineFn;
      }
    }

    DoFnInfoFactory fnFactory;
    final DoFn groupAlsoByWindowsDoFn =
        getGroupAlsoByWindowsDoFn(
            isStreamingPipeline, windowingStrategy, kvCoder, maybeMergingCombineFn);

    fnFactory =
        new DoFnInfoFactory() {
          @Override
          public DoFnInfo createDoFnInfo() {
            return new DoFnInfo(groupAlsoByWindowsDoFn, null);
          }
        };
    return new GroupAlsoByWindowsParDoFn(
        options, fnFactory, stepName, executionContext, addCounterMutator);
  }
 /**
  * Sets the seconds of time skew to accept when verifying time (default is {@link
  * #DEFAULT_TIME_SKEW_SECONDS}).
  *
  * <p>It must be greater or equal to zero.
  *
  * <p>Overriding is only supported for the purpose of calling the super implementation and
  * changing the return type, but nothing else.
  */
 public Builder setAcceptableTimeSkewSeconds(long acceptableTimeSkewSeconds) {
   Preconditions.checkArgument(acceptableTimeSkewSeconds >= 0);
   this.acceptableTimeSkewSeconds = acceptableTimeSkewSeconds;
   return this;
 }