- 13 5月, 2020 2 次提交
-
-
由 Ryuta Kamizono 提交于
Follow up of #39255. Previously aggregation functions only use the model's attribute types on the relation for type cast, this will be looking up association's attribute and type caster if a column name is table name qualified. Fixes #39248.
-
由 Ryuta Kamizono 提交于
This is the opposite direction of #39039. #39111 fixes `minimum` and `maximum` on date columns with type casting by column type on the database. But column type has no information for time zone aware attributes, it means that attribute type should always be precedence over column type. I've realized that fact in the related issue report #39248. I've reverted the expectation of #39039, to make time zone aware attributes works.
-
- 02 5月, 2020 1 次提交
-
-
由 Ryuta Kamizono 提交于
I supposed all aggregation functions will return numeric result in #39039, but that assumption was incorrect for `minimum` and `maximum`, if an aggregated column is non numeric type. I've restored type casting aggregated result for `minimum` and `maximum`. Fixes #39110.
-
- 29 4月, 2020 1 次提交
-
-
由 Ryuta Kamizono 提交于
Related #39039. Currently PostgreSQL adapter is the only adapter that rely on type casting by `result.column_types`, now the adapter can return numeric value without type casting by Active Record side. So we can remove that useless type cast on aggregated value.
-
- 25 4月, 2020 1 次提交
-
-
由 Ryuta Kamizono 提交于
Currently, `count` and `average` always returns numeric value, but `sum`, `maximum`, and `minimum` not always return numeric value if aggregated on custom attribute type. I think that inconsistent behavior is surprising: ```ruby # All adapters except postgresql adapter are affected # by custom type casting. Book.group(:status).sum(:status) # => { "proposed" => "proposed", "published" => nil } ``` That is caused by fallback looking up cast type to `type_for(column)`. Now all supported adapters can return numeric value without that fallback, so I think we can remove that, it will also fix aggregate functions to return numeric value consistently.
-
- 20 3月, 2020 1 次提交
-
-
由 stevenjackson 提交于
The current implementation raises a warning in Rails 6.0.2.2 ``` DEPRECATION WARNING: Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s): "DATEDIFF(updated_at, created_at)". Non-attribute arguments will be disallowed in Rails 6.1. This method should not be called with user-provided values, such as request parameters or model attributes. Known-safe values can be passed by wrapping them in Arel.sql(). ```
-
- 19 3月, 2020 1 次提交
-
-
由 Eugene Kenny 提交于
When called on a loaded relation, `pick` will now use the existing results instead of making another query, just like `pluck` does.
-
- 05 3月, 2020 1 次提交
-
-
由 Eugene Kenny 提交于
Using `index_by` or `index_with` is more concise than `each_with_object` and more performant than `map { ... }.to_h` or `Hash[map { ... }]`.
-
- 27 1月, 2020 1 次提交
-
-
由 Ryuta Kamizono 提交于
Follow up #37266.
-
- 07 8月, 2019 1 次提交
-
-
由 Ryuta Kamizono 提交于
c9e4c848 has one performance optimization for `aggregate_alias` to early returning by `aggregate_alias.match?(/\A\w+\z/)`, but it is caused a regression that failing deduplication for non word chars #36867. I've quited the optimization and add a test to prevent a future regression. Fixes #36867.
-
- 08 7月, 2019 1 次提交
-
-
由 Ryuta Kamizono 提交于
It appears that Oracle does not allow using aliases in GROUP BY clause unlike ORDER BY clause. Fixes #36613.
-
- 22 4月, 2019 1 次提交
-
-
由 Ryuta Kamizono 提交于
Related 0ee96d13.
-
- 08 4月, 2019 1 次提交
-
-
由 Ryuta Kamizono 提交于
Follow up of c9e4c848.
-
- 06 4月, 2019 1 次提交
-
-
由 Ryuta Kamizono 提交于
This refactors `execute_grouped_calculation` and slightly changes generated GROUP BY queries, since I'd not prefer to repeat same expression in SELECT and GROUP BY clauses. Before: ``` SELECT COUNT(*) AS count_all, "topics"."author_name" AS topics_author_name, COALESCE(type, title) AS coalesce_type_title FROM "topics" GROUP BY "topics"."author_name", COALESCE(type, title) ``` After: ``` SELECT COUNT(*) AS count_all, "topics"."author_name" AS topics_author_name, COALESCE(type, title) AS coalesce_type_title FROM "topics" GROUP BY topics_author_name, coalesce_type_title ``` Although we generally don't guarantee to support Arel node constructed by user itself, this also fixes #24207.
-
- 04 4月, 2019 2 次提交
-
-
由 Ryuta Kamizono 提交于
This follows up ebc09ed9. We've still experienced a regression for `size` (`count(:all)`) with eager loading and explicit select and order when upgrading Rails to 5.1. In that case, the eager loading enforces `distinct` to subselect but still keep the custom select, it would cause the ORDER BY with DISTINCT issue. ``` % ARCONN=postgresql bundle exec ruby -w -Itest test/cases/relations_test.rb -n test_size_with_eager_loading_and_custom_select_and_order Using postgresql Run options: -n test_size_with_eager_loading_and_custom_select_and_order --seed 8356 # Running: E Error: RelationTest#test_size_with_eager_loading_and_custom_select_and_order: ActiveRecord::StatementInvalid: PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list LINE 1: ..." ON "comments"."post_id" = "posts"."id" ORDER BY comments.i... ^ ``` As another problem on `distinct` is enforced, the result of `count` becomes fewer than expected if `select` is given explicitly. e.g. ```ruby Post.select(:type).count # => 11 Post.select(:type).distinct.count # => 3 ``` As long as `distinct` is enforced, we need to care to keep the result of `count`. This fixes both the `count` with eager loading problems.
-
由 Ryuta Kamizono 提交于
I've experienced this issue in our app, some hints only works on Top level query (e.g. `MAX_EXECUTION_TIME`).
-
- 26 2月, 2019 1 次提交
-
-
由 jvillarejo 提交于
When using `select` with `'DISTINCT( ... )'` if you use method `size` on a non loaded relation it overrides the column selected by passing `:all` so it returns different value than count. This fixes #35214
-
- 13 2月, 2019 1 次提交
-
-
由 Ryuta Kamizono 提交于
Currently custom attributes are always qualified by the table name in the generated SQL wrongly even if the table doesn't have the named column, it would cause an invalid SQL error. Custom attributes should only be qualified if the table has the same named column.
-
- 18 1月, 2019 2 次提交
-
-
由 Rafael Mendonça França 提交于
-
由 Rafael Mendonça França 提交于
-
- 04 1月, 2019 1 次提交
-
-
由 Alberto Almagro 提交于
Since Ruby 2.6.0 NilClass#to_d is returning `BigDecimal` 0.0, this breaks `average` compatibility with prior Ruby versions. This patch makes `average` return `nil` in all Ruby versions when there are no rows.
-
- 02 1月, 2019 1 次提交
-
-
由 Ryuta Kamizono 提交于
This reverts 27c6c071 since `arel_attr.to_s` is not right way to avoid the type error. That to_s returns `"#<struct Arel::Attributes::Attribute ...>"`, there is no reason to match the regex to the inspect form. And also, the regex path is not covered by our test cases. I've tweaked the regex for redundant part and added assertions for the regex path.
-
- 27 8月, 2018 1 次提交
-
-
由 Kevin Deisz 提交于
-
- 25 8月, 2018 1 次提交
-
-
由 Kevin Deisz 提交于
-
- 29 7月, 2018 2 次提交
-
-
由 Bart de Water 提交于
-
由 Bart de Water 提交于
In cases where the MatchData object is not used, this provides a speed-up: https://github.com/JuanitoFatas/fast-ruby/#stringmatch-vs-stringmatch-vs-stringstart_withstringend_with-code-start-code-end
-
- 26 2月, 2018 1 次提交
-
-
由 Max Schwenk 提交于
-
- 10 2月, 2018 2 次提交
-
-
由 yuuji.yaginuma 提交于
-
由 David Heinemeier Hansson 提交于
* Add Relation#pick as short-hand for single-value plucks
-
- 29 1月, 2018 1 次提交
-
-
由 Daniel Colson 提交于
With #31615 `type_for_attribute` accepts either a symbol as well as a string. `has_attribute?` and `attribute_alias` also accept either. Since these methods call `to_s` on the argument, we no longer need to do that at the call site.
-
- 25 1月, 2018 1 次提交
-
-
由 Ryuta Kamizono 提交于
This is a regression caused by 6beb4de7. In PostgreSQL, ORDER BY expressions must appear in SELECT list when using DISTINCT. When using `count(:all)` with eager loading, Active Record enforces DISTINCT to count the driving table records only. 6beb4de7 was caused the regression because `count(:all)` with DISTINCT path no longer removes ORDER BY. We need to ignore ORDER BY when DISTINCT is enforced, otherwise not always generated valid SQL for PostgreSQL. Fixes #31783.
-
- 20 12月, 2017 1 次提交
-
-
由 Ryuta Kamizono 提交于
Currently `count(:all)` with `distinct` doesn't work correctly because SELECT list is always replaced to `*` or primary key in that case even if having custom SELECT list. And also, PostgreSQL has a limitation that ORDER BY expressions must appear in select list for SELECT DISTINCT. Therefore, we should not replace custom SELECT list when using `count(:all)` with `distinct`. Closes #31277.
-
- 09 11月, 2017 4 次提交
- 06 11月, 2017 1 次提交
-
-
由 Ryuta Kamizono 提交于
Fixes #30315.
-
- 14 10月, 2017 1 次提交
-
-
由 Ryuta Kamizono 提交于
This is the fix for the regression of #29848. In #29848, I've kept existing select list in the subquery for the count if ORDER BY is given. But it had accidentally affect to GROUP BY queries also. It should keep the previous behavior in that case. Fixes #30886.
-
- 09 10月, 2017 1 次提交
-
-
由 Ryuta Kamizono 提交于
I don't think this is a good abstraction because the internal method is used only if the relation need to be applied join dependency.
-
- 23 9月, 2017 1 次提交
-
-
由 Ken Collins 提交于
-