|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. 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, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +# GH-48068 TODO: run remote ODBC tests on Linux |
| 19 | + |
| 20 | +#!/bin/bash |
| 21 | +set -e |
| 22 | + |
| 23 | +HOST_URL="http://localhost:9047" |
| 24 | +NEW_USER_URL="$HOST_URL/apiv2/bootstrap/firstuser" |
| 25 | +LOGIN_URL="$HOST_URL/apiv2/login" |
| 26 | +SQL_URL="$HOST_URL/api/v3/sql" |
| 27 | + |
| 28 | +ADMIN_USER="admin" |
| 29 | +ADMIN_PASSWORD="admin2025" |
| 30 | + |
| 31 | +# Wait for Dremio to be available. |
| 32 | +until curl -s "$NEW_USER_URL"; do |
| 33 | + echo 'Waiting for Dremio to start...' |
| 34 | + sleep 5 |
| 35 | +done |
| 36 | + |
| 37 | +echo "" |
| 38 | +echo 'Creating admin user...' |
| 39 | + |
| 40 | +# Create new admin account. |
| 41 | +curl -X PUT "$NEW_USER_URL" \ |
| 42 | + -H "Content-Type: application/json" \ |
| 43 | + -d "{ \"userName\": \"$ADMIN_USER\", \"password\": \"$ADMIN_PASSWORD\" }" |
| 44 | + |
| 45 | +echo "" |
| 46 | +echo "Created admin user." |
| 47 | + |
| 48 | +# Use admin account to login and acquire a token. |
| 49 | +TOKEN=$(curl -s -X POST "$LOGIN_URL" \ |
| 50 | + -H "Content-Type: application/json" \ |
| 51 | + -d "{ \"userName\": \"$ADMIN_USER\", \"password\": \"$ADMIN_PASSWORD\" }" \ |
| 52 | + | grep -oP '(?<="token":")[^"]+') |
| 53 | + |
| 54 | +SQL_QUERY="Create Table \$scratch.ODBCTest As SELECT CAST(2147483647 AS INTEGER) AS sinteger_max, CAST(9223372036854775807 AS BIGINT) AS sbigint_max, CAST(999999999 AS DECIMAL(38,0)) AS decimal_positive, CAST(3.40282347E38 AS FLOAT) AS float_max, CAST(1.7976931348623157E308 AS DOUBLE) AS double_max, CAST(true AS BOOLEAN) AS bit_true, CAST(DATE '9999-12-31' AS DATE) AS date_max, CAST(TIME '23:59:59' AS TIME) AS time_max, CAST(TIMESTAMP '9999-12-31 23:59:59' AS TIMESTAMP) AS timestamp_max;" |
| 55 | +ESCAPED_QUERY=$(printf '%s' "$SQL_QUERY" | sed 's/"/\\"/g') |
| 56 | + |
| 57 | +echo "Creating \$scratch.ODBCTest table." |
| 58 | + |
| 59 | +# Create a new table by sending a SQL query. |
| 60 | +curl -i -X POST "$SQL_URL" \ |
| 61 | + -H "Authorization: _dremio$TOKEN" \ |
| 62 | + -H "Content-Type: application/json" \ |
| 63 | + -d "{\"sql\": \"$ESCAPED_QUERY\"}" |
| 64 | + |
| 65 | +echo "" |
| 66 | +echo "Finished setting up dremio docker instance." |
0 commit comments