| 1 |
/* |
| 2 |
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 3 |
* and the EPL 1.0 (https://h2database.com/html/license.html). |
| 4 |
* Initial Developer: H2 Group |
| 5 |
*/ |
| 6 |
package org.h2.expression; |
| 7 |
|
| 8 |
import org.h2.engine.SessionLocal; |
| 9 |
import org.h2.table.ColumnResolver; |
| 10 |
import org.h2.table.TableFilter; |
| 11 |
import org.h2.value.TypeInfo; |
| 12 |
|
| 13 |
/** |
| 14 |
* Operation with one or two arguments. |
| 15 |
*/ |
| 16 |
public abstract class Operation1_2 extends Expression { |
| 17 |
|
| 18 |
/** |
| 19 |
* The left part of the operation (the first argument). |
| 20 |
*/ |
| 21 |
protected Expression left; |
| 22 |
|
| 23 |
/** |
| 24 |
* The right part of the operation (the second argument). |
| 25 |
*/ |
| 26 |
protected Expression right; |
| 27 |
|
| 28 |
/** |
| 29 |
* The type of the result. |
| 30 |
*/ |
| 31 |
protected TypeInfo type; |
| 32 |
|
| 33 |
protected Operation1_2(Expression left, Expression right) { |
| 34 |
this.left = left; |
| 35 |
this.right = right; |
| 36 |
} |
| 37 |
|
| 38 |
@Override |
| 39 |
public TypeInfo getType() { |
| 40 |
return type; |
| 41 |
} |
| 42 |
|
| 43 |
@Override |
| 44 |
public void mapColumns(ColumnResolver resolver, int level, int state) { |
| 45 |
left.mapColumns(resolver, level, state); |
| 46 |
if (right != null) { |
| 47 |
right.mapColumns(resolver, level, state); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
@Override |
| 52 |
public void setEvaluatable(TableFilter tableFilter, boolean value) { |
| 53 |
left.setEvaluatable(tableFilter, value); |
| 54 |
if (right != null) { |
| 55 |
right.setEvaluatable(tableFilter, value); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
@Override |
| 60 |
public void updateAggregate(SessionLocal session, int stage) { |
| 61 |
left.updateAggregate(session, stage); |
| 62 |
if (right != null) { |
| 63 |
right.updateAggregate(session, stage); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
@Override |
| 68 |
public boolean isEverything(ExpressionVisitor visitor) { |
| 69 |
return left.isEverything(visitor) && (right == null || right.isEverything(visitor)); |
| 70 |
} |
| 71 |
|
| 72 |
@Override |
| 73 |
public int getCost() { |
| 74 |
int cost = left.getCost() + 1; |
| 75 |
if (right != null) { |
| 76 |
cost += right.getCost(); |
| 77 |
} |
| 78 |
return cost; |
| 79 |
} |
| 80 |
|
| 81 |
@Override |
| 82 |
public int getSubexpressionCount() { |
| 83 |
return right != null ? 2 : 1; |
| 84 |
} |
| 85 |
|
| 86 |
@Override |
| 87 |
public Expression getSubexpression(int index) { |
| 88 |
if (index == 0) { |
| 89 |
return left; |
| 90 |
} |
| 91 |
if (index == 1 && right != null) { |
| 92 |
return right; |
| 93 |
} |
| 94 |
throw new IndexOutOfBoundsException(); |
| 95 |
} |
| 96 |
|
| 97 |
} |