homebrew-core/Formula/trino.rb

96 lines
3.7 KiB
Ruby

class Trino < Formula
include Language::Python::Shebang
desc "Distributed SQL query engine for big data"
homepage "https://trino.io"
url "https://search.maven.org/remotecontent?filepath=io/trino/trino-server/405/trino-server-405.tar.gz", using: :nounzip
sha256 "22de0430a9da9229df8392d67d3e0a0e09b1b736560dcb9fa2ac3bcf97be0c7f"
license "Apache-2.0"
livecheck do
url "https://search.maven.org/remotecontent?filepath=io/trino/trino-server/"
regex(%r{href=["']?v?(\d+(?:\.\d+)*)/?["' >]}i)
end
bottle do
sha256 cellar: :any_skip_relocation, all: "c7d8f4144a5a67f76c1fad4fd790f0f351b0a9dfd7881f9489bae4db98282890"
end
depends_on "gnu-tar" => :build
depends_on "openjdk"
depends_on "python@3.11"
resource "trino-src" do
url "https://github.com/trinodb/trino/archive/refs/tags/405.tar.gz", using: :nounzip
sha256 "6e13ea2bbe4b4cf53e0700d434afe04da4027e9296f008665964e97b39169db3"
end
resource "trino-cli" do
url "https://search.maven.org/remotecontent?filepath=io/trino/trino-cli/405/trino-cli-405-executable.jar"
sha256 "4953912e3bc0e74efd0375b5a33881d66cd9ebc97a6993246df136939e295db4"
end
def install
# Manually extract tarball to avoid losing hardlinks which increases bottle
# size from MBs to GBs. Remove once Homebrew is able to preserve hardlinks.
# Ref: https://github.com/Homebrew/brew/pull/13154
libexec.mkpath
system "tar", "-C", libexec.to_s, "--strip-components", "1", "-xzf", "trino-server-#{version}.tar.gz"
# Manually untar, since macOS-bundled tar produces the error:
# trino-363/plugin/trino-hive/src/test/resources/<truncated>.snappy.orc.crc: Failed to restore metadata
# Remove when https://github.com/trinodb/trino/issues/8877 is fixed
resource("trino-src").stage do |r|
ENV.prepend_path "PATH", Formula["gnu-tar"].opt_libexec/"gnubin"
system "tar", "-xzf", "trino-#{r.version}.tar.gz"
(libexec/"etc").install Dir["trino-#{r.version}/core/docker/default/etc/*"]
inreplace libexec/"etc/node.properties", "docker", tap.user.downcase
inreplace libexec/"etc/node.properties", "/data/trino", var/"trino/data"
inreplace libexec/"etc/jvm.config", %r{^-agentpath:/usr/lib/trino/bin/libjvmkill.so$\n}, ""
end
rewrite_shebang detected_python_shebang, libexec/"bin/launcher.py"
(bin/"trino-server").write_env_script libexec/"bin/launcher", Language::Java.overridable_java_home_env
resource("trino-cli").stage do
libexec.install "trino-cli-#{version}-executable.jar"
bin.write_jar_script libexec/"trino-cli-#{version}-executable.jar", "trino"
end
# Remove incompatible pre-built binaries
libprocname_dirs = libexec.glob("bin/procname/*")
# Keep the Linux-x86_64 directory to make bottles identical
libprocname_dirs.reject! { |dir| dir.basename.to_s == "Linux-x86_64" } if build.bottle?
libprocname_dirs.reject! { |dir| dir.basename.to_s == "#{OS.kernel_name}-#{Hardware::CPU.arch}" }
libprocname_dirs.map(&:rmtree)
end
def post_install
(var/"trino/data").mkpath
end
service do
run [opt_bin/"trino-server", "run"]
working_dir opt_libexec
end
test do
port = free_port
cp libexec/"etc/config.properties", testpath/"config.properties"
inreplace testpath/"config.properties", "8080", port.to_s
server = fork do
exec bin/"trino-server", "run", "--verbose",
"--data-dir", testpath,
"--config", testpath/"config.properties"
end
sleep 30
query = "SELECT state FROM system.runtime.nodes"
output = shell_output(bin/"trino --debug --server localhost:#{port} --execute '#{query}'")
assert_match "\"active\"", output
ensure
Process.kill("TERM", server)
Process.wait server
end
end