Skip to content

Filter blank failedWhere Queries from mutator#1482

Open
agusaldasoro wants to merge 8 commits intomasterfrom
agusaldasoro-patch-1
Open

Filter blank failedWhere Queries from mutator#1482
agusaldasoro wants to merge 8 commits intomasterfrom
agusaldasoro-patch-1

Conversation

@agusaldasoro
Copy link
Copy Markdown
Collaborator

This pull request makes a focused improvement to the mutation logic for handling failed SQL WHERE queries in the ApiWsStructureMutator class. The main change ensures that only non-blank failed WHERE queries are processed, which helps prevent unnecessary or invalid operations during mutation. We were sending empty strings as a valid query.

  • Mutation logic improvement:
    • In ApiWsStructureMutator, the list of failed WHERE queries is now filtered to exclude blank entries before further processing. This helps avoid issues related to empty or invalid SQL queries during mutation.

We were sending empty strings as a valid query
@agusaldasoro agusaldasoro requested a review from jgaleotti March 20, 2026 16:49
@agusaldasoro agusaldasoro requested a review from jgaleotti April 9, 2026 12:55
@agusaldasoro agusaldasoro marked this pull request as ready for review April 9, 2026 12:56
@jgaleotti jgaleotti requested a review from arcuri82 April 9, 2026 17:44
val oldSqlActions = mutableListOf<EnvironmentAction>().plus(ind.seeInitializingActions())

val failedWhereQueries = evaluatedIndividual.fitness.getViewOfAggregatedFailedWhereQueries()
.filter { it.isNotBlank() }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is it possible that a query is empty? or is it possibly a bug where those queries are collected? see below:

Image

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! You are right, I moved the fix to that function

@agusaldasoro agusaldasoro requested a review from arcuri82 April 15, 2026 23:49
.map { it.sqlCommand }
// JSQLParser >= 4.9 may produce empty-string SQL commands (it used to throw, now
// parses "" to null). Guard here at the source rather than at every call site.
.filter { it.isNotBlank() }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this definition of aggregatedFailedWhereQueries correct? i mean, also the previous version. inside DatabaseExecution we keep track of all SQL commands done in a test. some have failedWhere, some do not. but here it seems like you mark everything under executionInfo as failedWhere, isn't it? this would work if and only if all queries had failedWhere, isn't it?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to be on safe side, can you add some tests to check this scenario?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that be covered by line 169 .filter { it.failedWhere.isNotEmpty() }?

I added a test also to check both conditions failed where present and absent

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the class DatabaseExecution is old, where executionInfo was added later

/**
 * When a test case is executed, and the SUT does access a SQL database,
 * keep track of which SQL commands were executed.
 *
 * In particular, we keep track of which tables and columns were involved.
 *
 * For the Maps:
 * key -> table name
 * value -> column names, where "*" means all
 *
 *
 * This class MUST be immutable
 */
class DatabaseExecution(
        val queriedData: Map<TableId, Set<String>>,
        val updatedData: Map<TableId, Set<String>>,
        val insertedData: Map<TableId, Set<String>>,
        val failedWhere: Map<TableId, Set<String>>,
        val deletedData: List<TableId>,
        val numberOfSqlCommands: Int,
        val sqlParseFailureCount: Int,
        val executionInfo: List<SqlExecutionInfo>
)

unless I m mistaken, executionInfo includes info for all SQL commands, even the ones that had no failed WHERE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants