MCPcopy Create free account
hub / github.com/apache/arrow / ApplyOriginalMetadata

Function ApplyOriginalMetadata

cpp/src/parquet/arrow/schema.cc:1153–1219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1151}
1152
1153Result<bool> ApplyOriginalMetadata(const Field& origin_field, SchemaField* inferred) {
1154 bool modified = false;
1155
1156 auto& origin_type = origin_field.type();
1157
1158 // The origin was an extension type. This occurs when the ARROW:extension:name field
1159 // was present when the schema was written and that extension is registered when
1160 // the schema is read.
1161 if (origin_type->id() == ::arrow::Type::EXTENSION) {
1162 const auto& origin_extension_type =
1163 checked_cast<const ::arrow::ExtensionType&>(*origin_type);
1164
1165 // (Recursively) Apply the original storage metadata from the original storage field
1166 // This applies extension types to child elements, if any.
1167 auto origin_storage_field =
1168 origin_field.WithType(origin_extension_type.storage_type());
1169 RETURN_NOT_OK(ApplyOriginalStorageMetadata(*origin_storage_field, inferred));
1170
1171 // Use the inferred type after child updates for below checks to see if
1172 // we can restore an extension type on the output.
1173 const auto& inferred_type = inferred->field->type();
1174
1175 // Whether or not the inferred type is also an extension type. This can occur when
1176 // arrow_extensions_enabled is true in the ArrowReaderProperties. Extension types
1177 // are not currently inferred for any other reason.
1178 bool arrow_extension_inferred = inferred_type->id() == ::arrow::Type::EXTENSION;
1179
1180 // Check if the inferred storage type is compatible with the extension type
1181 // we're hoping to apply. We assume that if an extension type was inferred
1182 // that it was constructed with a valid storage type. Otherwise, we check with
1183 // extension types that we know about for valid storage, falling back to
1184 // storage type equality for extension types that we don't know about.
1185 std::string origin_extension_name = origin_extension_type.extension_name();
1186 bool extension_supports_inferred_storage;
1187
1188 if (origin_extension_name == "arrow.json") {
1189 extension_supports_inferred_storage =
1190 arrow_extension_inferred ||
1191 ::arrow::extension::JsonExtensionType::IsSupportedStorageType(
1192 inferred_type->id());
1193 } else if (origin_extension_name == "arrow.uuid") {
1194 extension_supports_inferred_storage =
1195 arrow_extension_inferred ||
1196 ::arrow::extension::UuidType::IsSupportedStorageType(inferred_type);
1197 } else if (origin_extension_name == "arrow.parquet.variant") {
1198 extension_supports_inferred_storage =
1199 arrow_extension_inferred ||
1200 ::arrow::extension::VariantExtensionType::IsSupportedStorageType(inferred_type);
1201 } else {
1202 extension_supports_inferred_storage =
1203 origin_extension_type.storage_type()->Equals(*inferred_type);
1204 }
1205
1206 // If the origin extension of the metadata we are about to apply supports
1207 // the Arrow storage type we would otherwise return, we restore the extension
1208 // type to the output.
1209 if (extension_supports_inferred_storage) {
1210 inferred->field = inferred->field->WithType(origin_type);

Callers 1

MakeMethod · 0.85

Calls 8

WithTypeMethod · 0.80
storage_typeMethod · 0.80
ARROW_ASSIGN_OR_RAISEFunction · 0.70
typeMethod · 0.45
idMethod · 0.45
extension_nameMethod · 0.45
EqualsMethod · 0.45

Tested by

no test coverage detected