Skip to content

Conversation

@acwhite211
Copy link
Member

@acwhite211 acwhite211 commented Oct 21, 2025

Fixes #7436

On the front-end, allow for the disambiguation between taxon and host taxon columns in the QB results. Implement this as a special case in the generateMappingPathPreview function on the front-end. This will show the column CollectingEvent->CollectingEventAttribute->HostTaxon->Genius->FullName to be displayed as Host - Genus - Full name, rather than Genus - Full name. This allows the user to differentiate between other paths from Taxon.

This resolves the specific case described in the issue. If we want a more general solution that can resolve any disambiguation between fields in the QB results, then we'll need to design a more complex solution on the front-end. That solution would need to be different from generateMappingPathPreview, as it would need to have the context of all the fields in the query, and then have some way of deciding on alternative names when disambiguation as needed.

The issue on the back-end is with the query that gets generated:

SELECT
	collectionobject.`CollectionObjectID`,
	CASE
		WHEN (taxon_1.`TaxonTreeDefItemID` = 64) THEN taxon_1.`Name`
		WHEN (taxon_2.`TaxonTreeDefItemID` = 64) THEN taxon_2.`Name`
		WHEN (taxon_3.`TaxonTreeDefItemID` = 64) THEN taxon_3.`Name`
		WHEN (taxon_4.`TaxonTreeDefItemID` = 64) THEN taxon_4.`Name`
		WHEN (taxon_5.`TaxonTreeDefItemID` = 64) THEN taxon_5.`Name`
		WHEN (taxon_6.`TaxonTreeDefItemID` = 64) THEN taxon_6.`Name`
		WHEN (taxon_7.`TaxonTreeDefItemID` = 64) THEN taxon_7.`Name`
		WHEN (taxon_8.`TaxonTreeDefItemID` = 64) THEN taxon_8.`Name`
		WHEN (taxon_9.`TaxonTreeDefItemID` = 64) THEN taxon_9.`Name`
		WHEN (taxon_10.`TaxonTreeDefItemID` = 64) THEN taxon_10.`Name`
		WHEN (taxon_11.`TaxonTreeDefItemID` = 64) THEN taxon_11.`Name`
		WHEN (taxon_12.`TaxonTreeDefItemID` = 64) THEN taxon_12.`Name`
		WHEN (taxon_13.`TaxonTreeDefItemID` = 64) THEN taxon_13.`Name`
		WHEN (taxon_14.`TaxonTreeDefItemID` = 64) THEN taxon_14.`Name`
		WHEN (taxon_15.`TaxonTreeDefItemID` = 64) THEN taxon_15.`Name`
		WHEN (taxon_16.`TaxonTreeDefItemID` = 64) THEN taxon_16.`Name`
		WHEN (taxon_17.`TaxonTreeDefItemID` = 64) THEN taxon_17.`Name`
	END AS anon_1,
	CASE
		WHEN (taxon_1.`TaxonTreeDefItemID` = 64) THEN taxon_1.`Name`
		WHEN (taxon_2.`TaxonTreeDefItemID` = 64) THEN taxon_2.`Name`
		WHEN (taxon_3.`TaxonTreeDefItemID` = 64) THEN taxon_3.`Name`
		WHEN (taxon_4.`TaxonTreeDefItemID` = 64) THEN taxon_4.`Name`
		WHEN (taxon_5.`TaxonTreeDefItemID` = 64) THEN taxon_5.`Name`
		WHEN (taxon_6.`TaxonTreeDefItemID` = 64) THEN taxon_6.`Name`
		WHEN (taxon_7.`TaxonTreeDefItemID` = 64) THEN taxon_7.`Name`
		WHEN (taxon_8.`TaxonTreeDefItemID` = 64) THEN taxon_8.`Name`
		WHEN (taxon_9.`TaxonTreeDefItemID` = 64) THEN taxon_9.`Name`
		WHEN (taxon_10.`TaxonTreeDefItemID` = 64) THEN taxon_10.`Name`
		WHEN (taxon_11.`TaxonTreeDefItemID` = 64) THEN taxon_11.`Name`
		WHEN (taxon_12.`TaxonTreeDefItemID` = 64) THEN taxon_12.`Name`
		WHEN (taxon_13.`TaxonTreeDefItemID` = 64) THEN taxon_13.`Name`
		WHEN (taxon_14.`TaxonTreeDefItemID` = 64) THEN taxon_14.`Name`
		WHEN (taxon_15.`TaxonTreeDefItemID` = 64) THEN taxon_15.`Name`
		WHEN (taxon_16.`TaxonTreeDefItemID` = 64) THEN taxon_16.`Name`
		WHEN (taxon_17.`TaxonTreeDefItemID` = 64) THEN taxon_17.`Name`
	END AS anon_2
FROM
	collectionobject
LEFT OUTER JOIN determination AS determination_1 ON
	collectionobject.`CollectionObjectID` = determination_1.`CollectionObjectID`
LEFT OUTER JOIN taxon AS taxon_1 ON
	taxon_1.`TaxonID` = determination_1.`TaxonID`
LEFT OUTER JOIN taxon AS taxon_2 ON
	taxon_1.`ParentID` = taxon_2.`TaxonID`
LEFT OUTER JOIN taxon AS taxon_3 ON
	taxon_2.`ParentID` = taxon_3.`TaxonID`
LEFT OUTER JOIN taxon AS taxon_4 ON
	taxon_3.`ParentID` = taxon_4.`TaxonID`
LEFT OUTER JOIN taxon AS taxon_5 ON
	taxon_4.`ParentID` = taxon_5.`TaxonID`
LEFT OUTER JOIN taxon AS taxon_6 ON
	taxon_5.`ParentID` = taxon_6.`TaxonID`
LEFT OUTER JOIN taxon AS taxon_7 ON
	taxon_6.`ParentID` = taxon_7.`TaxonID`
LEFT OUTER JOIN taxon AS taxon_8 ON
	taxon_7.`ParentID` = taxon_8.`TaxonID`
LEFT OUTER JOIN taxon AS taxon_9 ON
	taxon_8.`ParentID` = taxon_9.`TaxonID`
LEFT OUTER JOIN taxon AS taxon_10 ON
	taxon_9.`ParentID` = taxon_10.`TaxonID`
LEFT OUTER JOIN taxon AS taxon_11 ON
	taxon_10.`ParentID` = taxon_11.`TaxonID`
LEFT OUTER JOIN taxon AS taxon_12 ON
	taxon_11.`ParentID` = taxon_12.`TaxonID`
LEFT OUTER JOIN taxon AS taxon_13 ON
	taxon_12.`ParentID` = taxon_13.`TaxonID`
LEFT OUTER JOIN taxon AS taxon_14 ON
	taxon_13.`ParentID` = taxon_14.`TaxonID`
LEFT OUTER JOIN taxon AS taxon_15 ON
	taxon_14.`ParentID` = taxon_15.`TaxonID`
LEFT OUTER JOIN taxon AS taxon_16 ON
	taxon_15.`ParentID` = taxon_16.`TaxonID`
LEFT OUTER JOIN taxon AS taxon_17 ON
	taxon_16.`ParentID` = taxon_17.`TaxonID`
LEFT OUTER JOIN collectingevent AS collectingevent_1 ON
	collectingevent_1.`CollectingEventID` = collectionobject.`CollectingEventID`
LEFT OUTER JOIN collectingeventattribute AS collectingeventattribute_1 ON
	collectingeventattribute_1.`CollectingEventAttributeID` = collectingevent_1.`CollectingEventAttributeID`
LEFT OUTER JOIN taxon AS taxon_18 ON
	taxon_18.`TaxonID` = collectingeventattribute_1.`HostTaxonID`
WHERE
	collectionobject.`CollectionID` = 4
	AND (taxon_1.`TaxonTreeDefID` IN (4)
		OR taxon_1.`TaxonTreeDefID` IS NULL
		OR taxon_18.`TaxonTreeDefID` IN (4)
			OR taxon_18.`TaxonTreeDefID` IS NULL);

You can see in the query that taxon_18, which is associated with the CollectingEventAttribute Taxon, is not used the select clause. So, the anon_2 alias select clause in this case should have:

WHEN (taxon_18.`TaxonTreeDefItemID` = 64) THEN taxon_18.`Name`

The solution is to change the join_cache key from (table, 'TreeRanks') → (start_alias, 'TreeRanks'), preventing the host branch from reusing the determination branch’s chain. I'm investigating to make sure that this change is ok for other tree queries.

Before:
image

After:
image

Checklist

  • Self-review the PR after opening it to make sure the changes look good and
    self-explanatory (or properly documented)
  • Add relevant issue to release milestone
  • Add pr to documentation list

Testing instructions

  • Open up the query builder with Collection Object as the base table.
  • Add 'Species' and 'Genus' FullName fields from the path Determinations -> Taxon
  • Add 'Species' and 'Genus' FullName fields from the path Collecting Event -> Collecting Event Attribute -> Host taxon
  • Run the query and see that the fields from the different paths are different. The ones from 'Host Taxon' should have the 'Host' in the column name.
  • Find an example row in the results where the values from the taxon and host taxon are different.
  • Test other tree based queries to make sure that they still work correctly.

@acwhite211 acwhite211 added this to the 7.12.0 milestone Oct 21, 2025
@acwhite211 acwhite211 self-assigned this Oct 21, 2025
@acwhite211 acwhite211 added javascript Pull requests that update Javascript code 2 - Queries Issues that are related to the query builder or queries in general labels Oct 21, 2025
@github-project-automation github-project-automation bot moved this to 📋Back Log in General Tester Board Oct 21, 2025
@acwhite211 acwhite211 requested review from a team and removed request for a team October 21, 2025 17:28
@acwhite211 acwhite211 marked this pull request as draft October 21, 2025 17:30
@acwhite211 acwhite211 marked this pull request as ready for review October 21, 2025 21:12
@acwhite211 acwhite211 requested review from a team October 21, 2025 21:13
@acwhite211 acwhite211 added the python Pull requests that update Python code label Oct 22, 2025
Copy link
Collaborator

@emenslin emenslin left a comment

Choose a reason for hiding this comment

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

  • Run the query and see that the fields from the different paths are different. The ones from 'Host Taxon' should have the 'Host' in the column name.
  • Find an example row in the results where the values from the taxon and host taxon are different.
  • Test other tree based queries to make sure that they still work correctly.

The taxon and host taxon problem seems to be fixed but I am running into issues with the gegraphy and storage queries. When I try to query for state -> full name and county -> full name I get an error that doesn't happen in main. I'm not sure if this is happening on other queries as I was running into issues with queries in general running very slowly.

Main:

10-22_13.23.mp4

Issue branch:

10-22_13.25.mp4

Error message:
Specify 7 Crash Report - 2025-10-22T18_25_19.960Z.txt

@github-project-automation github-project-automation bot moved this from 📋Back Log to Dev Attention Needed in General Tester Board Oct 22, 2025
@acwhite211
Copy link
Member Author

acwhite211 commented Oct 23, 2025

Thanks @emenslin. I pushed a change that fixes the issue in Geography and Storage. It should also help some with performance, let me know if the queries are still slow for you. I'm going to test some more on larger databases to test performance.

@acwhite211 acwhite211 requested a review from emenslin October 23, 2025 15:08
Copy link
Collaborator

@emenslin emenslin left a comment

Choose a reason for hiding this comment

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

  • Run the query and see that the fields from the different paths are different. The ones from 'Host Taxon' should have the 'Host' in the column name.
  • Find an example row in the results where the values from the taxon and host taxon are different.
  • Test other tree based queries to make sure that they still work correctly.

Looks good, I'm no longer getting an error on geography and storage queries.

@emenslin emenslin requested a review from a team October 24, 2025 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 - Queries Issues that are related to the query builder or queries in general javascript Pull requests that update Javascript code python Pull requests that update Python code

Projects

Status: Dev Attention Needed

Development

Successfully merging this pull request may close these issues.

Query Results Show Incorrect Data and Ambiguous Headers for Fields with the Same Name

3 participants