Library of functions to extend H2 database with functions missing in compatibility modes.
Mainly for simplified integration testing in cases where running a real target database in container or standalone could be considered an overkill.
Aim is to provide missing functions, aggregations and types as compatible as possible, with minimal additional dependencies and targeting same minimal JDK version as H2 project, which is currently Java 11. Minimum H2 version that is compatible is 2.2.x.
Functions are split into modules to minimize dependency footprint and are dynamically registered
using the Java ServiceLoader mechanism.
Though the functions have a suite of tests, there might be differences to original DB functions and these are not optimized performance-wise - that means this library is intended for test usage and is not recommended for any production or mission-critical deployment.
testRuntimeOnly("cz.miou.h2:h2-[DB]-[FUNCTIONS]:1.1.0")<dependency>
<groupId>cz.miou.h2</groupId>
<artifactId>h2-[DB]-[FUNCTIONS]</artifactId>
<version>1.1.0</version>
<scope>test</scope>
</dependency>CREATE ALIAS IF NOT EXISTS H2_COMPATIBILITY FOR "cz.miou.h2.loader.Loader.load";
CALL H2_COMPATIBILITY();import java.sql.Connection;
import cz.miou.h2.Loader;
...
Connection connection = ... // JDBC connection for H2 database
Loader.load(connection);As a convenience option for projects using Flyway for handling database migrates,
it's possible to add a dependency to h2-loader-flyway module, that will automatically provide a migration with
version 0 targeting a H2 database environment, that would load all currently present functions.
testRuntimeOnly("cz.miou.h2:h2-loader-flyway:1.1.0")<dependency>
<groupId>cz.miou.h2</groupId>
<artifactId>h2-loader-flyway</artifactId>
<version>1.1.0</version>
<scope>test</scope>
</dependency>If for some reason some of the functions aren't compatible with H2 anymore, it's possible to exclude them by specifying cz.miou.h2.loader.exclude system property with a coma separated list of function names.
testRuntimeOnly("cz.miou.h2:h2-mariadb-all:1.1.0")<dependency>
<groupId>cz.miou.h2</groupId>
<artifactId>h2-mariadb-all</artifactId>
<version>1.1.0</version>
<scope>test</scope>
</dependency>In case a stricter control over dependencies is needed, it's possible to include only as specific module.
Module h2-mariadb-functions
List of supported functions
Module h2-mariadb-functions
List of supported functions
Module h2-mariadb-functions
List of supported functions
ADDDATEADDTIMEADD_MONTHSCONVERT_TZDATE_ADDDATE_FORMATDATE_SUBFORMAT_PICO_TIMEFROM_DAYSMAKEDATEMAKETIMEMICROSECONDPERIOD_ADDPERIOD_DIFFSEC_TO_TIMESTR_TO_DATESUBDATESUBTIMETIMETIMEDIFFTIMESTAMPTIME_FORMATTIME_TO_SECTO_DAYSTO_SECONDSUTC_DATEUTC_TIMEUTC_TIMEWEEKDAYWEEKOFYEARYEARWEEK
GET_FORMAT is intentionally left out because MariaDB requires a keyword
first argument, for example GET_FORMAT(DATE, 'EUR') which is not possible to replicate with H2.
Module h2-mariadb-inet
List of supported functions
Module h2-mariadb-crypto
List of supported functions
Module h2-mariadb-json
List of supported functions
JSON_ARRAY_APPENDJSON_ARRAY_INSERTJSON_ARRAY_INTERSECTJSON_COMPACTJSON_CONTAINSJSON_CONTAINS_PATHJSON_DEPTHJSON_DETAILEDJSON_EQUALSJSON_EXISTSJSON_EXTRACTJSON_INSERTJSON_KEYSJSON_KEY_VALUEJSON_LENGTHJSON_LOOSEJSON_MERGEJSON_MERGE_PATCHJSON_NORMALIZEJSON_OBJECT_FILTER_KEYSJSON_OBJECT_TO_ARRAYJSON_OVERLAPSJSON_QUERYJSON_QUOTEJSON_REMOVEJSON_REPLACEJSON_SEARCHJSON_SCHEMA_VALIDJSON_SETJSON_TYPEJSON_UNQUOTEJSON_VALIDJSON_VALUE
Module h2-mariadb-uuid
Module h2-mariadb-spatial
List of supported types
POINTLINESTRING(implemented in H2GIS)POLYGONMULTIPOINTMULTILINESTRINGMULTIPOLYGONGEOMETRYCOLLECTION
List of supported functions
AREA(implemented in H2GIS)AsBinary(implemented in H2GIS)AsText(implemented in H2GIS)AsWKB(implemented in H2GIS)AsWKT(implemented in H2GIS)BOUNDARY(implemented in H2GIS)BUFFER(implemented in H2GIS)CENTROID(implemented in H2GIS)CONTAINS(implemented in H2GIS)CONVEXHULL(implemented in H2GIS)CROSSES(implemented in H2GIS)DIMENSION(implemented in H2GIS)DISJOINT(implemented in H2GIS)ENDPOINT(implemented in H2GIS)EQUALS(implemented in H2GIS)EXTERIORRING(implemented in H2GIS)GEOMETRYCOLLECTIONGeomCollFromText(implemented in H2GIS)GeomCollFromWKB(implemented in H2GIS)GeometryCollectionFromText(implemented in H2GIS)GeometryCollectionFromWKB(implemented in H2GIS)GeometryFromText(implemented in H2GIS)GeometryFromWKB(implemented in H2GIS)GeometryN(implemented in H2GIS)GeometryType(implemented in H2GIS)GeomFromText(implemented in H2GIS)GeomFromWKB(implemented in H2GIS)GLENGTH(implemented in H2GIS)INTERIORRINGN(implemented in H2GIS)INTERSECTS(implemented in H2GIS)IsClosed(implemented in H2GIS)IsEmpty(implemented in H2GIS)IsRing(implemented in H2GIS)IsSimple(implemented in H2GIS)LINESTRINGLineFromText(implemented in H2GIS)LineFromWKB(implemented in H2GIS)LineStringFromText(implemented in H2GIS)LineStringFromWKB(implemented in H2GIS)MBRContainsMBRCoveredByMBRDisjointMBREqualMBREqualsMBRIntersectsMBROverlapsMBRTouchesMBRWithinMLineFromText(implemented in H2GIS)MLineFromWKB(implemented in H2GIS)MPointFromText(implemented in H2GIS)MPointFromWKB(implemented in H2GIS)MPolyFromText(implemented in H2GIS)MPolyFromWKB(implemented in H2GIS)MULTILINESTRINGMultiLineStringFromText(implemented in H2GIS)MultiLineStringFromWKB(implemented in H2GIS)MULTIPOINTMultiPointFromText(implemented in H2GIS)MultiPointFromWKB(implemented in H2GIS)MULTIPOLYGONMultiPolygonFromText(implemented in H2GIS)MultiPolygonFromWKB(implemented in H2GIS)NumGeometries(implemented in H2GIS)NumInteriorRings(implemented in H2GIS)NumPoints(implemented in H2GIS)OVERLAPS(implemented in H2GIS)POINT(implemented in H2GIS)PointFromText(implemented in H2GIS)PointFromWKB(implemented in H2GIS)PointN(implemented in H2GIS)PointOnSurface(implemented in H2GIS)POLYGONPolyFromText(implemented in H2GIS)PolyFromWKB(implemented in H2GIS)PolygonFromText(implemented in H2GIS)PolygonFromWKB(implemented in H2GIS)SRID(implemented in H2GIS)STARTPOINT(implemented in H2GIS)ST_AREA(implemented in H2GIS)ST_AsBinary(implemented in H2GIS)ST_AsGeoJSON(implemented in H2GIS)ST_AsText(implemented in H2GIS)ST_AsWKB(implemented in H2GIS)ST_AsWKT(implemented in H2GIS)ST_BOUNDARY(implemented in H2GIS)ST_BUFFER(implemented in H2GIS)ST_CENTROID(implemented in H2GIS)ST_Collect(implemented in H2GIS)ST_CONTAINS(implemented in H2GIS)ST_CONVEXHULL(implemented in H2GIS)ST_CROSSES(implemented in H2GIS)ST_DIFFERENCE(implemented in H2GIS)ST_DIMENSION(implemented in H2GIS)ST_DISJOINT(implemented in H2GIS)ST_DISTANCE(implemented in H2GIS)ST_DISTANCE_SPHEREST_ENDPOINT(implemented in H2GIS)ST_ENVELOPE(implemented in H2GIS)ST_EQUALS(implemented in H2GIS)ST_EXTERIORRING(implemented in H2GIS)ST_GeoHashST_GeomCollFromText(implemented in H2GIS)ST_GeomCollFromWKB(implemented in H2GIS)ST_GeomFromGeoJSON(implemented in H2GIS)ST_GeomFromText(implemented in H2GIS)ST_GeomFromWKB(implemented in H2GIS)ST_GEOMETRYN(implemented in H2GIS)ST_GEOMETRYTYPE(implemented in H2GIS)ST_GeometryCollectionFromText(implemented in H2GIS)ST_GeometryCollectionFromWKB(implemented in H2GIS)ST_GeometryFromText(implemented in H2GIS)ST_GeometryFromWKB(implemented in H2GIS)ST_INTERIORRINGN(implemented in H2GIS)ST_INTERSECTION(implemented in H2GIS)ST_INTERSECTS(implemented in H2GIS)ST_ISCLOSED(implemented in H2GIS)ST_ISEMPTY(implemented in H2GIS)ST_IsRing(implemented in H2GIS)ST_IsSimple(implemented in H2GIS)ST_IsValid(implemented in H2GIS)ST_LatFromGeoHashST_LENGTH(implemented in H2GIS)ST_LineFromText(implemented in H2GIS)ST_LineFromWKB(implemented in H2GIS)ST_LineStringFromText(implemented in H2GIS)ST_LineStringFromWKB(implemented in H2GIS)ST_LongFromGeoHashST_MLineFromText(implemented in H2GIS)ST_MLineFromWKB(implemented in H2GIS)ST_MPointFromText(implemented in H2GIS)ST_MPointFromWKB(implemented in H2GIS)ST_MPolyFromText(implemented in H2GIS)ST_MPolyFromWKB(implemented in H2GIS)ST_MultiLineStringFromText(implemented in H2GIS)ST_MultiLineStringFromWKB(implemented in H2GIS)ST_MultiPointFromText(implemented in H2GIS)ST_MultiPointFromWKB(implemented in H2GIS)ST_MultiPolygonFromText(implemented in H2GIS)ST_MultiPolygonFromWKB(implemented in H2GIS)ST_NUMGEOMETRIES(implemented in H2GIS)ST_NUMINTERIORRINGS(implemented in H2GIS)ST_NUMPOINTS(implemented in H2GIS)ST_OVERLAPS(implemented in H2GIS)ST_POINTN(implemented in H2GIS)ST_POINTONSURFACE(implemented in H2GIS)ST_PointFromGeoHashST_PointFromText(implemented in H2GIS)ST_PointFromWKB(implemented in H2GIS)ST_PolyFromText(implemented in H2GIS)ST_PolyFromWKB(implemented in H2GIS)ST_PolygonFromText(implemented in H2GIS)ST_PolygonFromWKB(implemented in H2GIS)ST_RELATE(implemented in H2GIS)ST_Simplify(implemented in H2GIS)ST_SRID(implemented in H2GIS)ST_STARTPOINT(implemented in H2GIS)ST_SYMDIFFERENCE(implemented in H2GIS)ST_TOUCHES(implemented in H2GIS)ST_UNION(implemented in H2GIS)ST_ValidateST_WITHIN(implemented in H2GIS)ST_X(implemented in H2GIS)ST_Y(implemented in H2GIS)TOUCHES(implemented in H2GIS)WITHIN(implemented in H2GIS)X(implemented in H2GIS)Y(implemented in H2GIS)
ENVELOPE is not supported because it collides with H2's built-in ENVELOPE aggregate function.
Due to how DATE, TIME and TIMESTAMP types in H2 works, the functions behave as if MariaDB had
ALLOW_INVALID_DATES, NO_ZERO_DATE and NO_ZERO_IN_DATE SQL modes disabled.