PageRenderTime 23ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/ql/src/java/org/apache/hadoop/hive/ql/exec/persistence/MapJoinDoubleKeys.java

https://github.com/steeve/hive
Java | 184 lines | 114 code | 31 blank | 39 comment | 32 complexity | 0b59e5fc94797f27dbcfc4f55fe605f6 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.exec.persistence;
  19. import java.io.IOException;
  20. import java.io.ObjectInput;
  21. import java.io.ObjectOutput;
  22. import java.util.ArrayList;
  23. import org.apache.hadoop.hive.ql.exec.MapJoinMetaData;
  24. import org.apache.hadoop.hive.ql.exec.HashTableSinkOperator.HashTableSinkObjectCtx;
  25. import org.apache.hadoop.hive.serde2.SerDeException;
  26. import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils;
  27. import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils.ObjectInspectorCopyOption;
  28. import org.apache.hadoop.io.Writable;
  29. public class MapJoinDoubleKeys extends AbstractMapJoinKey {
  30. protected transient Object obj1;
  31. protected transient Object obj2;
  32. public MapJoinDoubleKeys() {
  33. }
  34. /**
  35. * @param metadataTag
  36. * @param obj
  37. */
  38. public MapJoinDoubleKeys(Object obj1, Object obj2) {
  39. this.obj1 = obj1;
  40. this.obj2 = obj2;
  41. }
  42. @Override
  43. public boolean equals(Object o) {
  44. if (o instanceof MapJoinDoubleKeys) {
  45. MapJoinDoubleKeys mObj = (MapJoinDoubleKeys) o;
  46. Object key1 = mObj.getObj1();
  47. Object key2 = mObj.getObj2();
  48. if ((obj1 == null) && (key1 == null)) {
  49. if ((obj2 == null) && (key2 == null)) {
  50. return true;
  51. }
  52. }
  53. if ((obj1 != null) && (key1 != null)) {
  54. if (obj1.equals(key1)) {
  55. if ((obj2 != null) && (key2 != null)) {
  56. if (obj2.equals(key2)) {
  57. return true;
  58. }
  59. }
  60. }
  61. }
  62. }
  63. return false;
  64. }
  65. @Override
  66. public int hashCode() {
  67. int hashCode = 1;
  68. if (obj1 == null) {
  69. hashCode = metadataTag;
  70. } else {
  71. hashCode += (31 + obj1.hashCode());
  72. }
  73. if (obj2 == null) {
  74. hashCode += metadataTag;
  75. } else {
  76. hashCode += (31 + obj2.hashCode());
  77. }
  78. return hashCode;
  79. }
  80. @Override
  81. public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
  82. try {
  83. // get the tableDesc from the map stored in the mapjoin operator
  84. HashTableSinkObjectCtx ctx = MapJoinMetaData.get(Integer.valueOf(metadataTag));
  85. Writable val = ctx.getSerDe().getSerializedClass().newInstance();
  86. val.readFields(in);
  87. ArrayList<Object> list = (ArrayList<Object>) ObjectInspectorUtils.copyToStandardObject(ctx
  88. .getSerDe().deserialize(val), ctx.getSerDe().getObjectInspector(),
  89. ObjectInspectorCopyOption.WRITABLE);
  90. if (list == null) {
  91. obj1 = null;
  92. obj2 = null;
  93. } else {
  94. obj1 = list.get(0);
  95. obj2 = list.get(1);
  96. }
  97. } catch (Exception e) {
  98. throw new IOException(e);
  99. }
  100. }
  101. @Override
  102. public void writeExternal(ObjectOutput out) throws IOException {
  103. try {
  104. // out.writeInt(metadataTag);
  105. // get the tableDesc from the map stored in the mapjoin operator
  106. HashTableSinkObjectCtx ctx = MapJoinMetaData.get(Integer.valueOf(metadataTag));
  107. ArrayList<Object> list = MapJoinMetaData.getList();
  108. list.add(obj1);
  109. list.add(obj2);
  110. // Different processing for key and value
  111. Writable outVal = ctx.getSerDe().serialize(list, ctx.getStandardOI());
  112. outVal.write(out);
  113. } catch (SerDeException e) {
  114. throw new IOException(e);
  115. }
  116. }
  117. /**
  118. * @return the obj
  119. */
  120. public Object getObj1() {
  121. return obj1;
  122. }
  123. /**
  124. * @param obj
  125. * the obj to set
  126. */
  127. public void setObj1(Object obj1) {
  128. this.obj1 = obj1;
  129. }
  130. /**
  131. * @return the obj
  132. */
  133. public Object getObj2() {
  134. return obj2;
  135. }
  136. /**
  137. * @param obj
  138. * the obj to set
  139. */
  140. public void setObj2(Object obj2) {
  141. this.obj2 = obj2;
  142. }
  143. @Override
  144. public boolean hasAnyNulls() {
  145. if (obj1 == null) {
  146. return true;
  147. }
  148. if (obj2 == null) {
  149. return true;
  150. }
  151. return false;
  152. }
  153. }