Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# remove python bytecode files
*.pyc
Binary file added pykylin/.DS_Store
Binary file not shown.
Binary file removed pykylin/__init__.pyc
Binary file not shown.
18 changes: 14 additions & 4 deletions pykylin/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
from .cursor import Cursor
from .proxy import Proxy
from .log import logger
#import sys
#import importlib,sys
#reload(sys)
#sys.setdefaultencoding('utf-8')

class Connection(object):

def __init__(self, username, password, endpoint, project, **kwargs):
self.endpoint = endpoint
self.username = username
self.password = password
self.project = project
self.proxy = Proxy(self.endpoint)
self.limit = kwargs['limit'] if 'limit' in kwargs else 50000

self.proxy.login(self.username, self.password)

def close(self):
Expand All @@ -29,7 +31,8 @@ def list_tables(self):
route = 'tables_and_columns'
params = {'project': self.project}
tables = self.proxy.get(route, params=params)
return [t['table_NAME'] for t in tables]
tableNames = [t['table_NAME'] for t in tables]
return tableNames

def list_columns(self, table_name):
table_NAME = str(table_name).upper()
Expand All @@ -39,9 +42,16 @@ def list_columns(self, table_name):
table = [t for t in tables if t['table_NAME'] == table_NAME][0]
return table['columns']

def list_schemas(self):
route = 'tables_and_columns'
params = {'project': self.project}
tables = self.proxy.get(route, params=params)
schema_names = [t['table_SCHEM'] for t in tables]
logger.info("schema_names is : "+str(schema_names))
return schema_names

def cursor(self):
return Cursor(self)


def connect(username='', password='', endpoint='', project='', **kwargs):
return Connection(username, password, endpoint, project, **kwargs)
Binary file removed pykylin/connection.pyc
Binary file not shown.
8 changes: 8 additions & 0 deletions pykylin/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def execute(self, operation, parameters={}, acceptPartial=True, limit=None, offs
resp = self.connection.proxy.post('query', json=data)

column_metas = resp['columnMetas']

for c in column_metas:
c['label']=str(c['label']).lower()
c['name']=str(c['name']).lower()

self.description = [
[c['label'], c['columnTypeName'],
c['displaySize'], 0,
Expand All @@ -54,6 +59,9 @@ def _type_mapped(self, result):
column = meta[i]
tpe = column[1]
val = result[i]
#skip null value
if val is None:
pass
if tpe == 'DATE':
val = parser.parse(val)
elif tpe == 'BIGINT' or tpe == 'INT' or tpe == 'TINYINT':
Expand Down
Binary file removed pykylin/cursor.pyc
Binary file not shown.
13 changes: 9 additions & 4 deletions pykylin/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,17 @@ def initialize(self, connection):

def create_connect_args(self, url):
opts = url.translate_connect_args()
api_prefix="kylin/api"
args = {
'username': opts['username'],
'password': opts['password'],
'endpoint': 'http://%s:%s/%s' % (opts['host'], opts['port'], opts['database'])
'endpoint': 'http://%s:%s/%s' % (opts['host'], opts['port'],api_prefix)
}
args.update(url.query)
return [], args

def get_table_names(self, connection, schema=None, **kw):
def get_table_names(self, engine, schema=None, **kw):
connection = engine.contextual_connect()
return connection.connection.list_tables()

def has_table(self, connection, table_name, schema=None):
Expand All @@ -153,7 +155,8 @@ def has_table(self, connection, table_name, schema=None):
def has_sequence(self, connection, sequence_name, schema=None):
return False

def get_columns(self, connection, table_name, schema=None, **kw):
def get_columns(self, engine, table_name, schema=None, **kw):
connection = engine.contextual_connect()
cols = connection.connection.list_columns(table_name)
return [self._map_column_type(c) for c in cols]

Expand Down Expand Up @@ -191,4 +194,6 @@ def get_pk_constraint(self, conn, table_name, schema=None, **kw):
def get_unique_constraints(
self, connection, table_name, schema=None, **kw):
return []

def get_schema_names(self, engine, schema=None, **kw):
connection = engine.contextual_connect()
return connection.connection.list_schemas()
Binary file removed pykylin/dialect.pyc
Binary file not shown.
Binary file removed pykylin/encoding.pyc
Binary file not shown.
Binary file removed pykylin/errors.pyc
Binary file not shown.
Binary file removed pykylin/log.pyc
Binary file not shown.
6 changes: 4 additions & 2 deletions pykylin/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def login(self, user, password):
route = 'user/authentication'
url = '%s/%s' % (self.base_url, route)
self.user = user
self.password = user
self.password = password
self.auth = HTTPBasicAuth(user, password)
resp = requests.post(url, auth=self.auth, headers=self.headers)

Expand All @@ -48,7 +48,9 @@ def request(self, method, route, **kwargs):
finally:
raise Error('Error when requesting: "%s", exception: "%s"' % (route, exception))

return decode(resp.text)
responseText= decode(resp.text)
#logger.info('response text is: '+str(responseText))
return responseText

def post(self, route, **kwargs):
return self.request('post', route, **kwargs)
Expand Down
Binary file removed pykylin/proxy.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion pykylin/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from sqlalchemy import types as sqltypes
from sqlalchemy.types import INTEGER, BIGINT, SMALLINT, VARCHAR, CHAR, \
FLOAT, DATE, BOOLEAN
FLOAT, DATE, BOOLEAN, TIMESTAMP

class DOUBLE(sqltypes.Float):
__visit_name__ = 'DOUBLE'
Expand All @@ -24,4 +24,5 @@ class TINYINT(sqltypes.Integer):
'FLOAT': FLOAT,
'SMALLINT': SMALLINT,
'VARCHAR': VARCHAR,
'TIMESTAMP(0)': TIMESTAMP
}
Binary file removed pykylin/types.pyc
Binary file not shown.
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
requests==2.8.1
python-dateutil==2.4.2
requests==2.14.2
#解决版本冲突问题
python-dateutil==2.6.0