Faveod / arel-extensions

Extending Arel
MIT License
142 stars 24 forks source link

.as() broken in MSSQL #113

Closed jmlevesque333 closed 1 month ago

jmlevesque333 commented 1 month ago

Hello, We have recently updated arel-extensions from 2.1.9 to 2.1.10 and found a breaking changes with MSSQL.

When using Arel's .as method ArelExtension is now adding brackets around the new column name. We get this: SUM([kpi_machine_state_durations].[estop]) AS [\"estop\"]

Instead of : SUM([kpi_machine_state_durations].[estop]) AS \"estop\"

Gemfile.lock ``` GEM remote: https://rubygems.org/ specs: actioncable (6.1.4.7) actionpack (= 6.1.4.7) activesupport (= 6.1.4.7) nio4r (~> 2.0) websocket-driver (>= 0.6.1) actionmailbox (6.1.4.7) actionpack (= 6.1.4.7) activejob (= 6.1.4.7) activerecord (= 6.1.4.7) activestorage (= 6.1.4.7) activesupport (= 6.1.4.7) mail (>= 2.7.1) actionmailer (6.1.4.7) actionpack (= 6.1.4.7) actionview (= 6.1.4.7) activejob (= 6.1.4.7) activesupport (= 6.1.4.7) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) actionpack (6.1.4.7) actionview (= 6.1.4.7) activesupport (= 6.1.4.7) rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) actionpack-xml_parser (2.0.1) actionpack (>= 5.0) railties (>= 5.0) actiontext (6.1.4.7) actionpack (= 6.1.4.7) activerecord (= 6.1.4.7) activestorage (= 6.1.4.7) activesupport (= 6.1.4.7) nokogiri (>= 1.8.5) actionview (6.1.4.7) activesupport (= 6.1.4.7) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) activejob (6.1.4.7) activesupport (= 6.1.4.7) globalid (>= 0.3.6) activemodel (6.1.4.7) activesupport (= 6.1.4.7) activerecord (6.1.4.7) activemodel (= 6.1.4.7) activesupport (= 6.1.4.7) activestorage (6.1.4.7) actionpack (= 6.1.4.7) activejob (= 6.1.4.7) activerecord (= 6.1.4.7) activesupport (= 6.1.4.7) marcel (~> 1.0.0) mini_mime (>= 1.1.0) activesupport (6.1.4.7) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) zeitwerk (~> 2.3) addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) annotate (3.2.0) activerecord (>= 3.2, < 8.0) rake (>= 10.4, < 14.0) arel_extensions (2.1.10) activerecord (>= 6.0) benchmark-ips (2.13.0) bigdecimal (3.1.8) bindex (0.8.1) bootsnap (1.18.4) msgpack (~> 1.2) builder (3.3.0) bullet (7.2.0) activesupport (>= 3.0.0) uniform_notifier (~> 1.11) byebug (11.1.3) capybara (3.39.2) addressable matrix mini_mime (>= 0.1.3) nokogiri (~> 1.8) rack (>= 1.6.0) rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) concurrent-ruby (1.3.4) crass (1.0.6) daemons (1.4.1) date (3.3.4) dead_end (4.0.0) debase (2.3.9) debase-ruby_core_source (~> 0.10.18) debase-ruby_core_source (0.10.18) deep_cloneable (3.2.0) activerecord (>= 3.1.0, < 8) delayed_job (4.1.11) activesupport (>= 3.0, < 8.0) delayed_job_active_record (4.1.8) activerecord (>= 3.0, < 8.0) delayed_job (>= 3.0, < 5) derailed_benchmarks (2.1.2) benchmark-ips (~> 2) dead_end get_process_mem (~> 0) heapy (~> 0) memory_profiler (>= 0, < 2) mini_histogram (>= 0.3.0) rack (>= 1) rack-test rake (> 10, < 14) ruby-statistics (>= 2.1) thor (>= 0.19, < 2) diff-lcs (1.5.1) docile (1.4.1) dotenv (2.8.1) dotenv-rails (2.8.1) dotenv (= 2.8.1) railties (>= 3.2) erubi (1.13.0) et-orbi (1.2.11) tzinfo faraday (1.10.3) faraday-em_http (~> 1.0) faraday-em_synchrony (~> 1.0) faraday-excon (~> 1.1) faraday-httpclient (~> 1.0) faraday-multipart (~> 1.0) faraday-net_http (~> 1.0) faraday-net_http_persistent (~> 1.0) faraday-patron (~> 1.0) faraday-rack (~> 1.0) faraday-retry (~> 1.0) ruby2_keywords (>= 0.0.4) faraday-em_http (1.0.0) faraday-em_synchrony (1.0.0) faraday-excon (1.1.0) faraday-httpclient (1.0.1) faraday-multipart (1.0.4) multipart-post (~> 2) faraday-net_http (1.0.2) faraday-net_http_persistent (1.2.0) faraday-patron (1.0.0) faraday-rack (1.0.0) faraday-retry (1.0.3) faraday_middleware (1.2.0) faraday (~> 1.0) ffi (1.17.0-x64-mingw32) ffi-win32-extensions (1.0.4) ffi fugit (1.11.0) et-orbi (~> 1, >= 1.2.11) raabro (~> 1.4) get_process_mem (0.2.7) ffi (~> 1.0) git (1.19.1) addressable (~> 2.8) rchardet (~> 1.8) globalid (1.2.1) activesupport (>= 6.1) heapy (0.2.0) thor i18n (1.14.5) concurrent-ruby (~> 1.0) jbuilder (2.12.0) actionview (>= 5.0.0) activesupport (>= 5.0.0) jbuilder_cache_multi (0.1.0) jbuilder (>= 1.5.0, < 3) json-schema (4.3.1) addressable (>= 2.8) lograge (0.14.0) actionpack (>= 4) activesupport (>= 4) railties (>= 4) request_store (~> 1.0) loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) mini_mime (>= 0.1.1) net-imap net-pop net-smtp marcel (1.0.4) matrix (0.4.2) memory_profiler (1.0.2) method_source (1.1.0) mini_histogram (0.3.1) mini_mime (1.1.5) minitest (5.10.3) mocha (2.4.5) ruby2_keywords (>= 0.0.5) msgpack (1.7.2) multipart-post (2.4.1) net-imap (0.4.14) date net-protocol net-pop (0.1.2) net-protocol net-protocol (0.2.2) timeout net-smtp (0.5.0) net-protocol nio4r (2.7.3) nokogiri (1.15.6-x64-mingw32) racc (~> 1.4) oj (3.16.5) bigdecimal (>= 3.0) ostruct (>= 0.2) ostruct (0.6.0) pg (1.3.5-x64-mingw32) public_suffix (5.1.1) puma (4.3.12) nio4r (~> 2.0) raabro (1.4.0) racc (1.8.1) rack (2.2.9) rack-attack (6.7.0) rack (>= 1.0, < 4) rack-proxy (0.7.7) rack rack-test (2.1.0) rack (>= 1.3) rails (6.1.4.7) actioncable (= 6.1.4.7) actionmailbox (= 6.1.4.7) actionmailer (= 6.1.4.7) actionpack (= 6.1.4.7) actiontext (= 6.1.4.7) actionview (= 6.1.4.7) activejob (= 6.1.4.7) activemodel (= 6.1.4.7) activerecord (= 6.1.4.7) activestorage (= 6.1.4.7) activesupport (= 6.1.4.7) bundler (>= 1.15.0) railties (= 6.1.4.7) sprockets-rails (>= 2.0.0) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) rails-perftest (0.0.7) railties (6.1.4.7) actionpack (= 6.1.4.7) activesupport (= 6.1.4.7) method_source rake (>= 0.13) thor (~> 1.0) rake (13.2.1) rchardet (1.8.0) regexp_parser (2.9.2) request_store (1.7.0) rack (>= 1.4) rexml (3.3.5) strscan rr (3.1.0) rspec-core (3.13.0) rspec-support (~> 3.13.0) rspec-expectations (3.13.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-mocks (3.13.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-rails (6.1.3) actionpack (>= 6.1) activesupport (>= 6.1) railties (>= 6.1) rspec-core (~> 3.13) rspec-expectations (~> 3.13) rspec-mocks (~> 3.13) rspec-support (~> 3.13) rspec-support (3.13.1) rswag-api (2.13.0) activesupport (>= 3.1, < 7.2) railties (>= 3.1, < 7.2) rswag-specs (2.13.0) activesupport (>= 3.1, < 7.2) json-schema (>= 2.2, < 5.0) railties (>= 3.1, < 7.2) rspec-core (>= 2.14) rswag-ui (2.13.0) actionpack (>= 3.1, < 7.2) railties (>= 3.1, < 7.2) ruby-debug-ide (2.3.13) debase (~> 2.3.9) ruby-prof (1.3.2) ruby-statistics (3.0.2) ruby2_keywords (0.0.5) rubyzip (2.3.2) rufus-scheduler (3.9.1) fugit (~> 1.1, >= 1.1.6) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) sassc (2.4.0-x64-mingw32) ffi (~> 1.9) sassc-rails (2.1.2) railties (>= 4.0.0) sassc (>= 2.0) sprockets (> 3.0) sprockets-rails tilt selenium-webdriver (4.9.0) rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) sprockets-rails (3.5.2) actionpack (>= 6.1) activesupport (>= 6.1) sprockets (>= 3.0.0) strscan (3.1.0) sys-proctable (1.3.0) ffi (~> 1.1) thor (1.3.1) tilt (2.4.0) timeout (0.4.1) tiny_tds (2.1.7-x64-mingw32) turbolinks (5.2.1) turbolinks-source (~> 5.2) turbolinks-source (5.2.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) tzinfo-data (1.2024.1) tzinfo (>= 1.0.0) uniform_notifier (1.16.0) web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) webdrivers (5.3.1) nokogiri (~> 1.6) rubyzip (>= 1.3.0) selenium-webdriver (~> 4.0, < 4.11) webpacker (4.3.0) activesupport (>= 4.2) rack-proxy (>= 0.6.1) railties (>= 4.2) websocket (1.2.11) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) win32-service (2.3.2) ffi ffi-win32-extensions xpath (3.2.0) nokogiri (~> 1.8) zeitwerk (2.6.17) PLATFORMS x64-mingw32 DEPENDENCIES actionpack-xml_parser! activerecord-sqlserver-adapter! annotate! bootsnap (>= 1.4.2)! bullet! byebug! capybara (>= 2.15)! debase! deep_cloneable (~> 3.1)! delayed_job_active_record! derailed_benchmarks! dotenv-rails! jbuilder (~> 2.7)! jbuilder_cache_multi! minitest (= 5.10.3)! mocha! pg (= 1.3.5)! puma (~> 4.1)! rack-attack (~> 6.5)! rails (~> 6.1.0, < 6.1.5)! rails-perftest! rr! rspec-rails! rswag-api! rswag-specs! rswag-ui! ruby-debug-ide! ruby-prof (= 1.3.2)! rx_module! sass-rails (>= 6)! selenium-webdriver! simplecov! sys-proctable! tiny_tds! turbolinks (~> 5)! tzinfo-data! web-console (>= 3.3.0)! webdrivers! webpacker (~> 4.0)! RUBY VERSION ruby 2.7.6p219 BUNDLED WITH 2.3.13 ```
stackmystack commented 1 month ago

Did you try 2.1.11 ?

stackmystack commented 1 month ago

I haven't done a release of the upcoming version, which contains fixes for SQL Server.

Can you try to install from git, specifically from this branch (from https://github.com/Faveod/arel-extensions/pull/112)?

So that would be:

gem 'arel_extensions', git: 'https://github.com/stackmystack/arel-extensions', branch: 'sqlserver-regression-on-bool'

I would also appreciate it if you can give me a minimum reproducible example, with details on the platform + db version.

jmlevesque333 commented 1 month ago

Hello again, we have updated to 2.1.11 and it seems to work fine.

Thanks for the input.

stackmystack commented 1 month ago

Hello again, we have updated to 2.1.11 and it seems to work fine.

Thanks for the input.

Good to know. But out of curiosity, could you communicate the version of SQL server please and how did you encounter it? I'd like to add it to the test suite so we don't regress like we did in 2.1.10.

jmlevesque333 commented 1 month ago

SQL server version:

Microsoft SQL Server 2022 (RTM) - 16.0.1000.6 (X64)   Oct  8 2022 05:58:25   Copyright (C) 2022 Microsoft Corporation  Developer Edition (64-bit) on Windows Server 2019 Datacenter 10.0 <X64> (Build 17763: ) (Hypervisor)

Encountered error while running this table.arel_table[state.to_sym].sum.as("\"#{state.to_s}\"")