Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
buremba committed Aug 5, 2024
1 parent 99e009f commit bb40fbd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ sets up [filesystem](https://duckdb.org/docs/guides/python/filesystems.html) tha

* Smart caching for your Snowflake queries, reducing the compute costs. UniverSQL caches the SQL AST locally and re-uses the cache across multiple runs, better than Snowflake's [result cache](https://docs.snowflake.com/en/user-guide/querying-persisted-results).
* Query local files without any need to upload them to Snowflake for prototyping and only upload them when you want to share data with your colleagues.
* Utilize your hardware for running queries faster on small datasets and run queries on your data even when you're offline.
* Utilize your hardware for running queries faster on small datasets and run queries on your data even when you don't have internet connectivity.
* Develop end-user facing applications on top Snowflake, using DuckDB to query the data.
* Use DuckDB warehouse for managed and on-premise Polaris Catalog.

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions universql/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import yaml
from requests.exceptions import SSLError

from universql.util import LOCALHOST_UNIVERSQL_COM_BYTES, Compute, Catalog, sizeof_fmt
from universql.util import LOCALHOST_UNIVERSQL_COM_BYTES, Compute, Catalog, sizeof_fmt, prepend_to_lines

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("🏠")
Expand Down Expand Up @@ -91,7 +91,7 @@ def snowflake(host, port, ssl_keyfile, ssl_certfile, account, catalog, compute,
elif compute == Compute.SNOWFLAKE.value:
logger.info("The queries will run directly on Snowflake")

print(yaml.dump(params).strip())
click.secho(yaml.dump(params).strip())

if not ssl_keyfile or not ssl_certfile:
data = socket.gethostbyname_ex("localhostcomputing.com")
Expand Down
21 changes: 17 additions & 4 deletions universql/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import signal
import time
from threading import Thread
from traceback import print_exc
from uuid import uuid4

import click
Expand All @@ -22,7 +21,8 @@
from starlette.responses import JSONResponse, Response

from universql.lake.fsspec_util import pprint_disk_usage
from universql.util import unpack_request_body, session_from_request, SnowflakeError, parameters
from universql.util import unpack_request_body, session_from_request, SnowflakeError, parameters, \
print_dict_as_markdown_table
from fastapi.encoders import jsonable_encoder

from universql.warehouse.duckdb import UniverSQLSession
Expand Down Expand Up @@ -65,7 +65,8 @@ async def login_request(request: Request) -> JSONResponse:
except OAuthError as e:
message = e.args[0]

logger.info(f"[{token}] Created local session for user {credentials.get('user')} from {request.client.host}:{request.client.port}")
logger.info(
f"[{token}] Created local session for user {credentials.get('user')} from {request.client.host}:{request.client.port}")
return JSONResponse(
{
"data":
Expand Down Expand Up @@ -215,6 +216,8 @@ def harakiri(_, frame):


last_intent_to_kill = time.time()


def graceful_shutdown(_, frame):
global last_intent_to_kill
processing_sessions = sum(session.processing for token, session in sessions.items())
Expand All @@ -228,5 +231,15 @@ def graceful_shutdown(_, frame):
@app.on_event("startup")
async def startup_event():
import signal

signal.signal(signal.SIGINT, graceful_shutdown)
host_port = f"{current_context.get('host')}:{current_context.get('port')}"
connections = {
"Node.js": f"snowflake.createConnection({{accessUrl: 'https://{host_port}'}})",
"JDBC": f"jdbc:snowflake://{host_port}/dbname",
"Python": f"snowflake.connector.connect(host='{current_context.get('host')}', port='{current_context.get('port')}')",
"PHP": f"new PDO('snowflake:host={host_port}', '<user>', '<password>')",
"Go": f"sql.Open('snowflake', 'user:pass@{host_port}/dbname')",
".NET": f"host=;{host_port};db=testdb",
"ODBC": f"Server={current_context.get('host')}; Database=dbname; Port={current_context.get('port')}",
}
click.secho(print_dict_as_markdown_table(connections, footer_message=f"For other clients and applications, see https://github.com/buremba/universql",))
8 changes: 8 additions & 0 deletions universql/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,11 @@ def prepend_to_lines(input_string, prepend_string=" ", vertical_string='------')
modified_lines = [prepend_string + line for line in lines]
modified_string = '\n'.join(modified_lines)
return modified_string + '\n' + vertical_string


def print_dict_as_markdown_table(input_dict, footer_message : str, column_width=(8, 80)):
top_bottom_line = "─" * (87 + 8)
result = top_bottom_line
for key, value in input_dict.items():
result += f"\n{str(key).ljust(column_width[0])}{str(value).ljust(column_width[1])} │"
return result + '\n' + top_bottom_line + "\n│ " + footer_message.ljust(92) + '│\n' + top_bottom_line

0 comments on commit bb40fbd

Please sign in to comment.