| 227 | } |
| 228 | |
| 229 | void ArrowReader::initialize() |
| 230 | { |
| 231 | if (Utils::iequals(FileUtils::extension(m_filename), ".feather")) |
| 232 | { |
| 233 | m_formatType = arrowsupport::Feather; |
| 234 | } |
| 235 | else if (Utils::iequals(FileUtils::extension(m_filename), ".parquet")) |
| 236 | { |
| 237 | m_formatType = arrowsupport::Parquet; |
| 238 | } |
| 239 | if (m_formatTypeString.size()) |
| 240 | { |
| 241 | |
| 242 | if (Utils::iequals(m_formatTypeString, "geoarrow")) |
| 243 | m_formatType = arrowsupport::Feather; |
| 244 | else if (Utils::iequals(m_formatTypeString, "geoparquet")) |
| 245 | m_formatType = arrowsupport::Parquet; |
| 246 | else |
| 247 | throwError("Unknown format type " + m_formatTypeString); |
| 248 | |
| 249 | } |
| 250 | |
| 251 | auto result = arrow::io::ReadableFile::Open(m_filename); |
| 252 | if (result.ok()) |
| 253 | m_file = result.ValueOrDie(); |
| 254 | else |
| 255 | { |
| 256 | std::stringstream msg; |
| 257 | msg << "Unable to open '" << m_filename << "' for to read data with message '" |
| 258 | << result.status().ToString() <<"'"; |
| 259 | throwError(msg.str()); |
| 260 | } |
| 261 | |
| 262 | if (m_formatType == arrowsupport::Feather) |
| 263 | { |
| 264 | auto status = arrow::ipc::RecordBatchFileReader::Open(m_file); |
| 265 | if (!status.ok()) |
| 266 | { |
| 267 | std::stringstream msg; |
| 268 | msg << "Unable to create RecordBatchFileReader for file '" << m_filename << "' with message '" |
| 269 | << result.status().ToString() <<"'"; |
| 270 | throwError(msg.str()); |
| 271 | } |
| 272 | |
| 273 | m_ipcReader = status.ValueOrDie(); |
| 274 | m_batchCount = m_ipcReader->num_record_batches(); |
| 275 | |
| 276 | const auto fields = m_ipcReader->schema()->fields(); |
| 277 | |
| 278 | for (const auto& field: fields) |
| 279 | { |
| 280 | auto metadata = field->metadata(); |
| 281 | if (metadata) |
| 282 | if (metadata->Contains("ARROW:extension:metadata")) |
| 283 | loadArrowGeoMetadata(metadata); |
| 284 | } |
| 285 | |
| 286 | m_currentBatchIndex = 0; |