-
Notifications
You must be signed in to change notification settings - Fork 3
/
cloud_import.sh
74 lines (69 loc) · 2 KB
/
cloud_import.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# Copyright (c) 2023, Crate.io Inc.
# Distributed under the terms of the Apache 2 license.
#
# About
# =====
#
# This is an example program demonstrating how to load data from
# files using the Import API interface of CrateDB Cloud into
# a CrateDB Cloud Cluster.
#
# The supported file types are CSV, JSON, Parquet, optionally with
# gzip compression. They can be acquired from the local filesystem,
# or from remote HTTP and AWS S3 resources.
#
# Setup
# =====
#
# To install the client SDK, use `pip`::
#
# pip install 'cratedb-toolkit'
#
# Configuration
# =============
#
# The program assumes you are appropriately authenticated to the CrateDB Cloud
# platform, for example using `croud login --idp azuread`. To inspect the list
# of available clusters, run `croud clusters list`.
#
# For addressing a database cluster, and obtaining corresponding credentials,
# the program uses environment variables, which you can define interactively,
# or store them within a `.env` file.
#
# You can use those configuration snippet as a blueprint. Please adjust the
# individual settings accordingly::
#
# CRATEDB_CLOUD_CLUSTER_NAME=Hotzenplotz
# CRATEDB_USERNAME='admin'
# CRATEDB_PASSWORD='H3IgNXNvQBJM3CiElOiVHuSp6CjXMCiQYhB4I9dLccVHGvvvitPSYr1vTpt4'
#
# Usage
# =====
#
# Initialize a cluster instance, and run a data import::
#
# bash examples/shell/cloud_import.sh
#
# Query imported data::
#
# ctk shell --command 'SELECT * FROM "nab-machine-failure" LIMIT 10;'
function setup() {
# Fail on errors.
set -e
# Load configuration settings from dotenv file.
# https://gist.github.com/mihow/9c7f559807069a03e302605691f85572
if [ -f .env ]; then
# Variant 1.
set -o allexport; source .env; set +o allexport
# Variant 2.
# export $(cat .env | xargs)
fi
}
function main() {
ctk cluster start
ctk load table "https:/crate/cratedb-datasets/raw/main/machine-learning/timeseries/nab-machine-failure.csv"
ctk shell --command 'SELECT * FROM "nab-machine-failure" LIMIT 10;'
}
setup
main