|
| 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 | + |
| 18 | +package org.apache.spark.sql.connector.expressions.filter; |
| 19 | + |
| 20 | +import java.util.Objects; |
| 21 | + |
| 22 | +import org.apache.spark.annotation.Evolving; |
| 23 | +import org.apache.spark.sql.connector.expressions.NamedReference; |
| 24 | + |
| 25 | +/** |
| 26 | + * Base class for {@link And}, {@link Or} |
| 27 | + * |
| 28 | + * @since 3.3.0 |
| 29 | + */ |
| 30 | +@Evolving |
| 31 | +abstract class BinaryFilter extends Filter { |
| 32 | + protected final Filter left; |
| 33 | + protected final Filter right; |
| 34 | + |
| 35 | + protected BinaryFilter(Filter left, Filter right) { |
| 36 | + this.left = left; |
| 37 | + this.right = right; |
| 38 | + } |
| 39 | + |
| 40 | + public Filter left() { return left; } |
| 41 | + public Filter right() { return right; } |
| 42 | + |
| 43 | + @Override |
| 44 | + public boolean equals(Object o) { |
| 45 | + if (this == o) return true; |
| 46 | + if (o == null || getClass() != o.getClass()) return false; |
| 47 | + BinaryFilter and = (BinaryFilter) o; |
| 48 | + return Objects.equals(left, and.left) && Objects.equals(right, and.right); |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public int hashCode() { |
| 53 | + return Objects.hash(left, right); |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public NamedReference[] references() { |
| 58 | + NamedReference[] refLeft = left.references(); |
| 59 | + NamedReference[] refRight = right.references(); |
| 60 | + NamedReference[] arr = new NamedReference[refLeft.length + refRight.length]; |
| 61 | + System.arraycopy(refLeft, 0, arr, 0, refLeft.length); |
| 62 | + System.arraycopy(refRight, 0, arr, refLeft.length, refRight.length); |
| 63 | + return arr; |
| 64 | + } |
| 65 | +} |
0 commit comments