PageRenderTime 47ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/release-0.1-rc2/hive/external/ql/src/java/org/apache/hadoop/hive/ql/hooks/ReadEntity.java

#
Java | 197 lines | 96 code | 28 blank | 73 comment | 14 complexity | ce3efccff4a64be27f1a0f463b505c22 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, JSON, CPL-1.0
  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.hooks;
  19. import java.io.Serializable;
  20. import java.net.URI;
  21. import java.util.Map;
  22. import org.apache.hadoop.hive.ql.metadata.Partition;
  23. import org.apache.hadoop.hive.ql.metadata.Table;
  24. /**
  25. * This class encapsulates the information on the partition and tables that are
  26. * read by the query.
  27. */
  28. public class ReadEntity implements Serializable {
  29. private static final long serialVersionUID = 1L;
  30. /**
  31. * The table.
  32. */
  33. private Table t;
  34. /**
  35. * The partition. This is null for a non partitioned table.
  36. */
  37. private Partition p;
  38. /**
  39. * This is derived from t and p, but we need to serialize this field to make sure
  40. * ReadEntity.hashCode() does not need to recursively read into t and p.
  41. */
  42. private String name;
  43. public String getName() {
  44. return name;
  45. }
  46. public void setName(String name) {
  47. this.name = name;
  48. }
  49. public void setP(Partition p) {
  50. this.p = p;
  51. }
  52. public void setT(Table t) {
  53. this.t = t;
  54. }
  55. public Partition getP() {
  56. return p;
  57. }
  58. public Table getT() {
  59. return t;
  60. }
  61. /**
  62. * For serialization only.
  63. */
  64. public ReadEntity() {
  65. }
  66. /**
  67. * Constructor.
  68. *
  69. * @param t
  70. * The Table that the query reads from.
  71. */
  72. public ReadEntity(Table t) {
  73. this.t = t;
  74. p = null;
  75. name = computeName();
  76. }
  77. /**
  78. * Constructor given a partiton.
  79. *
  80. * @param p
  81. * The partition that the query reads from.
  82. */
  83. public ReadEntity(Partition p) {
  84. t = p.getTable();
  85. this.p = p;
  86. name = computeName();
  87. }
  88. private String computeName() {
  89. if (p != null) {
  90. return p.getTable().getDbName() + "@" + p.getTable().getTableName() + "@"
  91. + p.getName();
  92. } else {
  93. return t.getDbName() + "@" + t.getTableName();
  94. }
  95. }
  96. /**
  97. * Enum that tells what time of a read entity this is.
  98. */
  99. public static enum Type {
  100. TABLE, PARTITION
  101. };
  102. /**
  103. * Get the type.
  104. */
  105. public Type getType() {
  106. return p == null ? Type.TABLE : Type.PARTITION;
  107. }
  108. /**
  109. * Get the parameter map of the Entity.
  110. */
  111. public Map<String, String> getParameters() {
  112. if (p != null) {
  113. return p.getParameters();
  114. } else {
  115. return t.getParameters();
  116. }
  117. }
  118. /**
  119. * Get the location of the entity.
  120. */
  121. public URI getLocation() {
  122. if (p != null) {
  123. return p.getDataLocation();
  124. } else {
  125. return t.getDataLocation();
  126. }
  127. }
  128. /**
  129. * Get partition entity.
  130. */
  131. public Partition getPartition() {
  132. return p;
  133. }
  134. /**
  135. * Get table entity.
  136. */
  137. public Table getTable() {
  138. return t;
  139. }
  140. /**
  141. * toString function.
  142. */
  143. @Override
  144. public String toString() {
  145. return name;
  146. }
  147. /**
  148. * Equals function.
  149. */
  150. @Override
  151. public boolean equals(Object o) {
  152. if (o == null) {
  153. return false;
  154. }
  155. if (o instanceof ReadEntity) {
  156. ReadEntity ore = (ReadEntity) o;
  157. return (toString().equalsIgnoreCase(ore.toString()));
  158. } else {
  159. return false;
  160. }
  161. }
  162. /**
  163. * Hashcode function.
  164. */
  165. @Override
  166. public int hashCode() {
  167. return toString().hashCode();
  168. }
  169. }