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

Apply count and startindex to queries without SORTBY/FILTER in blob mode #1467

Merged
merged 1 commit into from
May 12, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
import org.deegree.commons.utils.kvp.InvalidParameterValueException;
import org.deegree.cs.coordinatesystems.ICRS;
import org.deegree.cs.persistence.CRSManager;
import org.deegree.cs.refs.coordinatesystem.CRSRef;
import org.deegree.db.ConnectionProvider;
import org.deegree.db.ConnectionProviderProvider;
import org.deegree.feature.Feature;
Expand Down Expand Up @@ -1011,10 +1010,10 @@ public FeatureInputStream query( final Query[] queries )
}
}

boolean isMaxFeaturesAndStartIndexApplicable = isMaxFeaturesAndStartIndexApplicable( queries );
if ( wmsStyleQuery ) {
return queryMultipleFts( queries, env );
return queryMultipleFtsFromBlob( queries, env, isMaxFeaturesAndStartIndexApplicable );
}
boolean isMaxFeaturesAndStartIndexApplicable = isMaxFeaturesAndStartIndexApplicable( queries );
Iterator<FeatureInputStream> rsIter = new Iterator<FeatureInputStream>() {
int i = 0;

Expand Down Expand Up @@ -1534,7 +1533,8 @@ private FeatureInputStream queryByOperatorFilter( Query query, List<QName> ftNam
return result;
}

private FeatureInputStream queryMultipleFts( Query[] queries, Envelope looseBBox )
private FeatureInputStream queryMultipleFtsFromBlob( Query[] queries, Envelope looseBBox,
boolean isMaxFeaturesAndStartIndexApplicable )
throws FeatureStoreException {
FeatureInputStream result = null;
Connection conn = null;
Expand All @@ -1547,14 +1547,20 @@ private FeatureInputStream queryMultipleFts( Query[] queries, Envelope looseBBox
blobWb = getWhereBuilderBlob( bboxFilter, conn );
}
conn = getConnection();
final short[] ftId = getQueriedFeatureTypeIds( queries );
final List<Short> ftIds = new ArrayList<>();
final StringBuilder sql = new StringBuilder();
for ( int i = 0; i < ftId.length; i++ ) {
for ( int i = 0; i < queries.length; i++ ) {
Query query = queries[i];
if ( query.getTypeNames() == null || query.getTypeNames().length > 1 ) {
String msg = "Join queries between multiple feature types are currently not supported.";
throw new UnsupportedOperationException( msg );
}
short ftId = getFtId( query.getTypeNames()[0].getFeatureTypeName() );
if ( i > 0 ) {
sql.append( " UNION " );
}
sql.append( "SELECT gml_id,binary_object" );
if ( ftId.length > 1 ) {
if ( queries.length > 1 ) {
sql.append( "," );
sql.append( i );
sql.append( " AS QUERY_POS" );
Expand All @@ -1565,14 +1571,18 @@ private FeatureInputStream queryMultipleFts( Query[] queries, Envelope looseBBox
if ( looseBBox != null ) {
sql.append( " AND gml_bounded_by && ?" );
}
if (isMaxFeaturesAndStartIndexApplicable) {
appendOffsetAndFetch(sql, query.getMaxFeatures(), query.getStartIndex());
}
ftIds.add( ftId );
}
if ( ftId.length > 1 ) {
if ( queries.length > 1 ) {
sql.append( " ORDER BY QUERY_POS" );
}
stmt = conn.prepareStatement( sql.toString() );
stmt.setFetchSize( fetchSize );
int argIdx = 1;
for ( final short ftId2 : ftId ) {
for ( final short ftId2 : ftIds ) {
stmt.setShort( argIdx++, ftId2 );
if ( blobWb != null && blobWb.getWhere() != null ) {
for ( SQLArgument o : blobWb.getWhere().getArguments() ) {
Expand All @@ -1595,19 +1605,6 @@ private FeatureInputStream queryMultipleFts( Query[] queries, Envelope looseBBox
return result;
}

private short[] getQueriedFeatureTypeIds( Query[] queries ) {
short[] ftId = new short[queries.length];
for ( int i = 0; i < ftId.length; i++ ) {
Query query = queries[i];
if ( query.getTypeNames() == null || query.getTypeNames().length > 1 ) {
String msg = "Join queries between multiple feature types are currently not supported.";
throw new UnsupportedOperationException( msg );
}
ftId[i] = getFtId( query.getTypeNames()[0].getFeatureTypeName() );
}
return ftId;
}

private AbstractWhereBuilder getWhereBuilder( Collection<FeatureTypeMapping> ftMappings, OperatorFilter filter, SortProperty[] sortCrit,
boolean handleStrict )
throws FilterEvaluationException, UnmappableException {
Expand Down