Skip to content

Commit

Permalink
Merge pull request #334 from folio-org/MODFQMMGR-373-arrays
Browse files Browse the repository at this point in the history
MODFQMMGR-373 Fix bug with contains_all
  • Loading branch information
mweaver-ebsco committed Jul 19, 2024
2 parents 3f3da1f + ada773c commit ae0c2f6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
11 changes: 2 additions & 9 deletions src/main/java/org/folio/fqm/repository/IdStreamer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.folio.fql.model.Fql;
import org.folio.querytool.domain.dto.EntityType;
import org.folio.querytool.domain.dto.EntityTypeDefaultSort;
import org.folio.querytool.domain.dto.EntityTypeSource;
import org.jooq.Condition;
import org.jooq.Cursor;
import org.jooq.DSLContext;
Expand Down Expand Up @@ -82,12 +81,6 @@ private int streamIdsInBatch(EntityType entityType,
Consumer<IdsWithCancelCallback> idsConsumer) {
String finalJoinClause = entityTypeFlatteningService.getJoinClause(entityType);
Field<String[]> idValueGetter = IdColumnUtils.getResultIdValueGetter(entityType);
String finalWhereClause = sqlWhereClause.toString();
for (EntityTypeSource source : entityType.getSources()) {
String toReplace = ":" + source.getAlias();
String alias = "\"" + source.getAlias() + "\"";
finalWhereClause = finalWhereClause.replace(toReplace, alias);
}
ResultQuery<Record1<String[]>> query = null;
if (!isEmpty(entityType.getGroupByFields())) {
Field<?>[] groupByFields = entityType
Expand All @@ -100,15 +93,15 @@ private int streamIdsInBatch(EntityType entityType,
query = jooqContext.dsl()
.select(field(idValueGetter))
.from(finalJoinClause)
.where(finalWhereClause)
.where(sqlWhereClause)
.groupBy(groupByFields)
.orderBy(getSortFields(entityType, sortResults))
.fetchSize(batchSize);
} else {
query = jooqContext.dsl()
.select(field(idValueGetter))
.from(finalJoinClause)
.where(finalWhereClause)
.where(sqlWhereClause)
.orderBy(getSortFields(entityType, sortResults))
.fetchSize(batchSize);
}
Expand Down
11 changes: 1 addition & 10 deletions src/main/java/org/folio/fqm/repository/ResultSetRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import org.folio.fql.model.Fql;
import org.folio.fqm.exception.FieldNotFoundException;
import org.folio.fqm.exception.EntityTypeNotFoundException;
import org.folio.fqm.service.EntityTypeFlatteningService;
import org.folio.fqm.service.FqlToSqlConverterService;
import org.folio.fqm.utils.IdColumnUtils;
Expand All @@ -23,7 +22,6 @@

import org.apache.commons.collections4.CollectionUtils;
import org.folio.querytool.domain.dto.EntityTypeColumn;
import org.folio.querytool.domain.dto.EntityTypeSource;
import org.jooq.Condition;
import org.jooq.DSLContext;
import org.jooq.Field;
Expand Down Expand Up @@ -124,13 +122,6 @@ public List<Map<String, Object>> getResultSet(UUID entityTypeId, Fql fql, List<S
}

Condition condition = FqlToSqlConverterService.getSqlCondition(fql.fqlCondition(), entityType);
// TODO: might want to put next 5 lines in its own method in EntityTypeFlatteningService
String finalWhereClause = condition.toString();
for (EntityTypeSource source : entityType.getSources()) {
String toReplace = ":" + source.getAlias();
String alias = "\"" + source.getAlias() + "\"";
finalWhereClause = finalWhereClause.replace(toReplace, alias);
}
var fieldsToSelect = getSqlFields(entityType, fields);
String idColumnName = entityType
.getColumns()
Expand All @@ -143,7 +134,7 @@ public List<Map<String, Object>> getResultSet(UUID entityTypeId, Fql fql, List<S
String fromClause = entityTypeFlatteningService.getJoinClause(entityType);
var result = jooqContext.select(fieldsToSelect)
.from(fromClause)
.where(finalWhereClause)
.where(condition)
.and(afterIdCondition)
.orderBy(sortCriteria)
.limit(limit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,19 +511,19 @@
},
},
isIdColumn: false,
queryable: false,
queryable: true,
visibleByDefault: false,
valueGetter: "(\
SELECT\
array_agg(elems.value::text)\
FROM\
jsonb_array_elements(:sourceAlias.jsonb->'departments') AS elems\
jsonb_array_elements_text(:sourceAlias.jsonb->'departments') AS elems\
)",
filterValueGetter: "(\
SELECT\
array_agg(lower(elems.value::text))\
FROM\
jsonb_array_elements(:sourceAlias.jsonb->'departments') AS elems\
jsonb_array_elements_text(:sourceAlias.jsonb->'departments') AS elems\
)",
},
{
Expand Down

0 comments on commit ae0c2f6

Please sign in to comment.