Skip to content

tested and working #3

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Maheidem
Copy link

@Maheidem Maheidem commented Apr 8, 2025

feel free to accept or not, but it's heloping me a lot

Comment on lines +551 to +556
cmd = [
"curl", "-s",
"-H", f"Authorization: Bearer {DATABRICKS_TOKEN}",
"-H", "Content-Type: application/json",
f"https://{DATABRICKS_HOST}/api/2.0/dbfs/list?path={path}"
]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here we can use the request function as in the other calls. Not sure why to do it using subprocess and cmd.

Databricks API call

Comment on lines +601 to +607
# Build URL with query parameters directly
encoded_path = urllib.parse.quote(path)
url = f"https://{DATABRICKS_HOST}/api/2.0/dbfs/read?path={encoded_path}&length={length}"

print(f"Requesting URL: {url}")
response = requests.get(url, headers=headers)
print(f"Status code: {response.status_code}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, we can reuse the databricks_api_request function

Comment on lines +639 to +652
headers = {
"Authorization": f"Bearer {DATABRICKS_TOKEN}",
"Content-Type": "application/json"
}

# DBFS file upload requires three steps:
# 1. Create a handle
create_url = f"https://{DATABRICKS_HOST}/api/2.0/dbfs/create"
create_data = {
"path": dbfs_path,
"overwrite": overwrite
}

create_response = requests.post(create_url, headers=headers, json=create_data)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Comment on lines +695 to +707
headers = {
"Authorization": f"Bearer {DATABRICKS_TOKEN}",
"Content-Type": "application/json"
}

# Build URL with query parameters directly
encoded_path = urllib.parse.quote(path)
url = f"https://{DATABRICKS_HOST}/api/2.0/workspace/list?path={encoded_path}"

print(f"Requesting URL: {url}")
response = requests.get(url, headers=headers)
print(f"Status code: {response.status_code}")
print(f"Response: {response.text}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Comment on lines +745 to +757
headers = {
"Authorization": f"Bearer {DATABRICKS_TOKEN}",
"Content-Type": "application/json"
}

# Build request
export_url = f"https://{DATABRICKS_HOST}/api/2.0/workspace/export"
export_data = {
"path": path,
"format": format
}

response = requests.get(export_url, headers=headers, params=export_data)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Comment on lines +818 to +839
headers = {
"Authorization": f"Bearer {DATABRICKS_TOKEN}",
"Content-Type": "application/json"
}

# Encode the content as base64
import base64
content_bytes = content.encode("utf-8")
encoded_content = base64.b64encode(content_bytes).decode("utf-8")

# Build request
import_url = f"https://{DATABRICKS_HOST}/api/2.0/workspace/import"
import_data = {
"path": path,
"content": encoded_content,
"language": language,
"format": format,
"overwrite": overwrite
}

response = requests.post(import_url, headers=headers, json=import_data)
response.raise_for_status()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@JordiNeil
Copy link
Owner

Thank you so much for this contribution!

Let me know if you want to apply the changes, if not, I'll apply them later 😄

@Maheidem
Copy link
Author

Maheidem commented Apr 9, 2025

My honest take is that i actually did a lot of this with AI to get it working faster. I actually use for my job.
If you see improvements to be made, please fell free.
I am going into this a data science and not software eng.

@JordiNeil
Copy link
Owner

Hey, yes, I noticed you used AI 😅
I'll take your suggestions and apply them with the fixes. I'll let you know when they're in the main branch.

Thank you! 🙏

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

Successfully merging this pull request may close these issues.

2 participants