-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostgresql-hll.rb
67 lines (58 loc) · 2.5 KB
/
postgresql-hll.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class PostgresqlHll < Formula
desc "PostgreSQL extension adding HyperLogLog data structures as a native data type"
homepage "https://github.com/citusdata/postgresql-hll"
url "https://github.com/citusdata/postgresql-hll/archive/refs/tags/v2.18.tar.gz"
sha256 "e2f55a6f4c4ab95ee4f1b4a2b73280258c5136b161fe9d059559556079694f0e"
license "Apache-2.0"
revision 2
bottle do
root_url "https://ghcr.io/v2/bayandin/tap"
sha256 cellar: :any_skip_relocation, arm64_sequoia: "faa178bef91a0c2817a13c3eec3f75edb39ed6a1b5cff72c77eb91479deb658d"
sha256 cellar: :any_skip_relocation, arm64_sonoma: "b68bf292523bd033cbbd7e6ab5d07d1272e22b2e63038a9eece9f804ecabfc07"
sha256 cellar: :any_skip_relocation, ventura: "7326ceb01d156fe000302a6fab6d156f5b2264d62bb9ce6003d50ea45a571b30"
sha256 cellar: :any_skip_relocation, x86_64_linux: "8377cac766ba9e1d7dc477416b0d53eabdf95c46e21ee97b3b7fbe979a2744df"
end
depends_on "bayandin/tap/neon-postgres"
def neon_postgres
Formula["bayandin/tap/neon-postgres"]
end
def pg_versions
neon_postgres.pg_versions
end
def install
pg_versions.each do |v|
ENV["PG_CONFIG"] = neon_postgres.pg_bin_for(v)/"pg_config"
system "make", "clean"
system "make"
mkdir_p lib/neon_postgres.name/v
mv "hll.#{neon_postgres.dlsuffix(v)}", lib/neon_postgres.name/v
mkdir_p share/neon_postgres.name/v/"extension"
cp "hll.control", share/neon_postgres.name/v/"extension"
cp Dir["hll--*.sql"], share/neon_postgres.name/v/"extension"
end
end
test do
pg_versions.each do |v|
pg_ctl = neon_postgres.pg_bin_for(v)/"pg_ctl"
psql = neon_postgres.pg_bin_for(v)/"psql"
port = free_port
system pg_ctl, "initdb", "-D", testpath/"test-#{v}"
(testpath/"test-#{v}/postgresql.conf").write <<~EOS, mode: "a+"
port = #{port}
EOS
system pg_ctl, "start", "-D", testpath/"test-#{v}", "-l", testpath/"log-#{v}"
begin
system psql, "-p", port.to_s, "-c", <<~SQL, "postgres"
CREATE EXTENSION hll;
CREATE TABLE helloworld (id integer, set hll);
INSERT INTO helloworld(id, set) VALUES (1, hll_empty());
UPDATE helloworld SET set = hll_add(set, hll_hash_integer(12345)) WHERE id = 1;
UPDATE helloworld SET set = hll_add(set, hll_hash_text('hello world')) WHERE id = 1;
SELECT hll_cardinality(set) FROM helloworld WHERE id = 1;
SQL
ensure
system pg_ctl, "stop", "-D", testpath/"test-#{v}"
end
end
end
end