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

Function FromByteArray

cpp/src/parquet/arrow/schema_internal.cc:124–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122}
123
124Result<std::shared_ptr<ArrowType>> FromByteArray(
125 const LogicalType& logical_type, const ArrowReaderProperties& reader_properties,
126 const std::shared_ptr<const ::arrow::KeyValueMetadata>& metadata) {
127 auto binary_type = [&]() -> Result<std::shared_ptr<ArrowType>> {
128 const auto configured_binary_type = reader_properties.binary_type();
129 switch (configured_binary_type) {
130 case ::arrow::Type::BINARY:
131 return ::arrow::binary();
132 case ::arrow::Type::LARGE_BINARY:
133 return ::arrow::large_binary();
134 case ::arrow::Type::BINARY_VIEW:
135 return ::arrow::binary_view();
136 default:
137 return Status::TypeError("Invalid Arrow type for BYTE_ARRAY columns: ",
138 ::arrow::internal::ToString(configured_binary_type));
139 }
140 };
141
142 auto utf8_type = [&]() -> Result<std::shared_ptr<ArrowType>> {
143 const auto configured_binary_type = reader_properties.binary_type();
144 switch (configured_binary_type) {
145 case ::arrow::Type::BINARY:
146 return ::arrow::utf8();
147 case ::arrow::Type::LARGE_BINARY:
148 return ::arrow::large_utf8();
149 case ::arrow::Type::BINARY_VIEW:
150 return ::arrow::utf8_view();
151 default:
152 return Status::TypeError("Invalid Arrow type for BYTE_ARRAY columns: ",
153 ::arrow::internal::ToString(configured_binary_type));
154 }
155 };
156
157 switch (logical_type.type()) {
158 case LogicalType::Type::STRING:
159 return utf8_type();
160 case LogicalType::Type::DECIMAL:
161 return MakeArrowDecimal(logical_type, reader_properties.smallest_decimal_enabled());
162 case LogicalType::Type::NONE:
163 case LogicalType::Type::ENUM:
164 case LogicalType::Type::BSON:
165 return binary_type();
166 case LogicalType::Type::JSON: {
167 if (reader_properties.get_arrow_extensions_enabled()) {
168 return utf8_type().Map(::arrow::extension::json);
169 }
170 // When the original Arrow schema isn't stored and Arrow extensions are disabled,
171 // LogicalType::JSON is read as utf8().
172 return utf8_type();
173 }
174 case LogicalType::Type::GEOMETRY:
175 case LogicalType::Type::GEOGRAPHY: {
176 ARROW_ASSIGN_OR_RAISE(auto storage_type, binary_type());
177 if (reader_properties.get_arrow_extensions_enabled()) {
178 // Attempt creating a GeoArrow extension type (or return the default
179 // binary_type if types are not registered)
180 return GeoArrowTypeFromLogicalType(logical_type, metadata, storage_type);
181 }

Callers 1

GetArrowTypeFunction · 0.85

Calls 9

MakeArrowDecimalFunction · 0.85
binary_typeFunction · 0.85
TypeErrorFunction · 0.50
ToStringFunction · 0.50
NotImplementedFunction · 0.50
typeMethod · 0.45
MapMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected