Пример #1
0
 public static Expression create(Expression expression, PDataType toType) throws SQLException {
   return toType == expression.getDataType()
       ? expression
       : expression instanceof LiteralExpression
           ? LiteralExpression.newConstant(((LiteralExpression) expression).getValue(), toType)
           : new CoerceExpression(expression, toType);
 }
 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);
 }
Пример #3
0
 private static boolean testExpression(LiteralExpression literal, double expected)
     throws SQLException {
   List<Expression> expressions = Lists.newArrayList((Expression) literal);
   Expression sqrtFunction = new ExpFunction(expressions);
   ImmutableBytesWritable ptr = new ImmutableBytesWritable();
   boolean ret = sqrtFunction.evaluate(null, ptr);
   if (ret) {
     Double result =
         (Double) sqrtFunction.getDataType().toObject(ptr, sqrtFunction.getSortOrder());
     assertTrue(twoDoubleEquals(result.doubleValue(), expected));
   }
   return ret;
 }
  private static void testExpression(
      LiteralExpression array, LiteralExpression element, PhoenixArray expected)
      throws SQLException {
    List<Expression> expressions = Lists.newArrayList((Expression) element);
    expressions.add(array);

    Expression arrayPrependFunction = new ArrayPrependFunction(expressions);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    arrayPrependFunction.evaluate(null, ptr);
    PhoenixArray result =
        (PhoenixArray)
            arrayPrependFunction
                .getDataType()
                .toObject(
                    ptr, expressions.get(1).getSortOrder(), array.getMaxLength(), array.getScale());
    assertEquals(result, expected);
  }
  /**
   * Executes a CALL statement. It is assumed that the argument is of the correct type.
   *
   * @param cs a CompiledStatement of type CompiledStatement.CALL
   * @throws HsqlException if a database access error occurs
   * @return the result of executing the statement
   */
  private Result executeCallStatement(CompiledStatement cs) throws HsqlException {

    Expression e = cs.expression; // representing CALL
    Object o = e.getValue(session); // expression return value
    Result r;

    if (o instanceof Result) {
      return (Result) o;
    } else if (o instanceof jdbcResultSet) {
      return ((jdbcResultSet) o).rResult;
    }

    r = Result.newSingleColumnResult(DIProcedureInfo.RETURN_COLUMN_NAME, e.getDataType());

    Object[] row = new Object[1];

    row[0] = o;
    r.metaData.sClassName[0] = e.getValueClassName();

    r.add(row);

    return r;
  }