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

Function FromByteArray

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

Source from the content-addressed store, hash-verified

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

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