Skip to content
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

SQL validation returns sql that cannot be validated #357

Open
MortenHofft opened this issue Nov 1, 2024 · 0 comments
Open

SQL validation returns sql that cannot be validated #357

MortenHofft opened this issue Nov 1, 2024 · 0 comments

Comments

@MortenHofft
Copy link
Member

It seems odd that the SQL validator accepts a query, then rewrites it as invalid sql

e.g.

{
  "format": "SQL_TSV_ZIP", 
  "sql": "SELECT \n  \"kingdom\", \"kingdomkey\", \"phylum\", \"phylumkey\", \"class\", \"classkey\", \"family\", \"familykey\", \"genus\", \"genuskey\", \"species\", \"specieskey\", \"year\",\n  COUNT(*) AS occurrences, MIN(COALESCE(coordinateUncertaintyInMeters, 1000)) AS minCoordinateUncertaintyInMeters, MIN(GBIF_TemporalUncertainty(eventDate)) AS minTemporalUncertainty\nFROM\n  occurrence\nWHERE \n  countryCode = 'PL'\nGROUP BY\n  \"kingdom\", \"kingdomkey\", \"phylum\", \"phylumkey\", \"class\", \"classkey\", \"family\", \"familykey\", \"genus\", \"genuskey\", \"species\", \"specieskey\", \"year\"" 
}

is accepted and rewritten as

{
  "sql": "SELECT kingdom, kingdomkey, phylum, phylumkey, class, classkey, family, familykey, genus, genuskey, species, specieskey, year, COUNT(*) occurrences, MIN(CASE WHEN coordinateuncertaintyinmeters IS NOT NULL THEN coordinateuncertaintyinmeters ELSE 1000 END) mincoordinateuncertaintyinmeters, MIN(GBIF_TEMPORALUNCERTAINTY(eventdate)) mintemporaluncertainty\nFROM occurrence\nWHERE occurrence.countrycode = 'PL'\nGROUP BY occurrence.kingdom, occurrence.kingdomkey, occurrence.phylum, occurrence.phylumkey, occurrence.class, occurrence.classkey, occurrence.family, occurrence.familykey, occurrence.genus, occurrence.genuskey, occurrence.species, occurrence.specieskey, occurrence.year",
  "notificationAddresses": [],
  "sendNotification": false,
  "type": "OCCURRENCE",
  "format": "SQL_TSV_ZIP"
}

which in turn is invalid if you pass it back to the validator

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

No branches or pull requests

1 participant