forked from databricks/databricks-sql-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2f5939
commit 9cf92be
Showing
8 changed files
with
73 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from databricks import sql | ||
import os | ||
import logging | ||
|
||
|
||
logger = logging.getLogger("databricks.sql") | ||
logger.setLevel(logging.DEBUG) | ||
fh = logging.FileHandler("pysqllogs.log") | ||
fh.setFormatter(logging.Formatter("%(asctime)s %(process)d %(thread)d %(message)s")) | ||
fh.setLevel(logging.DEBUG) | ||
logger.addHandler(fh) | ||
|
||
with sql.connect( | ||
server_hostname=os.getenv("DATABRICKS_SERVER_HOSTNAME"), | ||
http_path=os.getenv("DATABRICKS_HTTP_PATH"), | ||
access_token=os.getenv("DATABRICKS_TOKEN"), | ||
use_cloud_fetch=True, | ||
max_download_threads = 2 | ||
) as connection: | ||
|
||
with connection.cursor(arraysize=1000, buffer_size_bytes=54857600) as cursor: | ||
print( | ||
"executing query: SELECT * FROM range(0, 20000000) AS t1 LEFT JOIN (SELECT 1) AS t2" | ||
) | ||
cursor.execute("SELECT * FROM range(0, 20000000) AS t1 LEFT JOIN (SELECT 1) AS t2") | ||
try: | ||
while True: | ||
row = cursor.fetchone() | ||
if row is None: | ||
break | ||
print(f"row: {row}") | ||
except sql.exc.ResultSetDownloadError as e: | ||
print(f"error: {e}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,13 @@ | ||
import threading | ||
from databricks import sql | ||
import os | ||
import logging | ||
|
||
|
||
logger = logging.getLogger("databricks.sql") | ||
logger.setLevel(logging.DEBUG) | ||
fh = logging.FileHandler('pysqllogs.log') | ||
fh.setFormatter(logging.Formatter("%(asctime)s %(process)d %(thread)d %(message)s")) | ||
fh.setLevel(logging.DEBUG) | ||
logger.addHandler(fh) | ||
|
||
with sql.connect(server_hostname = os.getenv("DATABRICKS_SERVER_HOSTNAME"), | ||
http_path = os.getenv("DATABRICKS_HTTP_PATH"), | ||
access_token = os.getenv("DATABRICKS_TOKEN"), | ||
# max_download_threads = 2 | ||
) as connection: | ||
access_token = os.getenv("DATABRICKS_TOKEN")) as connection: | ||
|
||
with connection.cursor() as cursor: | ||
cursor.execute("SELECT * FROM default.diamonds LIMIT 2") | ||
result = cursor.fetchall() | ||
|
||
with connection.cursor( | ||
# arraysize=100 | ||
) as cursor: | ||
# cursor.execute("SELECT * FROM range(0, 10000000) AS t1 LEFT JOIN (SELECT 1) AS t2") | ||
cursor.execute("SELECT * FROM andre.plotly_iot_dashboard.bronze_sensors limit 1000001") | ||
try: | ||
result = cursor.fetchall() | ||
print(f"result length: {len(result)}") | ||
except sql.exc.ResultSetDownloadError as e: | ||
print(f"error: {e}") | ||
# buffer_size_bytes=4857600 | ||
for row in result: | ||
print(row) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters