Exemple #1
0
expression::AbstractExpression *ExprTransformer::TransformConst(
    const Expr *es) {
  auto const_expr = reinterpret_cast<const Const *>(es);

  Value value;

  if (const_expr->constisnull) {  // Constant is null
    value = ValueFactory::GetNullValue();
  } else if (const_expr->constbyval) {  // non null
    value = TupleTransformer::GetValue(const_expr->constvalue,
                                       const_expr->consttype);
  } else if (const_expr->constlen == -1) {
    LOG_TRACE("Probably handing a string constant ");
    value = TupleTransformer::GetValue(const_expr->constvalue,
                                       const_expr->consttype);
  } else {
    LOG_ERROR(
        "Unknown Const profile: constlen = %d , constbyval = %d, constvalue = "
        "%lu ",
        const_expr->constlen, const_expr->constbyval,
        (long unsigned)const_expr->constvalue);
  }

  // A Const Expr has no children.
  if (const_expr->consttype == POSTGRES_VALUE_TYPE_TEXT_ARRAY ||
      const_expr->consttype == POSTGRES_VALUE_TYPE_INT2_ARRAY ||
      const_expr->consttype == POSTGRES_VALUE_TYPE_INT4_ARRAY ||
      const_expr->consttype == POSTGRES_VALUE_TYPE_FLOADT4_ARRAY ||
      const_expr->consttype == POSTGRES_VALUE_TYPE_OID_ARRAY ||
      const_expr->consttype == POSTGRES_VALUE_TYPE_BPCHAR2) {
    std::vector<expression::AbstractExpression *> vec_exprs;
    Value tmp_value;
    int vector_length = value.ArrayLength();
    for (int i = 0; i < vector_length; i++) {
      tmp_value = value.ItemAtIndex(i);
      std::string str = tmp_value.GetInfo();
      expression::AbstractExpression *ce =
          expression::ExpressionUtil::ConstantValueFactory(tmp_value);
      vec_exprs.push_back(ce);
    }
    // TODO: The following line is wrong. The first argument should be the
    //       the element type
    auto rv =
        expression::ExpressionUtil::VectorFactory(VALUE_TYPE_ARRAY, vec_exprs);
    return rv;
  } else {
    auto rv = expression::ExpressionUtil::ConstantValueFactory(value);
    return rv;
  }
}