Skip to content

Conversation

jdenquin
Copy link
Contributor

  • LIMIT 1 BY field clause is a very performant alternative for de-duplication. It's better than a FINAL or GROUP BY on large sets.
  • Add the support of this clause for the gem

Usage :

# limit_by(<Integer>, <Symbol> or <String>)
events = Event.limit_by(1, :event_key)
  • NOTE: you can't use aggregate functions with a LIMIT BY without grouping, if you want to do so, you should use CTE, eg:
events = Events.limit_by(1, :event_key)
sql = <<-SQL
  with events as (#{events.to_sql})
  SELECT count()
  FROM events
SQL
Events.connection.select_value(sql)
  • TODO: Add support for a list of fields limit_by(<Integer>, <[Symbol]> or <[String]>

@PNixx
Copy link
Owner

PNixx commented Oct 15, 2024

@jdenquin please, fix conflicts

@jdenquin
Copy link
Contributor Author

@jdenquin please, fix conflicts

done!

@PNixx PNixx merged commit e216bcb into PNixx:master Oct 16, 2024
16 checks passed
@jdenquin jdenquin deleted the upstream-support-limit-by branch October 16, 2024 22:03
vincent-pochet added a commit to getlago/lago-api that referenced this pull request Oct 29, 2024
## Context

Two pull requests opened on the `clickhouse-active` records repository
were merged lately.
- PNixx/clickhouse-activerecord#158
- PNixx/clickhouse-activerecord#169

Since now all mandatory pieces that we require to use it in production
are here, we can use the official gem rather than the fork.

## Description

This PR replaces `gem 'clickhouse-activerecord', git:
'https://github.com/getlago/clickhouse-activerecord.git'` with `gem
"clickhouse-activerecord", "~> 1.2.0"`
dmitrytrager added a commit to mayak-bz/clickhouse-activerecord that referenced this pull request Jan 20, 2025
* new-master: (77 commits)
  Use a flag to track updates/deletes instead of guessing (PNixx#188)
  Do not squish table definitions in schema dump. (PNixx#187)
  Add support for integer limits in map type (PNixx#178)
  Improve function dumps (PNixx#179)
  Reliably sort functions, views, and materialized views in schema (PNixx#181)
  Maintain primary key type specificity (PNixx#183)
  Support create table with request settings
  Support codec column PNixx#135, refactoring
  Add Array support to Map (PNixx#158)
  SchemaDumper adds materialized view destination (PNixx#159)
  Improve DB::Exception error handling (PNixx#165)
  Add blank line after create_function in schema (PNixx#170)
  Include column definitions in schema dump if the column name is not `id` (PNixx#173)
  Add support for LIMIT BY clause (PNixx#169)
  Add support for force `CREATE FUNCTION` (PNixx#146)
  Implement GROUP BY GROUPING SETS with new `group_by_grouping_sets` query method. (PNixx#161)
  fix for function creation in structure.sql (PNixx#166)
  fix schema dumper
  fix spec
  fix detect model primary key for older clickhouse versions
  ...
dmitrytrager added a commit to mayak-bz/clickhouse-activerecord that referenced this pull request Jan 20, 2025
* new-master: (77 commits)
  Use a flag to track updates/deletes instead of guessing (PNixx#188)
  Do not squish table definitions in schema dump. (PNixx#187)
  Add support for integer limits in map type (PNixx#178)
  Improve function dumps (PNixx#179)
  Reliably sort functions, views, and materialized views in schema (PNixx#181)
  Maintain primary key type specificity (PNixx#183)
  Support create table with request settings
  Support codec column PNixx#135, refactoring
  Add Array support to Map (PNixx#158)
  SchemaDumper adds materialized view destination (PNixx#159)
  Improve DB::Exception error handling (PNixx#165)
  Add blank line after create_function in schema (PNixx#170)
  Include column definitions in schema dump if the column name is not `id` (PNixx#173)
  Add support for LIMIT BY clause (PNixx#169)
  Add support for force `CREATE FUNCTION` (PNixx#146)
  Implement GROUP BY GROUPING SETS with new `group_by_grouping_sets` query method. (PNixx#161)
  fix for function creation in structure.sql (PNixx#166)
  fix schema dumper
  fix spec
  fix detect model primary key for older clickhouse versions
  ...
dmitrytrager added a commit to mayak-bz/clickhouse-activerecord that referenced this pull request Jan 21, 2025
* new-master: (77 commits)
  Use a flag to track updates/deletes instead of guessing (PNixx#188)
  Do not squish table definitions in schema dump. (PNixx#187)
  Add support for integer limits in map type (PNixx#178)
  Improve function dumps (PNixx#179)
  Reliably sort functions, views, and materialized views in schema (PNixx#181)
  Maintain primary key type specificity (PNixx#183)
  Support create table with request settings
  Support codec column PNixx#135, refactoring
  Add Array support to Map (PNixx#158)
  SchemaDumper adds materialized view destination (PNixx#159)
  Improve DB::Exception error handling (PNixx#165)
  Add blank line after create_function in schema (PNixx#170)
  Include column definitions in schema dump if the column name is not `id` (PNixx#173)
  Add support for LIMIT BY clause (PNixx#169)
  Add support for force `CREATE FUNCTION` (PNixx#146)
  Implement GROUP BY GROUPING SETS with new `group_by_grouping_sets` query method. (PNixx#161)
  fix for function creation in structure.sql (PNixx#166)
  fix schema dumper
  fix spec
  fix detect model primary key for older clickhouse versions
  ...
tylerCaineRhodes pushed a commit to magellan-ai/clickhouse-activerecord that referenced this pull request Jul 25, 2025
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