@Override public final Object getValue(Tuple tuple, PDataType type, ImmutableBytesWritable ptr) throws SQLException { try { Expression expression = getExpression(); if (!expression.evaluate(tuple, ptr)) { return null; } if (ptr.getLength() == 0) { return null; } return type.toObject( ptr, expression.getDataType(), expression.getSortOrder(), expression.getMaxLength(), expression.getScale()); } catch (RuntimeException e) { // FIXME: Expression.evaluate does not throw SQLException // so this will unwrap throws from that. if (e.getCause() instanceof SQLException) { throw (SQLException) e.getCause(); } throw e; } }
private void evaluateAndAssertResult( Expression expression, Object expectedResult, String context) { context = context == null ? "" : context; ImmutableBytesWritable ptr = new ImmutableBytesWritable(); assertTrue(expression.evaluate(null, ptr)); PDataType dataType = expression.getDataType(); SortOrder sortOrder = expression.getSortOrder(); Object result = dataType.toObject(ptr.get(), ptr.getOffset(), ptr.getLength(), dataType, sortOrder); assertEquals(context, expectedResult, result); }