|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# |
| 4 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 5 | +# contributor license agreements. See the NOTICE file distributed with |
| 6 | +# this work for additional information regarding copyright ownership. |
| 7 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 8 | +# (the "License"); you may not use this file except in compliance with |
| 9 | +# the License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +# See the License for the specific language governing permissions and |
| 17 | +# limitations under the License. |
| 18 | +# |
| 19 | + |
| 20 | +# |
| 21 | +# Generate TPC-DS data for TPCDSQUeryTestSuite. |
| 22 | +# Run with "-h" for options. |
| 23 | +# |
| 24 | + |
| 25 | +set -e |
| 26 | +SELF=$(cd $(dirname $0) && pwd) |
| 27 | + |
| 28 | +# Re-uses helper funcs for the release scripts |
| 29 | +. "$SELF/../create-release/release-util.sh" |
| 30 | + |
| 31 | +function usage { |
| 32 | + local NAME=$(basename $0) |
| 33 | + cat <<EOF |
| 34 | +Usage: $NAME [options] |
| 35 | +
|
| 36 | +This script generates TPC-DS data for TPCDSQUeryTestSuite inside a docker image. The image is hardcoded to be called |
| 37 | +"spark-tpcds" and will be re-generated (as needed) on every invocation of this script. |
| 38 | +
|
| 39 | +Options are: |
| 40 | +
|
| 41 | + -d [path] : required: working directory (output will be written to an "output" directory in |
| 42 | + the working directory). |
| 43 | +EOF |
| 44 | +} |
| 45 | + |
| 46 | +WORKDIR= |
| 47 | +IMGTAG=latest |
| 48 | +while getopts ":d:h" opt; do |
| 49 | + case $opt in |
| 50 | + d) WORKDIR="$OPTARG" ;; |
| 51 | + h) usage; exit 0 ;; |
| 52 | + \?) error "Invalid option. Run with -h for help." ;; |
| 53 | + esac |
| 54 | +done |
| 55 | + |
| 56 | +if [ -z "$WORKDIR" ] || [ ! -d "$WORKDIR" ]; then |
| 57 | + error "Work directory (-d) must be defined and exist. Run with -h for help." |
| 58 | +fi |
| 59 | + |
| 60 | +if [ -d "$WORKDIR/output" ]; then |
| 61 | + read -p "Output directory already exists. Overwrite and continue? [y/n] " ANSWER |
| 62 | + if [ "$ANSWER" != "y" ]; then |
| 63 | + error "Exiting." |
| 64 | + fi |
| 65 | +fi |
| 66 | + |
| 67 | +cd "$WORKDIR" |
| 68 | +rm -rf "$WORKDIR/output" |
| 69 | +mkdir "$WORKDIR/output" |
| 70 | + |
| 71 | +# Place all scripts in a local directory that must be defined in the command |
| 72 | +# line. This directory is mounted into the image. |
| 73 | +for f in "$SELF"/*; do |
| 74 | + if [ -f "$f" ]; then |
| 75 | + cp "$f" "$WORKDIR" |
| 76 | + fi |
| 77 | +done |
| 78 | + |
| 79 | +# Place `release-util.sh` for reuse |
| 80 | +cp "$SELF/../create-release/release-util.sh" "$WORKDIR" |
| 81 | + |
| 82 | +run_silent "Building spark-tpcds image with tag $IMGTAG..." "docker-build.log" \ |
| 83 | + docker build -t "spark-tpcds:$IMGTAG" --build-arg UID=$UID "$SELF/spark-tpcds" |
| 84 | + |
| 85 | +# Write the release information to a file with environment variables to be used when running the |
| 86 | +# image. |
| 87 | +ENVFILE="$WORKDIR/env.list" |
| 88 | +fcreate_secure "$ENVFILE" |
| 89 | + |
| 90 | +function cleanup { |
| 91 | + rm -f "$ENVFILE" |
| 92 | +} |
| 93 | + |
| 94 | +trap cleanup EXIT |
| 95 | + |
| 96 | +cat > $ENVFILE <<EOF |
| 97 | +RUNNING_IN_DOCKER=1 |
| 98 | +EOF |
| 99 | + |
| 100 | +echo "Building Spark to generate TPC-DS data; output will be at $WORKDIR/output/tpcds-data" |
| 101 | +docker run -ti \ |
| 102 | + --env-file "$ENVFILE" \ |
| 103 | + --volume "$WORKDIR:/opt/spark-tpcds" \ |
| 104 | + "spark-tpcds:$IMGTAG" |
0 commit comments