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

POC - Add custom database role #455

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

POC - Add custom database role #455

wants to merge 2 commits into from

Conversation

etravassos
Copy link
Contributor

…rings


attribute = @columns.first.split(".").second.to_sym

relation = relation.where(model.arel_table[attribute].gt(@position.first))
Copy link
Contributor Author

@etravassos etravassos Feb 1, 2024

Choose a reason for hiding this comment

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

This change is to demonstrate that using arel_table does not treat the id column as strings in the generated SQL:

# original SQL:
Stripe::Fee.where("id > ?", 3).to_sql
=> "SELECT `stripe_fees`.* FROM `stripe_fees` WHERE (id > '3')"

# SQL with arel_table:
Stripe::Fee.where(Stripe::Fee.arel_table[:id].gt(3)).to_sql
=> "SELECT `stripe_fees`.* FROM `stripe_fees` WHERE `stripe_fees`.`id` > 3"

MySql is lenient and allows such comparison, however BigQuery raises an exception for this behaviour:

Google::Cloud::InvalidArgumentError: No matching signature for operator > for argument types: INT64, STRING.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah we had noticed that too, making use of arel_table does the trick, however it becomes very cumbersome to convert database table names into constantized classes in the jobiteration layer.
I just had a pairing session with @bony2023 and we managed to patch the bigquery adapter to prevent the coercion.
All details in this PR: https://github.com/Shopify/activerecord-bigquery-adapter/pull/4

Copy link
Contributor Author

@etravassos etravassos Feb 1, 2024

Choose a reason for hiding this comment

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

That being said we may want to revisit that coercion on the Mysql queries too 👍
as you pointed out even though it is lenient about it ain't ideal.

@etravassos etravassos changed the title POC - Add custom database role and poc to avoid comparing ids as strings POC - Add custom database role Feb 1, 2024
@@ -18,23 +18,16 @@ def initialize
end
end

def initialize(relation, columns = nil, position = nil)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

2 participants