Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Azure File/URL helpers #1060

Closed
andrewbolster opened this issue Feb 16, 2024 · 0 comments
Closed

Add Azure File/URL helpers #1060

andrewbolster opened this issue Feb 16, 2024 · 0 comments

Comments

@andrewbolster
Copy link
Owner

def az_file_url_to_query_components(url:str):
    p = urlparse(url)
    assert not p.params, f"Invalid Params: {p.params}"
    assert not p.fragment, f"Invalid Fragment: {p.fragment}"
    assert not p.query, f"Invalid Params: {p.query}"
    
    netlocs =  p.netloc.split('.')
    assert len(netlocs) == 5, f"Invalid netlocs: {p.netloc}: Not long enough"
    assert netlocs[2:] == ['core','windows','net'], f"Invalid netlocs: {p.netloc} should end in core.windows.net"
    assert netlocs[1] in ['blob','dfs'], f"Invalid netlocs: {p.netloc} should be one of blob/dfs"
    
    storage_account = netlocs[0]
    _, container, *paths = p.path.split('/') #path starts with a / so p.path.split('/')[0] == ''
    file_path = '/'.join(paths)

    return  dict(
        storage_account = storage_account, 
        container = container,
        file_path = file_path
    )

And then query like

d = az_file_url_to_query_components("https://storageaccount.blob.core.windows.net/container/file_path.parquet")
df = pd.read_parquet(
  f"az://{d['container']}/{d['file_path']}", 
  storage_options = dict(
    account_name=d['storage_account'], 
    anon=False)
)
andrewbolster added a commit that referenced this issue Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant