org.apache.hadoop.hive.ql.plan.AddPartitionDesc Maven / Gradle / Ivy
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.hadoop.hive.ql.plan;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.hadoop.hive.metastore.api.FieldSchema;
import org.apache.hadoop.hive.metastore.api.Order;
import org.apache.hadoop.hive.ql.parse.ReplicationSpec;
/**
* Contains the information needed to add one or more partitions.
*/
public class AddPartitionDesc extends DDLDesc implements Serializable {
public static class OnePartitionDesc {
public OnePartitionDesc() {}
OnePartitionDesc(
Map partSpec, String location, Map params) {
this(partSpec, location);
this.partParams = params;
}
OnePartitionDesc(Map partSpec, String location) {
this.partSpec = partSpec;
this.location = location;
}
Map partSpec;
Map partParams;
String location;
String inputFormat = null;
String outputFormat = null;
int numBuckets = -1;
List cols = null;
String serializationLib = null;
Map serdeParams = null;
List bucketCols = null;
List sortCols = null;
public Map getPartSpec() {
return partSpec;
}
/**
* @return location of partition in relation to table
*/
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public Map getPartParams() {
return partParams;
}
public void setPartParams(Map partParams) {
this.partParams = partParams;
}
public int getNumBuckets() {
return numBuckets;
}
public void setNumBuckets(int numBuckets) {
this.numBuckets = numBuckets;
}
public List getCols() {
return cols;
}
public void setCols(List cols) {
this.cols = cols;
}
public String getSerializationLib() {
return serializationLib;
}
public void setSerializationLib(String serializationLib) {
this.serializationLib = serializationLib;
}
public Map getSerdeParams() {
return serdeParams;
}
public void setSerdeParams(Map serdeParams) {
this.serdeParams = serdeParams;
}
public List getBucketCols() {
return bucketCols;
}
public void setBucketCols(List bucketCols) {
this.bucketCols = bucketCols;
}
public List getSortCols() {
return sortCols;
}
public void setSortCols(List sortCols) {
this.sortCols = sortCols;
}
public String getInputFormat() {
return inputFormat;
}
public void setInputFormat(String inputFormat) {
this.inputFormat = inputFormat;
}
public String getOutputFormat() {
return outputFormat;
}
public void setOutputFormat(String outputFormat) {
this.outputFormat = outputFormat;
}
}
private static final long serialVersionUID = 1L;
String tableName;
String dbName;
boolean ifNotExists;
List partitions = null;
boolean replaceMode = false;
private ReplicationSpec replicationSpec = null;
/**
* For serialization only.
*/
public AddPartitionDesc() {
}
public AddPartitionDesc(
String dbName, String tableName, boolean ifNotExists) {
super();
this.dbName = dbName;
this.tableName = tableName;
this.ifNotExists = ifNotExists;
}
/**
* Legacy single-partition ctor for ImportSemanticAnalyzer
* @param dbName
* database to add to.
* @param tableName
* table to add to.
* @param partSpec
* partition specification.
* @param location
* partition location, relative to table location.
* @param params
* partition parameters.
*/
@Deprecated
public AddPartitionDesc(String dbName, String tableName,
Map partSpec, String location, Map params) {
super();
this.dbName = dbName;
this.tableName = tableName;
this.ifNotExists = true;
addPartition(partSpec, location, params);
}
public void addPartition(Map partSpec, String location) {
addPartition(partSpec, location, null);
}
private void addPartition(
Map partSpec, String location, Map params) {
if (this.partitions == null) {
this.partitions = new ArrayList();
}
this.partitions.add(new OnePartitionDesc(partSpec, location, params));
}
/**
* @return database name
*/
public String getDbName() {
return dbName;
}
/**
* @param dbName
* database name
*/
public void setDbName(String dbName) {
this.dbName = dbName;
}
/**
* @return the table we're going to add the partitions to.
*/
public String getTableName() {
return tableName;
}
/**
* @param tableName
* the table we're going to add the partitions to.
*/
public void setTableName(String tableName) {
this.tableName = tableName;
}
/**
* @return location of partition in relation to table
*/
@Explain(displayName = "Location")
public String getLocationForExplain() {
if (this.partitions == null || this.partitions.isEmpty()) return "";
boolean isFirst = true;
StringBuilder sb = new StringBuilder();
for (OnePartitionDesc desc : this.partitions) {
if (!isFirst) {
sb.append(", ");
}
isFirst = false;
sb.append(desc.location);
}
return sb.toString();
}
@Explain(displayName = "Spec")
public String getPartSpecStringForExplain() {
if (this.partitions == null || this.partitions.isEmpty()) return "";
boolean isFirst = true;
StringBuilder sb = new StringBuilder();
for (OnePartitionDesc desc : this.partitions) {
if (!isFirst) {
sb.append(", ");
}
isFirst = false;
sb.append(desc.partSpec.toString());
}
return sb.toString();
}
/**
* @return if the partition should only be added if it doesn't exist already
*/
public boolean isIfNotExists() {
return this.ifNotExists;
}
/**
* @param ifNotExists
* if the part should be added only if it doesn't exist
*/
public void setIfNotExists(boolean ifNotExists) {
this.ifNotExists = ifNotExists;
}
public int getPartitionCount() {
return this.partitions.size();
}
public OnePartitionDesc getPartition(int i) {
return this.partitions.get(i);
}
/**
* @param replaceMode Determine if this AddPartition should behave like a replace-into alter instead
*/
public void setReplaceMode(boolean replaceMode){
this.replaceMode = replaceMode;
}
/**
* @return true if this AddPartition should behave like a replace-into alter instead
*/
public boolean getReplaceMode() {
return this.replaceMode;
}
/**
* @param replicationSpec Sets the replication spec governing this create.
* This parameter will have meaningful values only for creates happening as a result of a replication.
*/
public void setReplicationSpec(ReplicationSpec replicationSpec) {
this.replicationSpec = replicationSpec;
}
/**
* @return what kind of replication scope this drop is running under.
* This can result in a "CREATE/REPLACE IF NEWER THAN" kind of semantic
*/
public ReplicationSpec getReplicationSpec(){
if (replicationSpec == null){
this.replicationSpec = new ReplicationSpec();
}
return this.replicationSpec;
}
}