std::string TypeImpl::toString()

in c++/src/TypeImpl.cc [192:277]


  std::string TypeImpl::toString() const {
    switch (static_cast<int64_t>(kind_)) {
      case BOOLEAN:
        return "boolean";
      case BYTE:
        return "tinyint";
      case SHORT:
        return "smallint";
      case INT:
        return "int";
      case LONG:
        return "bigint";
      case FLOAT:
        return "float";
      case DOUBLE:
        return "double";
      case STRING:
        return "string";
      case BINARY:
        return "binary";
      case TIMESTAMP:
        return "timestamp";
      case TIMESTAMP_INSTANT:
        return "timestamp with local time zone";
      case LIST:
        return "array<" + (subTypes_[0] ? subTypes_[0]->toString() : "void") + ">";
      case MAP:
        return "map<" + (subTypes_[0] ? subTypes_[0]->toString() : "void") + "," +
               (subTypes_[1] ? subTypes_[1]->toString() : "void") + ">";
      case STRUCT: {
        std::string result = "struct<";
        for (size_t i = 0; i < subTypes_.size(); ++i) {
          if (i != 0) {
            result += ",";
          }
          if (isUnquotedFieldName(fieldNames_[i])) {
            result += fieldNames_[i];
          } else {
            std::string name(fieldNames_[i]);
            size_t pos = 0;
            while ((pos = name.find("`", pos)) != std::string::npos) {
              name.replace(pos, 1, "``");
              pos += 2;
            }
            result += "`";
            result += name;
            result += "`";
          }
          result += ":";
          result += subTypes_[i]->toString();
        }
        result += ">";
        return result;
      }
      case UNION: {
        std::string result = "uniontype<";
        for (size_t i = 0; i < subTypes_.size(); ++i) {
          if (i != 0) {
            result += ",";
          }
          result += subTypes_[i]->toString();
        }
        result += ">";
        return result;
      }
      case DECIMAL: {
        std::stringstream result;
        result << "decimal(" << precision_ << "," << scale_ << ")";
        return result.str();
      }
      case DATE:
        return "date";
      case VARCHAR: {
        std::stringstream result;
        result << "varchar(" << maxLength_ << ")";
        return result.str();
      }
      case CHAR: {
        std::stringstream result;
        result << "char(" << maxLength_ << ")";
        return result.str();
      }
      default:
        throw NotImplementedYet("Unknown type");
    }
  }