-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Tests for searching boolean fields, including fixes for various bugs. #13614
Conversation
function fixBooleanFields({ row, table }: { row: Row; table: Table }) { | ||
for (let col of Object.values(table.schema)) { | ||
if (col.type === FieldType.BOOLEAN) { | ||
if (row[col.name] === 1) { | ||
row[col.name] = true | ||
} else if (row[col.name] === 0) { | ||
row[col.name] = false | ||
} | ||
} | ||
} | ||
return row | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SQS, MariaDB, and MySQL appear to store boolean values as numeric 1s or 0s, this function parses those back into proper booleans.
private findRow(expectedRow: any, foundRows: any[]) { | ||
const row = foundRows.find(foundRow => _.isMatch(foundRow, expectedRow)) | ||
if (!row) { | ||
const fields = Object.keys(expectedRow) | ||
// To make the error message more readable, we only include the fields | ||
// that are present in the expected row. | ||
const searchedObjects = foundRows.map(row => _.pick(row, fields)) | ||
throw new Error( | ||
`Failed to find row: ${JSON.stringify( | ||
expectedRow | ||
)} in ${JSON.stringify(searchedObjects)}` | ||
) | ||
} | ||
return row | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…directly to search.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the isEmpty
improvement!
Description
This PR introduces tests for searching against boolean fields, which appear to have been quite broken until now. The PR includes fixes for searching against
false
values in Lucene, and a variety of fixes required to get searching working for the SQL-based datasources.