Skip to content

Commit 9efc12b

Browse files
committed
use override for asset uri and maintain az://
1 parent 688765e commit 9efc12b

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

‎datasets/gbif/gbif_pkg/gbif.py‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict, List, Optional, Union
1+
from typing import List, Union
22

33
import pystac
44

@@ -15,28 +15,27 @@ def create_item(
1515
) -> Union[List[pystac.Item], WaitTaskResult]:
1616
from gbif_pkg.gbif_tools import create_item
1717

18-
storage_options: Optional[Dict[str, str]]
19-
asset_extra_fields: Optional[Dict[str, Optional[Dict[str, str]]]]
20-
2118
storage, path = storage_factory.get_storage_for_file(asset_uri)
2219
if isinstance(storage, BlobStorage):
23-
href = f"https://{storage.storage_account_name}.blob.core.windows.net/{storage.container_name}/{path}"
20+
az_uri = f"az://{storage.container_name}/{path}".rstrip("/")
21+
https_href = f"https://{storage.storage_account_name}.blob.core.windows.net/{storage.container_name}/{path}".rstrip("/")
2422
storage_options = dict(account_name=storage.storage_account_name)
2523
asset_extra_fields = {
2624
"table:storage_options": storage_options,
2725
"msft:partition_info": {
2826
"is_partitioned": True
2927
}
3028
}
29+
item = create_item(
30+
az_uri,
31+
storage_options=storage_options,
32+
asset_extra_fields=asset_extra_fields,
33+
asset_href_override=https_href,
34+
)
3135
else:
32-
href = storage.get_url(path)
33-
storage_options = dict()
34-
asset_extra_fields = None
35-
36-
href = href.rstrip("/")
37-
38-
item = create_item(
39-
href, storage_options=storage_options, asset_extra_fields=asset_extra_fields
40-
)
36+
href = storage.get_url(path).rstrip("/")
37+
item = create_item(
38+
href, storage_options=dict(), asset_extra_fields=None
39+
)
4140

4241
return [item]

‎datasets/gbif/gbif_pkg/gbif_tools.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
PARQUET_MEDIA_TYPE = "application/x-parquet"
7979

8080

81-
def create_item(asset_href: str, storage_options=None, asset_extra_fields=None) -> pystac.Item:
81+
def create_item(asset_href: str, storage_options=None, asset_extra_fields=None, asset_href_override=None) -> pystac.Item:
8282
"""
8383
Create a STAC item for a GBIF Parquet Dataset.
8484
@@ -127,6 +127,7 @@ def create_item(asset_href: str, storage_options=None, asset_extra_fields=None)
127127
proj=False,
128128
asset_extra_fields=asset_extra_fields,
129129
count_rows=False,
130+
asset_href_override=asset_href_override,
130131
)
131132

132133
for column in result.properties["table:columns"]:
@@ -223,6 +224,7 @@ def generate(
223224
proj=True,
224225
storage_options=None,
225226
validate=True,
227+
asset_href_override=None,
226228
) -> T:
227229
"""
228230
Generate a STAC Item from a Parquet Dataset.
@@ -406,7 +408,7 @@ def generate(
406408

407409
if asset_key:
408410
asset = pystac.asset.Asset(
409-
uri,
411+
asset_href_override if asset_href_override is not None else uri,
410412
title="Dataset root",
411413
media_type=PARQUET_MEDIA_TYPE,
412414
roles=["data"],

0 commit comments

Comments
 (0)