image.png

    1. /*
    2. * Licensed to the Apache Software Foundation (ASF) under one or more
    3. * contributor license agreements. See the NOTICE file distributed with
    4. * this work for additional information regarding copyright ownership.
    5. * The ASF licenses this file to you under the Apache License, Version 2.0
    6. * (the "License"); you may not use this file except in compliance with
    7. * the License. You may obtain a copy of the License at
    8. *
    9. * http://www.apache.org/licenses/LICENSE-2.0
    10. *
    11. * Unless required by applicable law or agreed to in writing, software
    12. * distributed under the License is distributed on an "AS IS" BASIS,
    13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14. * See the License for the specific language governing permissions and
    15. * limitations under the License.
    16. */
    17. package org.apache.calcite.rex;
    18. import org.apache.calcite.rel.type.RelDataType;
    19. import org.apache.calcite.sql.SqlKind;
    20. import java.util.Collection;
    21. /**
    22. * Row expression.
    23. *
    24. * <p>Every row-expression has a type.
    25. * (Compare with {@link org.apache.calcite.sql.SqlNode}, which is created before
    26. * validation, and therefore types may not be available.)
    27. *
    28. * <p>Some common row-expressions are: {@link RexLiteral} (constant value),
    29. * {@link RexVariable} (variable), {@link RexCall} (call to operator with
    30. * operands). Expressions are generally created using a {@link RexBuilder}
    31. * factory.</p>
    32. *
    33. * <p>All sub-classes of RexNode are immutable.</p>
    34. */
    35. public abstract class RexNode {
    36. //~ Instance fields --------------------------------------------------------
    37. // Effectively final. Set in each sub-class constructor, and never re-set.
    38. // RexNode 的摘要信息
    39. protected String digest;
    40. //~ Methods ----------------------------------------------------------------
    41. public abstract RelDataType getType();
    42. /**
    43. * Returns whether this expression always returns true. (Such as if this
    44. * expression is equal to the literal <code>TRUE</code>.)
    45. */
    46. public boolean isAlwaysTrue() {
    47. return false;
    48. }
    49. /**
    50. * Returns whether this expression always returns false. (Such as if this
    51. * expression is equal to the literal <code>FALSE</code>.)
    52. */
    53. public boolean isAlwaysFalse() {
    54. return false;
    55. }
    56. public boolean isA(SqlKind kind) {
    57. return getKind() == kind;
    58. }
    59. public boolean isA(Collection<SqlKind> kinds) {
    60. return getKind().belongsTo(kinds);
    61. }
    62. /**
    63. * Returns the kind of node this is.
    64. *
    65. * @return Node kind, never null
    66. */
    67. public SqlKind getKind() {
    68. return SqlKind.OTHER;
    69. }
    70. public String toString() {
    71. return digest;
    72. }
    73. /**
    74. * Accepts a visitor, dispatching to the right overloaded
    75. * {@link RexVisitor#visitInputRef visitXxx} method.
    76. *
    77. * <p>Also see {@link RexUtil#apply(RexVisitor, java.util.List, RexNode)},
    78. * which applies a visitor to several expressions simultaneously.
    79. */
    80. public abstract <R> R accept(RexVisitor<R> visitor);
    81. /**
    82. * Accepts a visitor with a payload, dispatching to the right overloaded
    83. * {@link RexBiVisitor#visitInputRef(RexInputRef, Object)} visitXxx} method.
    84. */
    85. public abstract <R, P> R accept(RexBiVisitor<R, P> visitor, P arg);
    86. /** {@inheritDoc}
    87. *
    88. * <p>Every node must implement {@link #equals} based on its content
    89. */
    90. @Override public abstract boolean equals(Object obj);
    91. /** {@inheritDoc}
    92. *
    93. * <p>Every node must implement {@link #hashCode} consistent with
    94. * {@link #equals}
    95. */
    96. @Override public abstract int hashCode();
    97. }
    98. // End RexNode.java