Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GIT
PATH
remote: .
specs:
umbrellio-utils (1.16.0)
umbrellio-utils (1.16.1)
memery (~> 1)

GEM
Expand Down
25 changes: 15 additions & 10 deletions lib/umbrellio_utils/click_house/backends/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,15 @@ def deduplication_source
# / config / logger) and define SERVER_ERROR.

def from(source, db_name: self.db_name)
ds =
case source
when Symbol
DB.from(db_name == self.db_name ? SQL[source] : SQL[db_name][source])
when nil
DB.dataset
else
DB.from(source)
end
ds.clone(ch: true).with_extend(ClickHouseDatasetMethods)
ds = base_dataset
case source
when Symbol
ds.from(db_name == self.db_name ? SQL[source] : SQL[db_name][source])
when nil
ds
else
ds.from(source)
end
end

def count(dataset, **)
Expand Down Expand Up @@ -246,6 +245,12 @@ def with_temp_table(

protected

def base_dataset
return @base_dataset if @base_dataset&.db.equal?(DB)

@base_dataset = DB.dataset.clone(ch: true).with_extend(ClickHouseDatasetMethods)
end

# Every read path needs both halves, and pairing them here keeps a new
# one from silently reinstating session-wide FINAL inside a dedup
# subquery — the exact cost `deduplicate` exists to remove.
Expand Down
2 changes: 1 addition & 1 deletion lib/umbrellio_utils/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module UmbrellioUtils
VERSION = "1.16.0"
VERSION = "1.16.1"
end
20 changes: 20 additions & 0 deletions spec/umbrellio_utils/clickhouse_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@
end

describe "#from" do
it "reuses the same dataset class for every source kind" do
datasets = [ch.from(:a), ch.from(:b), ch.from(nil), ch.from(ch.from(:a))]

expect(datasets.map(&:class)).to all(equal(datasets.first.class))
end

it "marks every source kind as a ClickHouse dataset" do
datasets = [ch.from(:a), ch.from(nil), ch.from(ch.from(:a)), ch.from(Sequel[:a].as(:b))]

expect(datasets.map { |dataset| dataset.opts[:ch] }).to all(be(true))
end

it "uses the current DB after the constant is replaced" do
ch.from(:a)
replacement_db = Sequel.mock
stub_const("DB", replacement_db)

expect(ch.from(:b).db).to equal(replacement_db)
end

context "with another db" do
specify do
expect(ch.from(:test, db_name: :test).sql).to eq(
Expand Down
Loading