/** * Get the current value of the expression. * * @param session the session * @return the value */ public Value getCurrentValue(Session session) { return expression.getValue(session); }
@Override public Value getValue(Session session) { return expr.getValue(session); }
private static Value getNullOrValue(Session session, Expression[] args, Value[] values, int i) { if (i >= args.length) { return null; } Value v = values[i]; if (v == null) { Expression e = args[i]; if (e == null) { return null; } v = values[i] = e.getValue(session); } return v; }
@Override public Value getValue(Session session) { Value[] v = new Value[list.length]; for (int i = 0; i < list.length; i++) { v[i] = list[i].getValue(session); } return ValueArray.get(v); }
private ValueResultSet getValueResultSet(Session session) { functionExpr = functionExpr.optimize(session); Value v = functionExpr.getValue(session); if (v == ValueNull.INSTANCE) { return null; } return (ValueResultSet) v; }
/** * Get the value in form of a boolean expression. * Returns true, false, or null. * In this database, everything can be a condition. * * @param session the session * @return the result */ public Boolean getBooleanValue(Session session) { return getValue(session).getBoolean(); }
@Override public Value getValue(Session session) { Value x = left.getValue(session); if (x == ValueNull.INSTANCE) { return x; } boolean result = valueSet.contains(x); if (!result) { boolean setHasNull = valueSet.contains(ValueNull.INSTANCE); if (setHasNull) { return ValueNull.INSTANCE; } } return ValueBoolean.get(result); }
@Override public Value getValue(Session session) { Value v = condition.getValue(session); if (v == ValueNull.INSTANCE) { return v; } return v.convertTo(Value.BOOLEAN).negate(); }
/** * Calculate and get the end value of this range. * * @param session the session * @return the end value */ public long getMax(Session session) { optimize(session); return max.getValue(session).getLong(); }
/** * Calculate and get the start value of this range. * * @param session the session * @return the start value */ public long getMin(Session session) { optimize(session); return min.getValue(session).getLong(); }
/** * Compute the value of this computed column. * * @param session the session * @param row the row * @return the value */ synchronized Value computeValue(Session session, Row row) { computeTableFilter.setSession(session); computeTableFilter.set(row); return defaultExpression.getValue(session); }
private int getIntValue() { expression = expression.optimize(session); return expression.getValue(session).getInt(); }
/** * Get the sample size, if set. * * @param session the session * @return the sample size */ int getSampleSizeValue(Session session) { if (sampleSizeExpr == null) { return 0; } Value v = sampleSizeExpr.optimize(session).getValue(session); if (v == ValueNull.INSTANCE) { return 0; } return v.getInt(); }
/** * Add an additional element if possible. Example: given two conditions * A IN(1, 2) OR A=3, the constant 3 is added: A IN(1, 2, 3). * * @param session the session * @param other the second condition * @return null if the condition was not added, or the new condition */ Expression getAdditional(Session session, Comparison other) { Expression add = other.getIfEquals(left); if (add != null) { if (add.isConstant()) { valueList.add(add); valueSet.add(add.getValue(session).convertTo(left.getType())); return this; } } return null; }
/** * Set the default expression. * * @param session the session * @param defaultExpression the default expression */ public void setDefaultExpression(Session session, Expression defaultExpression) { // also to test that no column names are used if (defaultExpression != null) { defaultExpression = defaultExpression.optimize(session); if (defaultExpression.isConstant()) { defaultExpression = ValueExpression.get( defaultExpression.getValue(session)); } } this.defaultExpression = defaultExpression; }
/** * @see http://dev.mysql.com/doc/refman/5.7/en/select.html */ @Override public SQLTranslated translate(Select select, ObjectNode executionOn, Map<ObjectNode, Map<TableFilter, ObjectNode>> consistencyTableNodes) { ArrayList<Expression> expressions = select.getExpressions(); Expression[] exprList = expressions.toArray(new Expression[expressions.size()]); Expression limitExpr = select.getLimit(); Expression offsetExpr = select.getOffset(); Integer limit = null, offset = null; if (limitExpr != null) { limit = limitExpr.getValue(select.getSession()).getInt(); } if (offsetExpr != null) { offset = offsetExpr.getValue(select.getSession()).getInt(); } return translate(select, executionOn, consistencyTableNodes, exprList, limit, offset); }
private String readString() { Expression expr = readExpression().optimize(session); if (!(expr instanceof ValueExpression)) { throw DbException.getSyntaxError(sqlCommand, parseIndex, "string"); } String s = expr.getValue(session).getString(); return s; }
@Override public ResultInterface query(int maxrows) { setCurrentRowNumber(1); Value v = expression.getValue(session); if (isResultSet) { v = v.convertTo(Value.RESULT_SET); ResultSet rs = v.getResultSet(); return LocalResult.read(session, rs, maxrows); } LocalResult result = new LocalResult(session, expressions, 1); Value[] row = {v}; result.addRow(row); result.done(); return result; }
@Override public Expression optimize(Session session) { Expression e2 = condition.getNotIfPossible(session); if (e2 != null) { return e2.optimize(session); } Expression expr = condition.optimize(session); if (expr.isConstant()) { Value v = expr.getValue(session); if (v == ValueNull.INSTANCE) { return ValueExpression.getNull(); } return ValueExpression.get(v.convertTo(Value.BOOLEAN).negate()); } condition = expr; return this; }
public void resetResult(ResultTarget result) { if(!isPrepared()) { throw DbException.throwInternalError("executor not prepared."); } if (result instanceof LocalResult) { LocalResult r = (LocalResult) result; if (limitPushless) { Expression offsetExpr = prepared.getOffset(); SortOrder sortOrder = prepared.getSortOrder(); int offset = offsetExpr.getValue(session).getInt(); if(sortOrder == null) { //drop offset rows if sortOrder is null while (offset-- > 0) { if (!next()) { break; } } r.setOffset(0); } } else { r.setOffset(0); } } }