in c++/src/Writer.cc [622:727]
void WriterImpl::buildFooterType(const Type& t, proto::Footer& footer, uint32_t& index) {
proto::Type protoType;
protoType.set_maximum_length(static_cast<uint32_t>(t.getMaximumLength()));
protoType.set_precision(static_cast<uint32_t>(t.getPrecision()));
protoType.set_scale(static_cast<uint32_t>(t.getScale()));
switch (t.getKind()) {
case BOOLEAN: {
protoType.set_kind(proto::Type_Kind_BOOLEAN);
break;
}
case BYTE: {
protoType.set_kind(proto::Type_Kind_BYTE);
break;
}
case SHORT: {
protoType.set_kind(proto::Type_Kind_SHORT);
break;
}
case INT: {
protoType.set_kind(proto::Type_Kind_INT);
break;
}
case LONG: {
protoType.set_kind(proto::Type_Kind_LONG);
break;
}
case FLOAT: {
protoType.set_kind(proto::Type_Kind_FLOAT);
break;
}
case DOUBLE: {
protoType.set_kind(proto::Type_Kind_DOUBLE);
break;
}
case STRING: {
protoType.set_kind(proto::Type_Kind_STRING);
break;
}
case BINARY: {
protoType.set_kind(proto::Type_Kind_BINARY);
break;
}
case TIMESTAMP: {
protoType.set_kind(proto::Type_Kind_TIMESTAMP);
break;
}
case TIMESTAMP_INSTANT: {
protoType.set_kind(proto::Type_Kind_TIMESTAMP_INSTANT);
break;
}
case LIST: {
protoType.set_kind(proto::Type_Kind_LIST);
break;
}
case MAP: {
protoType.set_kind(proto::Type_Kind_MAP);
break;
}
case STRUCT: {
protoType.set_kind(proto::Type_Kind_STRUCT);
break;
}
case UNION: {
protoType.set_kind(proto::Type_Kind_UNION);
break;
}
case DECIMAL: {
protoType.set_kind(proto::Type_Kind_DECIMAL);
break;
}
case DATE: {
protoType.set_kind(proto::Type_Kind_DATE);
break;
}
case VARCHAR: {
protoType.set_kind(proto::Type_Kind_VARCHAR);
break;
}
case CHAR: {
protoType.set_kind(proto::Type_Kind_CHAR);
break;
}
default:
throw std::logic_error("Unknown type.");
}
for (auto& key : t.getAttributeKeys()) {
const auto& value = t.getAttributeValue(key);
auto protoAttr = protoType.add_attributes();
protoAttr->set_key(key);
protoAttr->set_value(value);
}
int pos = static_cast<int>(index);
*footer.add_types() = protoType;
for (uint64_t i = 0; i < t.getSubtypeCount(); ++i) {
// only add subtypes' field names if this type is STRUCT
if (t.getKind() == STRUCT) {
footer.mutable_types(pos)->add_field_names(t.getFieldName(i));
}
footer.mutable_types(pos)->add_subtypes(++index);
buildFooterType(*t.getSubtype(i), footer, index);
}
}