Skip to content

Commit

Permalink
truncate sync queries in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
buremba committed Jan 9, 2025
1 parent a328158 commit 413f275
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
21 changes: 4 additions & 17 deletions universql/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,7 @@ class Catalog(Enum):
# {"name": "CLIENT_STAGE_ARRAY_BINDING_THRESHOLD", "value": 65280}]


def session_from_request(self, request):
"""
Get a request's relevant session
"""
auth = request.headers.get('Authorization')
if not auth:
raise HTTPException(status_code=401, detail='No Authorization header')
if not auth.startswith('Snowflake Token="'):
raise HTTPException(status_code=401, detail='Invalid Authorization header')
token = auth[17:-1]
if token not in self.sessions:
raise HTTPException(status_code=401, detail='Invalid Authorization header')
return self.sessions[token]



@dataclass
Expand Down Expand Up @@ -296,7 +284,6 @@ def session_from_request(sessions: List[str], request: Request):
detail="User must login again to access the service. Maybe server restarted? Restarting Universql aborts all the concurrent sessions.")
return sessions[token]


def pprint_secs(secs):
"""Format seconds in a human readable form."""
now = time.time()
Expand All @@ -318,9 +305,9 @@ def get_friendly_time_since(start_time, performance_counter):
suppress=["days"], format="%0.3f")


def prepend_to_lines(input_string, prepend_string=" ", vertical_string='------'):
if len(input_string) > 2500:
input_string = input_string[0:2500] + '[striped due to max 2500 character limit]'
def prepend_to_lines(input_string, prepend_string=" ", vertical_string='------', max = 2500):
if len(input_string) > max:
input_string = input_string[0:max] + '[striped due to max 2500 character limit]'
lines = input_string.split('\n')
modified_lines = [prepend_string + line for line in lines]
modified_string = '\n'.join(modified_lines)
Expand Down
3 changes: 1 addition & 2 deletions universql/warehouse/duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ def _sync_catalog(self, locations: Tables):
views_sql = ";\n".join(databases_sql + schemas_sql + setup_query + views_sql)

if views_sql != "":
logger.info(
f"[{self.catalog.session_id}] DuckDB environment is setting up:\n{views_sql}")
logger.debug(f"[{self.catalog.session_id}] DuckDB environment is setting up:\n{prepend_to_lines(views_sql, max=1000)}")
try:
self.catalog.duckdb.execute(views_sql)
except duckdb.Error as e:
Expand Down

0 comments on commit 413f275

Please sign in to comment.