Skip to content

Commit

Permalink
add h3_version function
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacbrodsky committed Jun 26, 2024
1 parent 379789d commit ab78b0e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ one to use. The unsigned and signed APIs are identical. Many functions also supp
| `h3_great_circle_distance` | | Compute the great circle distance between two points (haversine)
| `h3_cells_to_multi_polygon_wkt` | [v](#fv) | Convert a set of cells to multipolygon WKT
| `h3_polygon_wkt_to_cells` | [u](#fu) | Convert polygon WKT to a set of cells
| `h3_version` | | Get the version of the H3 library

### Notes

Expand Down
15 changes: 15 additions & 0 deletions src/h3_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ static void GreatCircleDistanceFunction(DataChunk &args, ExpressionState &state,
}
}

static void VersionFunction(DataChunk &args, ExpressionState &state,
Vector &result) {
result.SetVectorType(VectorType::CONSTANT_VECTOR);
auto str = StringUtil::Format("%d.%d.%d", H3_VERSION_MAJOR, H3_VERSION_MINOR, H3_VERSION_PATCH);
string_t versionStr = string_t(strdup(str.c_str()), str.size());
result.SetValue(0, StringVector::AddString(result, versionStr));
}

CreateScalarFunctionInfo H3Functions::GetGetHexagonAreaAvgFunction() {
return CreateScalarFunctionInfo(ScalarFunction(
"h3_get_hexagon_area_avg", {LogicalType::INTEGER, LogicalType::VARCHAR},
Expand Down Expand Up @@ -334,4 +342,11 @@ CreateScalarFunctionInfo H3Functions::GetGreatCircleDistanceFunction() {
LogicalType::DOUBLE, GreatCircleDistanceFunction));
}

CreateScalarFunctionInfo H3Functions::GetVersionFunctions() {
return CreateScalarFunctionInfo(ScalarFunction(
"h3_version",
{},
LogicalType::VARCHAR, VersionFunction));
}

} // namespace duckdb
2 changes: 2 additions & 0 deletions src/include/h3_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class H3Functions {
functions.push_back(GetGetRes0CellsFunction());
functions.push_back(GetGetPentagonsFunction());
functions.push_back(GetGreatCircleDistanceFunction());
functions.push_back(GetVersionFunctions());

// Regions
functions.push_back(GetCellsToMultiPolygonWktFunction());
Expand Down Expand Up @@ -156,6 +157,7 @@ class H3Functions {
static CreateScalarFunctionInfo GetGetRes0CellsFunction();
static CreateScalarFunctionInfo GetGetPentagonsFunction();
static CreateScalarFunctionInfo GetGreatCircleDistanceFunction();
static CreateScalarFunctionInfo GetVersionFunctions();

// Regions
static CreateScalarFunctionInfo GetCellsToMultiPolygonWktFunction();
Expand Down
5 changes: 5 additions & 0 deletions test/sql/h3/h3_functions_misc.test
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,8 @@ query I
SELECT h3_great_circle_distance(5, 5, -15, -15, NULL)
----
NULL

query I
SELECT h3_version()
----
4.1.0

0 comments on commit ab78b0e

Please sign in to comment.