Skip to content

Commit 5e0bad3

Browse files
author
Yufei Gu
committed
Support catalog backed by s3 in run_spark_sql.sh
1 parent f3c7a5e commit 5e0bad3

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

regtests/run_spark_sql.sh

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,19 @@
1616
# KIND, either express or implied. See the License for the
1717
# specific language governing permissions and limitations
1818
# under the License.
19+
20+
# -----------------------------------------------------------------------------
21+
# Purpose: Launch the Spark SQL shell to interact with Polaris.
22+
# -----------------------------------------------------------------------------
1923
#
24+
# Usage:
25+
# Without arguments: Runs against a catalog backed by the local filesystem
26+
# With two arguments: Runs against a catalog backed by AWS S3
27+
# Example: ./run_spark_sql.sh s3://my-bucket/path arn:aws:iam::123456789001:principal/my-role
2028
#
21-
# Run this to open an interactive spark-sql shell talking to a catalog named "manual_spark"
22-
#
29+
# Arguments:
30+
# [S3 location] - The S3 path to use as the default base location for the catalog.
31+
# [AWS IAM role] - The AWS IAM role to assume when the catalog accessing the S3 location.
2332

2433
REGTEST_HOME=$(dirname $(realpath $0))
2534
cd ${REGTEST_HOME}
@@ -35,9 +44,9 @@ fi
3544

3645
SPARK_BEARER_TOKEN="${REGTEST_ROOT_BEARER_TOKEN:-principal:root;realm:default-realm}"
3746

38-
# If argument 1 doesn't exist, use local filesystem
47+
# use local filesystem if no arguments are provided
3948
if [ -z "$1" ]; then
40-
# Use local filesystem by default
49+
# create a catalog backed by the local filesystem
4150
curl -X POST -H "Authorization: Bearer ${SPARK_BEARER_TOKEN}" \
4251
-H 'Accept: application/json' \
4352
-H 'Content-Type: application/json' \
@@ -59,13 +68,15 @@ if [ -z "$1" ]; then
5968
}
6069
}'
6170
else
62-
# Check if AWS environment variables are set
63-
if [ -z "${AWS_TEST_BASE}" ] || [ -z "${AWS_ROLE_ARN}" ]; then
64-
echo "AWS_TEST_BASE or AWS_ROLE_ARN not set. Please set them to enable S3 integration."
71+
AWS_BASE_LOCATION=$1
72+
AWS_ROLE_ARN=$2
73+
# Check if AWS variables are set
74+
if [ -z "${AWS_BASE_LOCATION}" ] || [ -z "${AWS_ROLE_ARN}" ]; then
75+
echo "AWS_BASE_LOCATION or/and AWS_ROLE_ARN not set. Please set them to create a catalog backed by S3."
6576
exit 1
6677
fi
6778

68-
# Use S3
79+
# create a catalog backed by S3
6980
curl -i -X POST -H "Authorization: Bearer ${SPARK_BEARER_TOKEN}" \
7081
-H 'Accept: application/json' \
7182
-H 'Content-Type: application/json' \
@@ -76,11 +87,11 @@ else
7687
\"type\": \"INTERNAL\",
7788
\"readOnly\": false,
7889
\"properties\": {
79-
\"default-base-location\": \"${AWS_TEST_BASE}\"
90+
\"default-base-location\": \"${AWS_BASE_LOCATION}\"
8091
},
8192
\"storageConfigInfo\": {
8293
\"storageType\": \"S3\",
83-
\"allowedLocations\": [\"${AWS_TEST_BASE}/\"],
94+
\"allowedLocations\": [\"${AWS_BASE_LOCATION}/\"],
8495
\"roleArn\": \"${AWS_ROLE_ARN}\"
8596
}
8697
}"
@@ -91,7 +102,7 @@ curl -i -X PUT -H "Authorization: Bearer ${SPARK_BEARER_TOKEN}" -H 'Accept: appl
91102
http://${POLARIS_HOST:-localhost}:8181/api/management/v1/catalogs/manual_spark/catalog-roles/catalog_admin/grants \
92103
-d '{"type": "catalog", "privilege": "TABLE_WRITE_DATA"}' > /dev/stderr
93104

94-
# For now, also explicitly assign the catalog_admin to the service_admin. Remove once GS fully rolled out for auto-assign.
105+
# Assign the catalog_admin to the service_admin.
95106
curl -i -X PUT -H "Authorization: Bearer ${SPARK_BEARER_TOKEN}" -H 'Accept: application/json' -H 'Content-Type: application/json' \
96107
http://${POLARIS_HOST:-localhost}:8181/api/management/v1/principal-roles/service_admin/catalog-roles/manual_spark \
97108
-d '{"name": "catalog_admin"}' > /dev/stderr

0 commit comments

Comments
 (0)