PageRenderTime 40ms CodeModel.GetById 11ms app.highlight 26ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/release-0.1-rc2/hive/external/ql/src/java/org/apache/hadoop/hive/ql/plan/TableDesc.java

#
Java | 173 lines | 117 code | 25 blank | 31 comment | 4 complexity | 360daf2c29d0db538ad8aa346ad72dec MD5 | raw file
  1/**
  2 * Licensed to the Apache Software Foundation (ASF) under one
  3 * or more contributor license agreements.  See the NOTICE file
  4 * distributed with this work for additional information
  5 * regarding copyright ownership.  The ASF licenses this file
  6 * to you under the Apache License, Version 2.0 (the
  7 * "License"); you may not use this file except in compliance
  8 * with the License.  You may obtain a copy of the License at
  9 *
 10 *     http://www.apache.org/licenses/LICENSE-2.0
 11 *
 12 * Unless required by applicable law or agreed to in writing, software
 13 * distributed under the License is distributed on an "AS IS" BASIS,
 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 */
 18
 19package org.apache.hadoop.hive.ql.plan;
 20
 21import java.io.Serializable;
 22import java.util.Enumeration;
 23import java.util.Properties;
 24import java.util.LinkedHashMap;
 25import java.util.Map;
 26
 27import org.apache.hadoop.hive.ql.io.HiveFileFormatUtils;
 28import org.apache.hadoop.hive.ql.io.HiveOutputFormat;
 29import org.apache.hadoop.hive.serde2.Deserializer;
 30import org.apache.hadoop.mapred.InputFormat;
 31
 32/**
 33 * TableDesc.
 34 *
 35 */
 36public class TableDesc implements Serializable, Cloneable {
 37  private static final long serialVersionUID = 1L;
 38  private Class<? extends Deserializer> deserializerClass;
 39  private Class<? extends InputFormat> inputFileFormatClass;
 40  private Class<? extends HiveOutputFormat> outputFileFormatClass;
 41  private java.util.Properties properties;
 42  private String serdeClassName;
 43  private Map<String, String> jobProperties;
 44
 45  public TableDesc() {
 46  }
 47
 48  public TableDesc(final Class<? extends Deserializer> serdeClass,
 49      final Class<? extends InputFormat> inputFileFormatClass,
 50      final Class<?> class1, final java.util.Properties properties) {
 51    deserializerClass = serdeClass;
 52    this.inputFileFormatClass = inputFileFormatClass;
 53    outputFileFormatClass = HiveFileFormatUtils
 54        .getOutputFormatSubstitute(class1);
 55    this.properties = properties;
 56    serdeClassName = properties
 57        .getProperty(org.apache.hadoop.hive.serde.Constants.SERIALIZATION_LIB);
 58    ;
 59  }
 60
 61  public Class<? extends Deserializer> getDeserializerClass() {
 62    return deserializerClass;
 63  }
 64
 65  public void setDeserializerClass(
 66      final Class<? extends Deserializer> serdeClass) {
 67    deserializerClass = serdeClass;
 68  }
 69
 70  public Class<? extends InputFormat> getInputFileFormatClass() {
 71    return inputFileFormatClass;
 72  }
 73
 74  /**
 75   * Return a deserializer object corresponding to the tableDesc.
 76   */
 77  public Deserializer getDeserializer() throws Exception {
 78    Deserializer de = deserializerClass.newInstance();
 79    de.initialize(null, properties);
 80    return de;
 81  }
 82
 83  public void setInputFileFormatClass(
 84      final Class<? extends InputFormat> inputFileFormatClass) {
 85    this.inputFileFormatClass = inputFileFormatClass;
 86  }
 87
 88  public Class<? extends HiveOutputFormat> getOutputFileFormatClass() {
 89    return outputFileFormatClass;
 90  }
 91
 92  public void setOutputFileFormatClass(final Class<?> outputFileFormatClass) {
 93    this.outputFileFormatClass = HiveFileFormatUtils
 94        .getOutputFormatSubstitute(outputFileFormatClass);
 95  }
 96
 97  @Explain(displayName = "properties", normalExplain = false)
 98  public java.util.Properties getProperties() {
 99    return properties;
100  }
101
102  public void setProperties(final java.util.Properties properties) {
103    this.properties = properties;
104  }
105
106  public void setJobProperties(Map<String, String> jobProperties) {
107    this.jobProperties = jobProperties;
108  }
109
110  @Explain(displayName = "jobProperties", normalExplain = false)
111  public Map<String, String> getJobProperties() {
112    return jobProperties;
113  }
114
115  /**
116   * @return the serdeClassName
117   */
118  @Explain(displayName = "serde")
119  public String getSerdeClassName() {
120    return serdeClassName;
121  }
122
123  /**
124   * @param serdeClassName
125   *          the serde Class Name to set
126   */
127  public void setSerdeClassName(String serdeClassName) {
128    this.serdeClassName = serdeClassName;
129  }
130
131  @Explain(displayName = "name")
132  public String getTableName() {
133    return properties
134        .getProperty(org.apache.hadoop.hive.metastore.api.Constants.META_TABLE_NAME);
135  }
136
137  @Explain(displayName = "input format")
138  public String getInputFileFormatClassName() {
139    return getInputFileFormatClass().getName();
140  }
141
142  @Explain(displayName = "output format")
143  public String getOutputFileFormatClassName() {
144    return getOutputFileFormatClass().getName();
145  }
146
147  public boolean isNonNative() {
148    return (properties.getProperty(
149        org.apache.hadoop.hive.metastore.api.Constants.META_TABLE_STORAGE)
150      != null);
151  }
152  
153  @Override
154  public Object clone() {
155    TableDesc ret = new TableDesc();
156    ret.setSerdeClassName(serdeClassName);
157    ret.setDeserializerClass(deserializerClass);
158    ret.setInputFileFormatClass(inputFileFormatClass);
159    ret.setOutputFileFormatClass(outputFileFormatClass);
160    Properties newProp = new Properties();
161    Enumeration<Object> keysProp = properties.keys();
162    while (keysProp.hasMoreElements()) {
163      Object key = keysProp.nextElement();
164      newProp.put(key, properties.get(key));
165    }
166
167    ret.setProperties(newProp);
168    if (jobProperties != null) {
169      ret.jobProperties = new LinkedHashMap<String, String>(jobProperties);
170    }
171    return ret;
172  }
173}