Skip to content

Commit bc5e716

Browse files
move guid to hex id to new utils module
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent 1ec8c45 commit bc5e716

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

src/databricks/sql/backend/thrift_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
SessionId,
1616
CommandId,
1717
BackendType,
18-
guid_to_hex_id,
1918
)
19+
from databricks.sql.backend.utils import guid_to_hex_id
2020

2121
try:
2222
import pyarrow

src/databricks/sql/backend/types.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
11
from enum import Enum
22
from typing import Dict, Optional, Any, Union
3-
import uuid
43
import logging
54

6-
logger = logging.getLogger(__name__)
7-
8-
9-
def guid_to_hex_id(guid: bytes) -> str:
10-
"""Return a hexadecimal string instead of bytes
5+
from databricks.sql.backend.utils import guid_to_hex_id
116

12-
Example:
13-
IN b'\x01\xee\x1d)\xa4\x19\x1d\xb6\xa9\xc0\x8d\xf1\xfe\xbaB\xdd'
14-
OUT '01ee1d29-a419-1db6-a9c0-8df1feba42dd'
15-
16-
If conversion to hexadecimal fails, the original bytes are returned
17-
"""
18-
try:
19-
this_uuid = uuid.UUID(bytes=guid)
20-
except Exception as e:
21-
logger.debug(f"Unable to convert bytes to UUID: {guid!r} -- {str(e)}")
22-
return str(guid)
23-
return str(this_uuid)
7+
logger = logging.getLogger(__name__)
248

259

2610
class BackendType(Enum):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .guid_utils import guid_to_hex_id
2+
3+
__all__ = ["guid_to_hex_id"]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import uuid
2+
import logging
3+
4+
logger = logging.getLogger(__name__)
5+
6+
7+
def guid_to_hex_id(guid: bytes) -> str:
8+
"""Return a hexadecimal string instead of bytes
9+
10+
Example:
11+
IN b'\x01\xee\x1d)\xa4\x19\x1d\xb6\xa9\xc0\x8d\xf1\xfe\xbaB\xdd'
12+
OUT '01ee1d29-a419-1db6-a9c0-8df1feba42dd'
13+
14+
If conversion to hexadecimal fails, the original bytes are returned
15+
"""
16+
try:
17+
this_uuid = uuid.UUID(bytes=guid)
18+
except Exception as e:
19+
logger.debug(f"Unable to convert bytes to UUID: {guid!r} -- {str(e)}")
20+
return str(guid)
21+
return str(this_uuid)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy