Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

2.9 KB
Raw Blame
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
set -ex

trino_dir="$(dirname "${BASH_SOURCE-$0}")"
trino_dir="$(cd "${trino_dir}">/dev/null; pwd)"
gravitino_home="$(cd "${trino_dir}/../../..">/dev/null; pwd)"

# Clean packages
rm -rf "${trino_dir}/packages"
mkdir -p "${trino_dir}/packages"

# Pick the version-segment module whose Trino range covers the base image version in the
# Dockerfile, e.g. trino-connector-478-479 for trinodb/trino:478.
trino_version="$(sed -nE 's/^FROM trinodb\/trino:([0-9]+).*/\1/p' "${trino_dir}/Dockerfile")"
connector_module=""
for module_dir in "${gravitino_home}"/trino-connector/trino-connector-*; do
  module="$(basename "${module_dir}")"
  range="${module#trino-connector-}"
  lo="${range%-*}"
  hi="${range#*-}"
  if [[ "${lo}" =~ ^[0-9]+$ && "${hi}" =~ ^[0-9]+$ ]] \
    && (( trino_version >= lo && trino_version <= hi )); then
    connector_module="${module}"
    break
  fi
done
if [ -z "${connector_module}" ]; then
  echo "ERROR: no trino-connector module supports Trino version '${trino_version}'." >&2
  exit 1
fi

cd ${gravitino_home}
${gravitino_home}/gradlew :trino-connector:${connector_module}:assembleTrinoConnector -x test
cp -r "${gravitino_home}/distribution/gravitino-${connector_module}" "${trino_dir}/packages/gravitino-trino-connector"

MYSQL_VERSION="8.0.27"
PG_VERSION="42.7.14"
MYSQL_JAVA_CONNECTOR_URL="https://repo1.maven.org/maven2/mysql/mysql-connector-java/${MYSQL_VERSION}/mysql-connector-java-${MYSQL_VERSION}.jar"
PG_JAVA_CONNECTOR_URL="https://jdbc.postgresql.org/download/postgresql-${PG_VERSION}.jar"

# Download MySQL jdbc driver if it does not exist.
if [ ! -f "${trino_dir}/packages/gravitino-trino-connector/mysql-connector-java-${MYSQL_VERSION}.jar" ]; then
  cd "${trino_dir}/packages/gravitino-trino-connector/" && curl -O "${MYSQL_JAVA_CONNECTOR_URL}" && cd -
fi

# Download PostgreSQL jdbc driver if it does not exist.
if [ ! -f "${trino_dir}/packages/gravitino-trino-connector/postgresql-${PG_VERSION}.jar" ]; then
  cd "${trino_dir}/packages/gravitino-trino-connector/" && curl -O "$PG_JAVA_CONNECTOR_URL" && cd -
fi

mkdir -p "${trino_dir}/packages/trino"
cp -r -p "${trino_dir}/conf" "${trino_dir}/packages/trino/conf"