HHH-12798: Fix for nested spatial functions on SAP HANA
This commit is contained in:
parent
a9d5847fa9
commit
dfe0bcbbca
|
@ -57,18 +57,19 @@ public class HANASpatialFunction extends StandardSQLFunction {
|
||||||
if ( arguments.size() == 0 ) {
|
if ( arguments.size() == 0 ) {
|
||||||
return getName() + "()";
|
return getName() + "()";
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
final StringBuilder buf = new StringBuilder();
|
final StringBuilder buf = new StringBuilder();
|
||||||
int firstArgumentIndex;
|
int firstArgumentIndex;
|
||||||
if ( staticFunction ) {
|
if ( this.staticFunction ) {
|
||||||
// Add function call
|
// Add function call
|
||||||
buf.append( getName() );
|
buf.append( getName() );
|
||||||
firstArgumentIndex = 0;
|
firstArgumentIndex = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// If the first argument is an expression, e.g. a nested function, strip the .ST_AsEWKB() suffix
|
// If the first argument is an expression, e.g. a nested function, strip the .ST_AsEWKB() suffix
|
||||||
buf.append( stripEWKBSuffix( arguments.get( 0 ) ) );
|
Object argument = arguments.get( 0 );
|
||||||
|
final boolean parseFromWKB = ( "?".equals( argument ) );
|
||||||
|
appendArgument( argument, parseFromWKB, buf );
|
||||||
// Add function call
|
// Add function call
|
||||||
buf.append( "." ).append( getName() );
|
buf.append( "." ).append( getName() );
|
||||||
|
|
||||||
|
@ -83,13 +84,7 @@ public class HANASpatialFunction extends StandardSQLFunction {
|
||||||
// Check if first argument needs to be parsed from EWKB. This is the case if the first argument is a
|
// Check if first argument needs to be parsed from EWKB. This is the case if the first argument is a
|
||||||
// parameter that is set as EWKB or if it's a nested function call.
|
// parameter that is set as EWKB or if it's a nested function call.
|
||||||
final boolean parseFromWKB = ( isGeometryArgument( i ) && "?".equals( argument ) );
|
final boolean parseFromWKB = ( isGeometryArgument( i ) && "?".equals( argument ) );
|
||||||
if ( parseFromWKB ) {
|
appendArgument( argument, parseFromWKB, buf );
|
||||||
buf.append( "ST_GeomFromEWKB(" );
|
|
||||||
}
|
|
||||||
buf.append( stripEWKBSuffix( argument ) );
|
|
||||||
if ( parseFromWKB ) {
|
|
||||||
buf.append( ")" );
|
|
||||||
}
|
|
||||||
if ( i < arguments.size() - 1 ) {
|
if ( i < arguments.size() - 1 ) {
|
||||||
buf.append( ", " );
|
buf.append( ", " );
|
||||||
}
|
}
|
||||||
|
@ -101,7 +96,6 @@ public class HANASpatialFunction extends StandardSQLFunction {
|
||||||
}
|
}
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private Object stripEWKBSuffix(Object argument) {
|
private Object stripEWKBSuffix(Object argument) {
|
||||||
if ( ( argument instanceof String ) && ( (String) argument ).endsWith( AS_EWKB_SUFFIX ) ) {
|
if ( ( argument instanceof String ) && ( (String) argument ).endsWith( AS_EWKB_SUFFIX ) ) {
|
||||||
|
@ -115,4 +109,14 @@ public class HANASpatialFunction extends StandardSQLFunction {
|
||||||
private boolean isGeometryArgument(int idx) {
|
private boolean isGeometryArgument(int idx) {
|
||||||
return this.argumentIsGeometryTypeMask.size() > idx && this.argumentIsGeometryTypeMask.get( idx );
|
return this.argumentIsGeometryTypeMask.size() > idx && this.argumentIsGeometryTypeMask.get( idx );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void appendArgument(Object argument, boolean parseFromWKB, StringBuilder buf) {
|
||||||
|
if ( parseFromWKB ) {
|
||||||
|
buf.append( "ST_GeomFromEWKB(" );
|
||||||
|
}
|
||||||
|
buf.append( stripEWKBSuffix( argument ) );
|
||||||
|
if ( parseFromWKB ) {
|
||||||
|
buf.append( ")" );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1018,6 +1018,31 @@ public class TestHANASpatialFunctions extends TestSpatialFunctions {
|
||||||
retrieveHQLResultsAndCompare( dbexpected, hql, pckg );
|
retrieveHQLResultsAndCompare( dbexpected, hql, pckg );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_nestedfunction_on_jts() throws SQLException {
|
||||||
|
nestedfunction( JTS );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_nestedfunction_on_geolatte() throws SQLException {
|
||||||
|
nestedfunction( GEOLATTE );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void nestedfunction(String pckg) throws SQLException {
|
||||||
|
Map<Integer, Geometry> dbexpected = hanaExpectationsFactory.getNestedFunctionInner( expectationsFactory.getTestPolygon() );
|
||||||
|
String hql = format(
|
||||||
|
"SELECT id, geom FROM org.hibernate.spatial.integration.%s.GeomEntity g where dwithin(geom, srid(:filter, 0), 1) = true",
|
||||||
|
pckg );
|
||||||
|
Map<String, Object> params = createQueryParams( "filter", expectationsFactory.getTestPolygon() );
|
||||||
|
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||||
|
|
||||||
|
dbexpected = hanaExpectationsFactory.getNestedFunctionOuter( expectationsFactory.getTestPolygon() );
|
||||||
|
hql = format(
|
||||||
|
"SELECT id, geom FROM org.hibernate.spatial.integration.%s.GeomEntity g where dwithin(:filter, srid(geom, 0), 1) = true",
|
||||||
|
pckg );
|
||||||
|
retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg );
|
||||||
|
}
|
||||||
|
|
||||||
private String getGeometryTypeFromPackage(String pckg) {
|
private String getGeometryTypeFromPackage(String pckg) {
|
||||||
switch ( pckg ) {
|
switch ( pckg ) {
|
||||||
case GEOLATTE:
|
case GEOLATTE:
|
||||||
|
|
|
@ -1097,4 +1097,37 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory {
|
||||||
"select t.id, t.geom.ST_ZMin() from GeomTest t where t.geom.ST_SRID() = "
|
"select t.id, t.geom.ST_ZMin() from GeomTest t where t.geom.ST_SRID() = "
|
||||||
+ getTestSrid() );
|
+ getTestSrid() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the result of a nested function call with a parameter inside the inner function
|
||||||
|
*
|
||||||
|
* @return map of identifier, geometry
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
public Map<Integer, Geometry> getNestedFunctionInner(Geometry geom) throws SQLException {
|
||||||
|
return retrieveExpected( createNativeNestedFunctionInnerStatement( geom ), GEOMETRY );
|
||||||
|
}
|
||||||
|
|
||||||
|
private NativeSQLStatement createNativeNestedFunctionInnerStatement(Geometry geom) {
|
||||||
|
return createNativeSQLStatementAllWKTParams(
|
||||||
|
"select t.id, t.geom from GeomTest t where t.geom.ST_WithinDistance(ST_GeomFromText(?, " + getTestSrid()
|
||||||
|
+ ").ST_SRID(0), 1) = 1",
|
||||||
|
geom.toText() );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the result of a nested function call with a parameter inside the outer function
|
||||||
|
*
|
||||||
|
* @return map of identifier, geometry
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
public Map<Integer, Geometry> getNestedFunctionOuter(Geometry geom) throws SQLException {
|
||||||
|
return retrieveExpected( createNativeNestedFunctionOuterStatement( geom ), GEOMETRY );
|
||||||
|
}
|
||||||
|
|
||||||
|
private NativeSQLStatement createNativeNestedFunctionOuterStatement(Geometry geom) {
|
||||||
|
return createNativeSQLStatementAllWKTParams(
|
||||||
|
"select t.id, t.geom from GeomTest t where ST_GeomFromText(?, " + getTestSrid() + ").ST_WithinDistance(geom.ST_SRID(0), 1) = 1",
|
||||||
|
geom.toText() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue