It seems like SA handles parameter conflicts by appending an increasing integer after each duplicate parameter name, however it detects duplicate parameters in a case-sensitive fashion. So two parameters whose name only differs in capitalization will be considered not duplicates. However the BQ API seems to be using a case-insensitive scheme for detecting duplicates.
Environment details
OS type and version: Darwin growthloop.local 23.1.0 Darwin Kernel Version 23.1.0: Mon Oct 9 21:28:45 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6020 arm64
Python version: Python 3.9.18
pip version: pip 24.2 from /Users/alexholyoke/projects/test/env/lib/python3.9/site-packages/pip (python 3.9)
DatabaseError: (google.cloud.bigquery.dbapi.exceptions.DatabaseError) 400 POST https://bigquery.googleapis.com/bigquery/v2/projects/flywheel-dev-328120/queries?prettyPrint=false: Duplicate parameter name state_1
[SQL: SELECT 1
FROM `holyoke_test`.`customers` JOIN `holyoke_test`.`journey` ON `customers`.`user_id` = `journey`.`user_id`
WHERE `customers`.`STATE` = %(STATE_1:STRING)s AND `journey`.`state` = %(state_1:STRING)s]
[parameters: {'STATE_1': 'California', 'state_1': 'pending'}]
SA BindParameter names are usually derived from the column you're matching on. In this case, because I have the filter expression customer_table.c.STATE == "California", it will place the string "California" in a BindParameter called STATE_1, then I have another filter journey_table.c.state == "pending" which creates another BindParameter called state_1. This seems logically consistent from SA's point of view because it considers parameters with different capitalization to be different parameters. And as you can see from the error, it is rendering them in the correct location in the SQL. However, BQ API is disallowing this.
It seems like SA handles parameter conflicts by appending an increasing integer after each duplicate parameter name, however it detects duplicate parameters in a case-sensitive fashion. So two parameters whose name only differs in capitalization will be considered not duplicates. However the BQ API seems to be using a case-insensitive scheme for detecting duplicates.
Environment details
Darwin growthloop.local 23.1.0 Darwin Kernel Version 23.1.0: Mon Oct 9 21:28:45 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6020 arm64
Python 3.9.18
pip 24.2 from /Users/alexholyoke/projects/test/env/lib/python3.9/site-packages/pip (python 3.9)
Steps to reproduce
The following code:
Will raise the following DatabaseError
SA BindParameter names are usually derived from the column you're matching on. In this case, because I have the filter expression
customer_table.c.STATE == "California"
, it will place the string "California" in a BindParameter calledSTATE_1
, then I have another filterjourney_table.c.state == "pending"
which creates another BindParameter calledstate_1
. This seems logically consistent from SA's point of view because it considers parameters with different capitalization to be different parameters. And as you can see from the error, it is rendering them in the correct location in the SQL. However, BQ API is disallowing this.