/tags/release-0.0.0-rc0/hive/external/ql/src/java/org/apache/hadoop/hive/ql/plan/ExprNodeFieldDesc.java

# · Java · 125 lines · 81 code · 20 blank · 24 comment · 7 complexity · ae3f3d0455cfd8201bbe97cfe348d704 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.ArrayList;
  21. import java.util.List;
  22. import org.apache.hadoop.hive.ql.exec.Utilities;
  23. import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
  24. /**
  25. * ExprNodeFieldDesc.
  26. *
  27. */
  28. public class ExprNodeFieldDesc extends ExprNodeDesc implements Serializable {
  29. private static final long serialVersionUID = 1L;
  30. ExprNodeDesc desc;
  31. String fieldName;
  32. // Used to support a.b where a is a list of struct that contains a field
  33. // called b.
  34. // a.b will return an array that contains field b of all elements of array a.
  35. Boolean isList;
  36. public ExprNodeFieldDesc() {
  37. }
  38. public ExprNodeFieldDesc(TypeInfo typeInfo, ExprNodeDesc desc,
  39. String fieldName, Boolean isList) {
  40. super(typeInfo);
  41. this.desc = desc;
  42. this.fieldName = fieldName;
  43. this.isList = isList;
  44. }
  45. @Override
  46. public List<ExprNodeDesc> getChildren() {
  47. List<ExprNodeDesc> children = new ArrayList<ExprNodeDesc>(2);
  48. children.add(desc);
  49. return children;
  50. }
  51. public ExprNodeDesc getDesc() {
  52. return desc;
  53. }
  54. public void setDesc(ExprNodeDesc desc) {
  55. this.desc = desc;
  56. }
  57. public String getFieldName() {
  58. return fieldName;
  59. }
  60. public void setFieldName(String fieldName) {
  61. this.fieldName = fieldName;
  62. }
  63. public Boolean getIsList() {
  64. return isList;
  65. }
  66. public void setIsList(Boolean isList) {
  67. this.isList = isList;
  68. }
  69. @Override
  70. public String toString() {
  71. return desc.toString() + "." + fieldName;
  72. }
  73. @Explain(displayName = "expr")
  74. @Override
  75. public String getExprString() {
  76. return desc.getExprString() + "." + fieldName;
  77. }
  78. @Override
  79. public List<String> getCols() {
  80. List<String> colList = new ArrayList<String>();
  81. if (desc != null) {
  82. colList = Utilities.mergeUniqElems(colList, desc.getCols());
  83. }
  84. return colList;
  85. }
  86. @Override
  87. public ExprNodeDesc clone() {
  88. return new ExprNodeFieldDesc(typeInfo, desc, fieldName, isList);
  89. }
  90. @Override
  91. public boolean isSame(Object o) {
  92. if (!(o instanceof ExprNodeFieldDesc)) {
  93. return false;
  94. }
  95. ExprNodeFieldDesc dest = (ExprNodeFieldDesc) o;
  96. if (!typeInfo.equals(dest.getTypeInfo())) {
  97. return false;
  98. }
  99. if (!fieldName.equals(dest.getFieldName())
  100. || !isList.equals(dest.getIsList()) || !desc.isSame(dest.getDesc())) {
  101. return false;
  102. }
  103. return true;
  104. }
  105. }