gobblin.hive.spec.SimpleHiveSpec Maven / Gradle / Ivy
 The newest version!
        
        /*
 * Copyright (C) 2014-2016 LinkedIn Corp. All rights reserved.
 *
 * 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.
 */
package gobblin.hive.spec;
import org.apache.hadoop.fs.Path;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import gobblin.annotation.Alpha;
import gobblin.hive.HivePartition;
import gobblin.hive.HiveTable;
import gobblin.hive.HiveRegister;
import gobblin.hive.spec.activity.Activity;
import lombok.Builder;
import lombok.Getter;
import lombok.Singular;
import java.util.Collection;
/**
 * A base implementation of {@link HiveSpec}.
 */
@Getter
@Alpha
@Builder(builderClassName = "Builder")
public class SimpleHiveSpec
    implements HiveSpec, HiveSpecWithPreActivities, HiveSpecWithPostActivities, HiveSpecWithPredicates {
  protected final Path path;
  protected final HiveTable table;
  protected final Optional partition;
  @Singular
  @Getter
  protected final Collection preActivities;
  @Singular
  @Getter
  protected final Collection postActivities;
  @Singular
  @Getter
  protected final Collection> predicates;
  protected SimpleHiveSpec(Builder> builder) {
    this.path = builder.path;
    this.table = builder.table;
    this.partition = builder.partition != null ? builder.partition : Optional. absent();
    this.preActivities = builder.preActivities;
    this.postActivities = builder.postActivities;
    this.predicates = builder.predicates;
  }
  @Override
  public String toString() {
    return Objects.toStringHelper(this).omitNullValues().add("path", this.path.toString())
        .add("db", this.table.getDbName()).add("table", this.table.getTableName())
        .add("partition", this.partition.orNull()).toString();
  }
  public static class Builder> {
    @Getter
    private Path path;
    @Getter
    private HiveTable table;
    @Getter
    private Optional partition;
    private Builder() {
      this.path = null;
    }
    public Builder(Path path) {
      this.path = path;
      this.preActivities = Lists.newArrayList();
      this.postActivities = Lists.newArrayList();
      this.predicates = Lists.newArrayList();
    }
    @SuppressWarnings("unchecked")
    public T withTable(HiveTable table) {
      this.table = table;
      return (T) this;
    }
    @SuppressWarnings("unchecked")
    public T withPartition(Optional partition) {
      this.partition = partition;
      return (T) this;
    }
    public SimpleHiveSpec build() {
      Preconditions.checkNotNull(this.path);
      Preconditions.checkNotNull(this.table);
      return new SimpleHiveSpec(this);
    }
  }
}
            © 2015 - 2025 Weber Informatics LLC | Privacy Policy