Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add h3_version function #113

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading