My 1billion row challenge solutions in various languages
at main 2.4 kB view raw
1#!/bin/bash 2# 3# Copyright 2023 The original authors 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17 18set -eo pipefail 19 20SOURCE_FORK="baseline" 21 22usage() { 23 echo "Usage: create_fork.sh [-s <source fork>] <fork name>" 24 echo " -s <source fork> The name of the fork to copy from (default: baseline)" 25 echo " <fork name> The name of the fork to create" 26 exit 1 27} 28 29# Parse 30while getopts ":s:" opt; do 31 case ${opt} in 32 s ) 33 SOURCE_FORK=$OPTARG 34 ;; 35 \? ) 36 usage 37 exit 1 38 ;; 39 : ) 40 echo "Invalid option: $OPTARG requires an argument" 1>&2 41 exit 1 42 ;; 43 esac 44done 45 46FORK=${@:$OPTIND:1} 47if [ -z "$FORK" ] 48 then 49 usage 50 exit 1 51fi 52 53# validate the fork name has only [a-zA-Z0-9_] and then error otherwise to let the user fix 54if [[ ! "$FORK" =~ ^[a-zA-Z0-9_]+$ ]]; then 55 echo "Fork name must only contain characters result in a valid Java class name [a-zA-Z0-9_]" 56 exit 1 57fi 58 59 60# helper function 61function substitute_in_file { 62 if [[ "$OSTYPE" == "darwin"* ]]; then 63 sed -i '' "s/$1/$2/g" $3 64 else 65 sed -i "s/$1/$2/g" $3 66 fi 67} 68 69set -x 70 71# create new fork 72 73cp -i prepare_$SOURCE_FORK.sh prepare_$FORK.sh 74 75cp -i calculate_average_$SOURCE_FORK.sh calculate_average_$FORK.sh 76substitute_in_file $SOURCE_FORK $FORK calculate_average_$FORK.sh 77 78if [ $SOURCE_FORK == "baseline" ]; then 79 cp -i src/main/java/dev/morling/onebrc/CalculateAverage_baseline.java src/main/java/dev/morling/onebrc/CalculateAverage_$FORK.java 80 substitute_in_file CalculateAverage_baseline CalculateAverage_$FORK src/main/java/dev/morling/onebrc/CalculateAverage_$FORK.java 81else 82 cp -i src/main/java/dev/morling/onebrc/CalculateAverage_$SOURCE_FORK.java src/main/java/dev/morling/onebrc/CalculateAverage_$FORK.java 83 substitute_in_file $SOURCE_FORK $FORK src/main/java/dev/morling/onebrc/CalculateAverage_$FORK.java 84fi 85