/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. package org.apache.hadoop.hive.ql.plan;
  19. import java.io.Serializable;
  20. import java.util.Enumeration;
  21. import java.util.Properties;
  22. import java.util.LinkedHashMap;
  23. import java.util.Map;
  24. import org.apache.hadoop.hive.ql.io.HiveFileFormatUtils;
  25. import org.apache.hadoop.hive.ql.io.HiveOutputFormat;
  26. import org.apache.hadoop.hive.serde2.Deserializer;
  27. import org.apache.hadoop.mapred.InputFormat;
  28. /**
  29. * TableDesc.
  30. *
  31. */
  32. public class TableDesc implements Serializable, Cloneable {
  33. private static final long serialVersionUID = 1L;
  34. private Class<? extends Deserializer> deserializerClass;
  35. private Class<? extends InputFormat> inputFileFormatClass;
  36. private Class<? extends HiveOutputFormat> outputFileFormatClass;
  37. private java.util.Properties properties;
  38. private String serdeClassName;
  39. private Map<String, String> jobProperties;
  40. public TableDesc() {
  41. }
  42. public TableDesc(final Class<? extends Deserializer> serdeClass,
  43. final Class<? extends InputFormat> inputFileFormatClass,
  44. final Class<?> class1, final java.util.Properties properties) {
  45. deserializerClass = serdeClass;
  46. this.inputFileFormatClass = inputFileFormatClass;
  47. outputFileFormatClass = HiveFileFormatUtils
  48. .getOutputFormatSubstitute(class1);
  49. this.properties = properties;
  50. serdeClassName = properties
  51. .getProperty(org.apache.hadoop.hive.serde.Constants.SERIALIZATION_LIB);
  52. ;
  53. }
  54. public Class<? extends Deserializer> getDeserializerClass() {
  55. return deserializerClass;
  56. }
  57. public void setDeserializerClass(
  58. final Class<? extends Deserializer> serdeClass) {
  59. deserializerClass = serdeClass;
  60. }
  61. public Class<? extends InputFormat> getInputFileFormatClass() {
  62. return inputFileFormatClass;
  63. }
  64. /**
  65. * Return a deserializer object corresponding to the tableDesc.
  66. */
  67. public Deserializer getDeserializer() throws Exception {
  68. Deserializer de = deserializerClass.newInstance();
  69. de.initialize(null, properties);
  70. return de;
  71. }
  72. public void setInputFileFormatClass(
  73. final Class<? extends InputFormat> inputFileFormatClass) {
  74. this.inputFileFormatClass = inputFileFormatClass;
  75. }
  76. public Class<? extends HiveOutputFormat> getOutputFileFormatClass() {
  77. return outputFileFormatClass;
  78. }
  79. public void setOutputFileFormatClass(final Class<?> outputFileFormatClass) {
  80. this.outputFileFormatClass = HiveFileFormatUtils
  81. .getOutputFormatSubstitute(outputFileFormatClass);
  82. }
  83. @Explain(displayName = "properties", normalExplain = false)
  84. public java.util.Properties getProperties() {
  85. return properties;
  86. }
  87. public void setProperties(final java.util.Properties properties) {
  88. this.properties = properties;
  89. }
  90. public void setJobProperties(Map<String, String> jobProperties) {
  91. this.jobProperties = jobProperties;
  92. }
  93. @Explain(displayName = "jobProperties", normalExplain = false)
  94. public Map<String, String> getJobProperties() {
  95. return jobProperties;
  96. }
  97. /**
  98. * @return the serdeClassName
  99. */
  100. @Explain(displayName = "serde")
  101. public String getSerdeClassName() {
  102. return serdeClassName;
  103. }
  104. /**
  105. * @param serdeClassName
  106. * the serde Class Name to set
  107. */
  108. public void setSerdeClassName(String serdeClassName) {
  109. this.serdeClassName = serdeClassName;
  110. }
  111. @Explain(displayName = "name")
  112. public String getTableName() {
  113. return properties
  114. .getProperty(org.apache.hadoop.hive.metastore.api.Constants.META_TABLE_NAME);
  115. }
  116. @Explain(displayName = "input format")
  117. public String getInputFileFormatClassName() {
  118. return getInputFileFormatClass().getName();
  119. }
  120. @Explain(displayName = "output format")
  121. public String getOutputFileFormatClassName() {
  122. return getOutputFileFormatClass().getName();
  123. }
  124. public boolean isNonNative() {
  125. return (properties.getProperty(
  126. org.apache.hadoop.hive.metastore.api.Constants.META_TABLE_STORAGE)
  127. != null);
  128. }
  129. @Override
  130. public Object clone() {
  131. TableDesc ret = new TableDesc();
  132. ret.setSerdeClassName(serdeClassName);
  133. ret.setDeserializerClass(deserializerClass);
  134. ret.setInputFileFormatClass(inputFileFormatClass);
  135. ret.setOutputFileFormatClass(outputFileFormatClass);
  136. Properties newProp = new Properties();
  137. Enumeration<Object> keysProp = properties.keys();
  138. while (keysProp.hasMoreElements()) {
  139. Object key = keysProp.nextElement();
  140. newProp.put(key, properties.get(key));
  141. }
  142. ret.setProperties(newProp);
  143. if (jobProperties != null) {
  144. ret.jobProperties = new LinkedHashMap<String, String>(jobProperties);
  145. }
  146. return ret;
  147. }
  148. }