| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public Expr optimizePos(final CmpOp op, final CompileContext cc) throws QueryException { |
| 100 | final Predicate<Expr> type = e -> { |
| 101 | final SeqType st = e.seqType(); |
| 102 | return st.one() && (st.type.instanceOf(BasicType.INTEGER) || st.type.isUntyped()); |
| 103 | }; |
| 104 | if(!type.test(exprs[0]) || !type.test(exprs[1])) return this; |
| 105 | |
| 106 | final Expr[] minMax = exprs.clone(); |
| 107 | final double mn = pos(minMax[0]), mx = pos(minMax[1]); |
| 108 | if(mx < mn) return Bln.FALSE; |
| 109 | |
| 110 | final boolean results = mn <= mx; |
| 111 | switch(op) { |
| 112 | case EQ: |
| 113 | if(mn <= 1 && mx >= LAST) return Bln.TRUE; |
| 114 | if(mn > LAST || mx < 1) return Bln.FALSE; |
| 115 | if(mn < 1) minMax[0] = Itr.ONE; |
| 116 | if(mn == LAST && mx > mn) minMax[1] = cc.function(Function.LAST, info); |
| 117 | if(mn < LAST && mx >= LAST) minMax[1] = Itr.MAX; |
| 118 | break; |
| 119 | case NE: |
| 120 | if(mn <= 1 && mx >= LAST) return Bln.FALSE; |
| 121 | if(results && (mn > LAST || mx < 1)) return Bln.TRUE; |
| 122 | if(mn < 1) minMax[0] = Itr.ONE; |
| 123 | if(mn == LAST && mx > mn) minMax[1] = cc.function(Function.LAST, info); |
| 124 | if(mn < LAST && mx >= LAST) minMax[1] = Itr.MAX; |
| 125 | break; |
| 126 | case LE: |
| 127 | if(mx < 1) return Bln.FALSE; |
| 128 | if(results && mx >= LAST) return Bln.TRUE; |
| 129 | if(mn < 1) minMax[0] = Itr.ONE; |
| 130 | break; |
| 131 | case LT: |
| 132 | if(mx <= 1) return Bln.FALSE; |
| 133 | if(results && mx > LAST) return Bln.TRUE; |
| 134 | break; |
| 135 | case GE: |
| 136 | if(mn > LAST) return Bln.FALSE; |
| 137 | if(results && mx <= 1) return Bln.TRUE; |
| 138 | break; |
| 139 | case GT: |
| 140 | if(mn >= LAST) return Bln.FALSE; |
| 141 | if(results && mx < 1) return Bln.TRUE; |
| 142 | break; |
| 143 | } |
| 144 | if(Arrays.equals(exprs, minMax)) return this; |
| 145 | final Expr ex = new Range(info, minMax).optimize(cc); |
| 146 | return ex == Empty.VALUE ? Bln.FALSE : ex; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Returns a static positional value for the specified expression. |