|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | + * you may not use this file except in compliance with the License. |
| 4 | + * You may obtain a copy of the License at |
| 5 | + * |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * |
| 8 | + * Unless required by applicable law or agreed to in writing, software |
| 9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | + * See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + */ |
| 14 | +package com.facebook.presto.plugin.clp; |
| 15 | + |
| 16 | +import com.facebook.presto.spi.relation.RowExpression; |
| 17 | + |
| 18 | +import java.util.Optional; |
| 19 | + |
| 20 | +/** |
| 21 | + * Represents the result of converting a Presto RowExpression into a CLP-compatible KQL query. In |
| 22 | + * every case, `pushDownExpression` represents the part of the RowExpression that could be |
| 23 | + * converted to a KQL expression, and `remainingExpression` represents the part that could not be |
| 24 | + * converted. |
| 25 | + */ |
| 26 | +public class ClpExpression |
| 27 | +{ |
| 28 | + // Optional KQL query or column name representing the fully or partially translatable part of the expression. |
| 29 | + private final Optional<String> pushDownExpression; |
| 30 | + |
| 31 | + // The remaining (non-translatable) portion of the RowExpression, if any. |
| 32 | + private final Optional<RowExpression> remainingExpression; |
| 33 | + |
| 34 | + public ClpExpression(String pushDownExpression, RowExpression remainingExpression) |
| 35 | + { |
| 36 | + this.pushDownExpression = Optional.ofNullable(pushDownExpression); |
| 37 | + this.remainingExpression = Optional.ofNullable(remainingExpression); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Creates an empty ClpExpression with neither pushdown nor remaining expressions. |
| 42 | + */ |
| 43 | + public ClpExpression() |
| 44 | + { |
| 45 | + this(null, null); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Creates a ClpExpression from a fully translatable KQL query or column name. |
| 50 | + * |
| 51 | + * @param pushDownExpression |
| 52 | + */ |
| 53 | + public ClpExpression(String pushDownExpression) |
| 54 | + { |
| 55 | + this(pushDownExpression, null); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Creates a ClpExpression from a non-translatable RowExpression. |
| 60 | + * |
| 61 | + * @param remainingExpression |
| 62 | + */ |
| 63 | + public ClpExpression(RowExpression remainingExpression) |
| 64 | + { |
| 65 | + this(null, remainingExpression); |
| 66 | + } |
| 67 | + |
| 68 | + public Optional<String> getPushDownExpression() |
| 69 | + { |
| 70 | + return pushDownExpression; |
| 71 | + } |
| 72 | + |
| 73 | + public Optional<RowExpression> getRemainingExpression() |
| 74 | + { |
| 75 | + return remainingExpression; |
| 76 | + } |
| 77 | +} |
0 commit comments