forked from databricks/databricks-sql-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
50 lines (33 loc) · 1.24 KB
/
__init__.py
File metadata and controls
50 lines (33 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import datetime
from databricks.sql.exc import *
# PEP 249 module globals
apilevel = "2.0"
threadsafety = 1 # Threads may share the module, but not connections.
paramstyle = "pyformat" # Python extended format codes, e.g. ...WHERE name=%(name)s
class DBAPITypeObject(object):
def __init__(self, *values):
self.values = values
def __eq__(self, other):
return other in self.values
def __repr__(self):
return "DBAPITypeObject({})".format(self.values)
STRING = DBAPITypeObject("string")
BINARY = DBAPITypeObject("binary")
NUMBER = DBAPITypeObject(
"boolean", "tinyint", "smallint", "int", "bigint", "float", "double", "decimal"
)
DATETIME = DBAPITypeObject("timestamp")
DATE = DBAPITypeObject("date")
ROWID = DBAPITypeObject()
__version__ = "2.0.4-dev"
USER_AGENT_NAME = "PyDatabricksSqlConnector"
# These two functions are pyhive legacy
Date = datetime.date
Timestamp = datetime.datetime
def DateFromTicks(ticks):
return Date(*time.localtime(ticks)[:3])
def TimestampFromTicks(ticks):
return Timestamp(*time.localtime(ticks)[:6])
def connect(server_hostname, http_path, access_token, **kwargs):
from .client import Connection
return Connection(server_hostname, http_path, access_token, **kwargs)