Skip to content

Commit

Permalink
Remove LOWER functions on file properties/metadata
Browse files Browse the repository at this point in the history
Database queries for metadata or file properties cannot use indices if
the function LOWER is called on the select query. We therefore remove
the LOWER functions altogether. This is a breaking change, making
metadata queries case sensitive, but this copies the behaviour of iquest
calls or wildcard behaviour of imeta.

Signed-off-by: Peter Verraedt <[email protected]>
  • Loading branch information
peterverraedt authored and michael-conway committed Aug 24, 2022
1 parent 4b9b281 commit 3a3475a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public String getSpecQueryAsString() {
String val = addSQLCharToQueryParamBasedOnOperator(this.value);
String theUnit = addSQLCharToQueryParamBasedOnOperator(unit);

String attrQuery = hasAttr ? String.format(" LOWER( %s ) = LOWER( '%s' ) ", attrColName, this.attribute) : "";
String valueQuery = hasVal ? String.format(" LOWER( %s ) %s LOWER( %s ) ", valueColName, this.operator, val)
String attrQuery = hasAttr ? String.format(" %s = '%s' ", attrColName, this.attribute) : "";
String valueQuery = hasVal ? String.format(" %s %s %s ", valueColName, this.operator, val)
: "";
String unitQuery = hasUnit ? String.format(" LOWER( %s ) %s LOWER( %s ) ", unitColName, this.operator, theUnit)
String unitQuery = hasUnit ? String.format(" %s %s %s ", unitColName, this.operator, theUnit)
: "";

if (hasAttr && (hasVal || hasUnit)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void testGetSpecQueryAsString() {
String queryString = dataGridMetadataSearch.getSpecQueryAsString();
Assert.assertNotNull(queryString);
Assert.assertEquals(
" SELECT map.object_id AS map_object_id FROM R_OBJT_METAMAP map JOIN ( SELECT m.meta_id, m.meta_attr_name, m.meta_attr_value FROM R_META_MAIN m WHERE LOWER( m.meta_attr_name ) = LOWER( 'Sîne klâwen durh die wolken sint geslagen' ) AND LOWER( m.meta_attr_value ) = LOWER( 'На берегу пустынных волн' ) AND LOWER( m.meta_attr_unit ) = LOWER( 'Ég get etið gler án þess að meiða mig' ) ) AS metadata ON (metadata.meta_id = map.meta_id) GROUP BY map.object_id HAVING COUNT(map.meta_id) > 0 ",
" SELECT map.object_id AS map_object_id FROM R_OBJT_METAMAP map JOIN ( SELECT m.meta_id, m.meta_attr_name, m.meta_attr_value FROM R_META_MAIN m WHERE ( m.meta_attr_name ) = ( 'Sîne klâwen durh die wolken sint geslagen' ) AND ( m.meta_attr_value ) = ( 'На берегу пустынных волн' ) AND ( m.meta_attr_unit ) = ( 'Ég get etið gler án þess að meiða mig' ) ) AS metadata ON (metadata.meta_id = map.meta_id) GROUP BY map.object_id HAVING COUNT(map.meta_id) > 0 ",
queryString);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,15 @@ public String buildWhereClauseForDataGridPropertySearch(FilePropertyField inAttr
|| inAttribute == FilePropertyField.MODIFICATION_DATE;

if (inOperator == DataGridSearchOperatorEnum.LIKE || inOperator == DataGridSearchOperatorEnum.NOT_LIKE) {
whereClause = String.format(" LOWER( fileProperties.%s ) %s LOWER( '%%%s%%' )", attribute, operator, value);
whereClause = String.format(" fileProperties.%s %s '%%%s%%'", attribute, operator, value);
} else if (isAttributeEqualsDate && inOperator == DataGridSearchOperatorEnum.EQUAL) {
whereClause = String.format(" fileProperties.%s BETWEEN %s AND %d", attribute, value,
Long.parseLong(value) + 60);
} else if (isAttributeEqualsDate || inAttribute == FilePropertyField.REPLICA_NUMBER
|| inAttribute == FilePropertyField.SIZE) {
whereClause = String.format(" fileProperties.%s %s %s", attribute, operator, value);
} else {
whereClause = String.format(" LOWER( fileProperties.%s ) %s LOWER( '%s' )", attribute, operator, value);
whereClause = String.format(" fileProperties.%s %s '%s'", attribute, operator, value);
}

return whereClause;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ public String buildWhereClauseForDataGridPropertySearch(FilePropertyField inAttr
|| inAttribute == FilePropertyField.MODIFICATION_DATE;

if (inOperator == DataGridSearchOperatorEnum.LIKE || inOperator == DataGridSearchOperatorEnum.NOT_LIKE) {
whereClause = String.format(" LOWER( fileProperties.%s ) %s LOWER( '%%%s%%' )", attribute, operator, value);
whereClause = String.format(" fileProperties.%s %s '%%%s%%'", attribute, operator, value);
} else if (isAttributeEqualsDate && inOperator == DataGridSearchOperatorEnum.EQUAL) {
whereClause = String.format(" fileProperties.%s BETWEEN %s AND %d", attribute, value,
Long.parseLong(value) + 60);
} else if (isAttributeEqualsDate || inAttribute == FilePropertyField.REPLICA_NUMBER
|| inAttribute == FilePropertyField.SIZE) {
whereClause = String.format(" fileProperties.%s %s %s", attribute, operator, value);
} else {
whereClause = String.format(" LOWER( fileProperties.%s ) %s LOWER( '%s' )", attribute, operator, value);
whereClause = String.format(" fileProperties.%s %s '%s'", attribute, operator, value);
}

return whereClause;
Expand Down

0 comments on commit 3a3475a

Please sign in to comment.