Skip to content

Commit a6a21c6

Browse files
committed
feat(query): supporting changing endpoint in IPFS copy
1. remove over designed tests 2. enable changing endpoints in IPFS ```sql COPY INTO ontime FROM 'ipfs://<QMHASH>' CONNECTION = ( ENDPOINT_URL \ = 'https://ipfs.filebase.io' ); ``` Signed-off-by: ClSlaid <cailue@bupt.edu.cn>
1 parent 63b5688 commit a6a21c6

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

src/common/storage/src/location.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ pub fn parse_uri_location(l: &UriLocation) -> Result<(StorageParams, String)> {
9898
root: root.to_string(),
9999
}),
100100
Scheme::Ipfs => StorageParams::Ipfs(StorageIpfsConfig {
101-
endpoint_url: STORAGE_IPFS_DEFAULT_ENDPOINT.to_string(),
101+
endpoint_url: l
102+
.connection
103+
.get("endpoint_url")
104+
.cloned()
105+
.unwrap_or_else(|| STORAGE_IPFS_DEFAULT_ENDPOINT.to_string()),
102106
root: "/ipfs/".to_string() + l.name.as_str(),
103107
}),
104108
Scheme::S3 => StorageParams::S3(StorageS3Config {

src/common/storage/tests/location.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,38 @@ use common_storage::STORAGE_S3_DEFAULT_ENDPOINT;
3030
fn test_parse_uri_location() -> Result<()> {
3131
let cases = vec![
3232
(
33-
"ipfs-directory",
33+
"ipfs-default-endpoint",
3434
UriLocation {
3535
protocol: "ipfs".to_string(),
36-
name: "too-simple/".to_string(),
36+
name: "too-simple".to_string(),
3737
path: "/".to_string(),
3838
connection: BTreeMap::new(),
3939
},
4040
(
4141
StorageParams::Ipfs(StorageIpfsConfig {
4242
endpoint_url: STORAGE_IPFS_DEFAULT_ENDPOINT.to_string(),
43-
root: "/ipfs/too-simple/".to_string(),
43+
root: "/ipfs/too-simple".to_string(),
4444
}),
4545
"/".to_string(),
4646
),
4747
),
4848
(
49-
"ipfs-file",
49+
"ipfs-change-endpoint",
5050
UriLocation {
5151
protocol: "ipfs".to_string(),
5252
name: "too-naive".to_string(),
5353
path: "/".to_string(),
54-
connection: Default::default(),
54+
connection: vec![("endpoint_url", "https://ipfs.filebase.io")]
55+
.into_iter()
56+
.map(|(k, v)| (k.to_string(), v.to_string()))
57+
.collect(),
5558
},
5659
(
5760
StorageParams::Ipfs(StorageIpfsConfig {
58-
endpoint_url: STORAGE_IPFS_DEFAULT_ENDPOINT.to_string(),
59-
root: "/ipfs//".to_string(),
61+
endpoint_url: "https://ipfs.filebase.io".to_string(),
62+
root: "/ipfs/too-naive".to_string(),
6063
}),
61-
"too-naive".to_string(),
64+
"/".to_string(),
6265
),
6366
),
6467
(

tests/suites/1_stateful/00_copy/00_0000_copy_from_ipfs_location.sh

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,31 @@
22

33
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
44
. "$CURDIR"/../../../shell_env.sh
5-
TABLE=ontime200
6-
FILE=ontime_200
75
QMHASH=QmPpCt1aYGb9JWJRmXRUnmJtVgeFFTJGzWFYEEX7bo9zGJ
86

97
echo "drop table if exists ${TABLE};" | $MYSQL_CLIENT_CONNECT
108

119
## Create table
12-
cat $CURDIR/../ddl/ontime.sql | sed "s/ontime/$TABLE/g" | $MYSQL_CLIENT_CONNECT
10+
cat $CURDIR/../ddl/ontime.sql | sed "s/ontime/ontime_199/g" | $MYSQL_CLIENT_CONNECT
1311

1412
copy_from_location_cases=(
1513
# copy csv
16-
"copy into $TABLE from 'ipfs://$QMHASH/$FILE.csv' FILE_FORMAT = (type = 'CSV' field_delimiter = ',' record_delimiter = '\n' skip_header = 1)"
14+
"copy into ontime_199 from 'ipfs://$QMHASH/ontime.csv' CONNECTION = (ENDPOINT_URL='https://ipfs.filebase.io') FILE_FORMAT = (type = 'CSV' field_delimiter = ',' record_delimiter = '\n' skip_header = 1)"
1715
# copy gzip csv
18-
"copy into $TABLE from 'ipfs://$QMHASH/$FILE.csv.gz' FILE_FORMAT = (type = 'CSV' field_delimiter = ',' compression = 'gzip' record_delimiter = '\n' skip_header = 1)"
16+
"copy into ontime_199 from 'ipfs://$QMHASH/ontime.csv.gz' CONNECTION = (ENDPOINT_URL='https://ipfs.filebase.io') FILE_FORMAT = (type = 'CSV' field_delimiter = ',' compression = 'gzip' record_delimiter = '\n' skip_header = 1)"
1917
# copy zstd csv
20-
"copy into $TABLE from 'ipfs://$QMHASH/$FILE.csv.zstd' FILE_FORMAT = (type = 'CSV' field_delimiter = ',' compression = 'zstd' record_delimiter = '\n' skip_header = 1)"
18+
"copy into ontime_199 from 'ipfs://$QMHASH/ontime.csv.zst' CONNECTION = (ENDPOINT_URL='https://ipfs.filebase.io') FILE_FORMAT = (type = 'CSV' field_delimiter = ',' compression = 'zstd' record_delimiter = '\n' skip_header = 1)"
2119
# copy bz2 csv
22-
"copy into $TABLE from 'ipfs://$QMHASH/$FILE.csv.bz2' FILE_FORMAT = (type = 'CSV' field_delimiter = ',' compression = 'bz2' record_delimiter = '\n' skip_header = 1)"
20+
"copy into ontime_199 from 'ipfs://$QMHASH/ontime.csv.bz2' CONNECTION = (ENDPOINT_URL='https://ipfs.filebase.io') FILE_FORMAT = (type = 'CSV' field_delimiter = ',' compression = 'bz2' record_delimiter = '\n' skip_header = 1)"
2321
# copy xz csv
24-
"copy into $TABLE from 'ipfs://$QMHASH/$FILE.csv.xz' FILE_FORMAT = (type = 'CSV' field_delimiter = ',' compression = 'xz' record_delimiter = '\n' skip_header = 1)"
25-
# copy file
26-
"copy into $TABLE from 'ipfs://$QMHASH' FILES = ('$FILE.csv', '${FILE}_v1.csv') FILE_FORMAT = (type = 'CSV' field_delimiter = ',' record_delimiter = '\n' skip_header = 1)"
27-
# copy dir with pattern
28-
"copy into $TABLE from 'ipfs://$QMHASH' PATTERN = 'ontime.*csv' FILE_FORMAT = (type = 'CSV' field_delimiter = ',' record_delimiter = '\n' skip_header = 1)"
29-
# copy parquet
30-
"copy into $TABLE from 'ipfs://$QMHASH' PATTERN = 'ontime.*parquet' FILE_FORMAT = (type = 'PARQUET')"
22+
"copy into ontime_199 from 'ipfs://$QMHASH/ontime.csv.xz' CONNECTION = (ENDPOINT_URL='https://ipfs.filebase.io') FILE_FORMAT = (type = 'CSV' field_delimiter = ',' compression = 'xz' record_delimiter = '\n' skip_header = 1)"
3123
)
3224

3325
for i in "${copy_from_location_cases[@]}"; do
3426
echo "$i" | $MYSQL_CLIENT_CONNECT
35-
echo "select count(1), avg(Year), sum(DayOfWeek) from $TABLE" | $MYSQL_CLIENT_CONNECT
36-
echo "truncate table $TABLE" | $MYSQL_CLIENT_CONNECT
27+
echo "select count(1), avg(Year), sum(DayOfWeek) from ontime_199" | $MYSQL_CLIENT_CONNECT
28+
echo "truncate table ontime_199" | $MYSQL_CLIENT_CONNECT
3729
done
3830

3931
## Drop table
40-
echo "drop table if exists $TABLE;" | $MYSQL_CLIENT_CONNECT
32+
echo "drop table if exists ontime_199;" | $MYSQL_CLIENT_CONNECT

0 commit comments

Comments
 (0)