All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.spotify.flo.contrib.bigquery.BigQueryOperator Maven / Gradle / Ivy

The newest version!
/*-
 * -\-\-
 * Flo BigQuery
 * --
 * Copyright (C) 2016 - 2018 Spotify AB
 * --
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * -/-/-
 */

package com.spotify.flo.contrib.bigquery;

import static com.spotify.flo.contrib.bigquery.BigQueryClientSingleton.bq;

import com.google.cloud.bigquery.JobInfo;
import com.spotify.flo.EvalContext;
import com.spotify.flo.TaskOperator;
import com.spotify.flo.contrib.bigquery.BigQueryOperation.Provider;

public class BigQueryOperator implements TaskOperator, BigQueryOperation, T> {

  private static final long serialVersionUID = 1L;

  private BigQueryOperator() {
  }

  @Override
  public T perform(BigQueryOperation spec, Listener listener) {
    final JobInfo result;
    if (spec.jobRequest != null) {
      result = runJob(spec);
    } else {
      throw new AssertionError();
    }
    return spec.success.apply(result);
  }

  private JobInfo runJob(BigQueryOperation spec) {
    return bq().job(spec.jobRequest.get());
  }

  public static  BigQueryOperator create() {
    return new BigQueryOperator<>();
  }

  @Override
  public Provider provide(EvalContext evalContext) {
    return new BigQueryOperation.Provider<>();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy