-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathcopy_to_and_scan.slt
115 lines (100 loc) · 2.21 KB
/
copy_to_and_scan.slt
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Basic tests for copy to.
statement ok
COPY ( SELECT 1 AS a, 2 AS b ) TO gcs
OPTIONS (
service_account_key = '${GCP_SERVICE_ACCOUNT_KEY}',
bucket = '${GCS_BUCKET_NAME}',
location = 'copy_to/with_opts.csv'
);
query II
SELECT * FROM csv_scan(
'gs://${GCS_BUCKET_NAME}/copy_to/with_opts.csv',
service_account_key => '${GCP_SERVICE_ACCOUNT_KEY}'
);
----
1 2
statement ok
COPY ( SELECT 3 AS a, 4 AS b )
TO 'gs://${GCS_BUCKET_NAME}/copy_to/with_url.csv'
OPTIONS (
service_account_key = '${GCP_SERVICE_ACCOUNT_KEY}',
);
query II
SELECT b, a FROM csv_scan(
'gs://${GCS_BUCKET_NAME}/copy_to/with_url.csv',
service_account_key => '${GCP_SERVICE_ACCOUNT_KEY}'
);
----
4 3
# Credentials
statement ok
CREATE CREDENTIALS gcp_creds PROVIDER gcp
( service_account_key '${GCP_SERVICE_ACCOUNT_KEY}' );
statement ok
COPY ( SELECT 5 AS a, 6 AS b )
TO 'gs://${GCS_BUCKET_NAME}/copy_to/with_creds.csv'
CREDENTIALS gcp_creds;
query II
SELECT a, b FROM csv_scan(
'gs://${GCS_BUCKET_NAME}/copy_to/with_creds.csv',
gcp_creds
);
----
5 6
# Multiple URLs
query II rowsort
SELECT a, b FROM csv_scan(
[
'gs://${GCS_BUCKET_NAME}/copy_to/with_opts.csv',
'gs://${GCS_BUCKET_NAME}/copy_to/with_url.csv',
'gs://${GCS_BUCKET_NAME}/copy_to/with_creds.csv'
],
service_account_key => '${GCP_SERVICE_ACCOUNT_KEY}'
);
----
1 2
3 4
5 6
query II rowsort
SELECT a, b FROM csv_scan(
[
'gs://${GCS_BUCKET_NAME}/copy_to/with_opts.csv',
'gs://${GCS_BUCKET_NAME}/copy_to/with_url.csv',
'gs://${GCS_BUCKET_NAME}/copy_to/with_creds.csv'
],
gcp_creds
);
----
1 2
3 4
5 6
query II rowsort
SELECT a, b FROM csv_scan(
'gs://${GCS_BUCKET_NAME}/copy_to/with_*.csv',
gcp_creds
);
----
1 2
3 4
5 6
# Test multiple URLs with globs (and different kinds of globs).
statement ok
COPY ( SELECT 7 AS a, 8 AS b )
TO 'gs://${GCS_BUCKET_NAME}/copy_to_with_creds.csv'
CREDENTIALS gcp_creds;
# Found a bug out of the blue, previous code took the prefix for search as
# "abc" when querying glob pattern "abc*". Since object_store adds a "/",
# prefix in this case should be None.
query II rowsort
SELECT a, b FROM csv_scan(
[
'gs://${GCS_BUCKET_NAME}/copy_to*',
'gs://${GCS_BUCKET_NAME}/**/with_*.csv'
],
gcp_creds
);
----
1 2
3 4
5 6
7 8