Skip to content

Commit

Permalink
casting / conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
hugopendlebury committed Feb 2, 2024
1 parent fd07696 commit a68a32d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/gribmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ using namespace std;

GribMessage::~GribMessage() {
//printf("Destuctor called on handle %p\n", h);
//codes_grib_nearest_delete()
codes_handle_delete(h);
}

Expand Down Expand Up @@ -345,6 +346,9 @@ using namespace std;
free(distances);
}




grib_nearest_find_multiple(h,1, inlats, inlons,
numberOfPoints, outlats, outlons, outvalues, distances, indexes);

Expand Down
23 changes: 16 additions & 7 deletions src/gribreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,37 @@ void GribReader::castConversionFields(std::shared_ptr<arrow::Table> locations, s
"division_value",
"ceiling_value"};

std::vector<std::shared_ptr<arrow::ChunkedArray>> resultsArray;
for (auto colName: f64_cols) {
auto col = table->GetColumnByName(colName).get();

cp::CastOptions castOptions;
castOptions.to_type = arrow::float64().get();

auto x = arrow::float64().get();
auto chunkVector = new arrow::ArrayVector();
for (auto chunk : col->chunks()) {
auto arr = chunk.get();
auto result = cp::Cast(*arr, castOptions.to_type, castOptions);
auto result = cp::Cast(*arr, arrow::float64().get(), castOptions);
if (result.ok()) {
auto converted = result.ValueOrDie();
//Ok it's converted do we need to update the table ?
chunkVector->emplace_back(converted);
} else{
std::string errMsg = "Unable to cast conversion column " + colName + " to float64";
throw new InvalidSchemaException(errMsg);
}
}
auto chunkedArrayResult = col->Make(*chunkVector, arrow::float64());
if(chunkedArrayResult.ok()) {
resultsArray.push_back(chunkedArrayResult.ValueOrDie());
}else {
std::string errMsg = "Unable to create arrow column for column " + colName;
throw new InvalidSchemaException(errMsg);
}

}


}

GribReader GribReader::withLocations(std::string path){
Expand Down Expand Up @@ -375,14 +389,9 @@ std::shared_ptr<arrow::Table> GribReader::getTableFromCsv(std::string path, arro
throw UnableToCreateArrowTableReaderException(errDetails);
}




} else {
throw NoSuchLocationsFileException(path);
}



}

Expand Down

0 comments on commit a68a32d

Please sign in to comment.