Skip to content

Commit

Permalink
Merge branch 'hotfix/1.5.13'
Browse files Browse the repository at this point in the history
  • Loading branch information
akuzminsky committed May 15, 2018
2 parents 6a448f5 + 4839a86 commit dbc8a35
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 161 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ target/
/vagrant/.vagrant/
/etcdb/sqlparser/parser.out
/tests/developement/
/.pytest_cache/
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@ install: clean ## install the package to the active Python's site-packages
docker-start:
@docker run \
-v $(shell pwd):/etcdb \
--rm \
-it \
ubuntu:xenial \
/bin/bash -l

docker-test-func:
@docker run \
-v $(shell pwd):/etcdb \
--rm \
ubuntu:xenial \
/bin/bash -l /etcdb/support/run_func_test.sh
2 changes: 1 addition & 1 deletion etcdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

__author__ = 'Box TechOps Database Team'
__email__ = '[email protected]'
__version__ = '1.5.12'
__version__ = '1.5.13'


def _split_version(version):
Expand Down
11 changes: 6 additions & 5 deletions etcdb/eval_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ class EtcdbFunction(object):
:param group: True if the functions is aggregate function
:type group: bool
:param *args: Arguments to pass to function_name"""
def __init__(self, function_name, group=False, *args):
self._function = function_name
self._group = group
self._args = args
def __init__(self, *args, **kwargs):

self._function = args[0]
self._group = kwargs.get('group', False)
self._args = args[1:]

@property
def function(self):
Expand Down Expand Up @@ -74,7 +75,7 @@ def eval_identifier(row, identifier):
pos = columns.index(Column(identifier_strip))
return identifier_strip, data[pos]
except ValueError:
raise OperationalError('Unknown identifier %s', identifier_strip)
raise OperationalError('Unknown identifier %s' % identifier_strip)


def eval_string(value):
Expand Down
51 changes: 32 additions & 19 deletions etcdb/execute/dml/select.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"""Implement SELECT query."""
import json

from etcdb import OperationalError
import time

from pyetcd import EtcdException

from etcdb import OperationalError, InternalError
from etcdb.eval_expr import eval_expr, EtcdbFunction
from etcdb.execute.dml.insert import get_table_columns
from etcdb.log import LOG
Expand Down Expand Up @@ -59,8 +63,7 @@ def prepare_columns(tree):
return columns


def get_row_by_primary_key(etcd_client, db, table, primary_key, # pylint: disable=too-many-arguments
wait=False, wait_index=None):
def get_row_by_primary_key(etcd_client, db, table, primary_key, **kwargs):
"""
Read row from etcd by its primary key value.
Expand All @@ -69,25 +72,35 @@ def get_row_by_primary_key(etcd_client, db, table, primary_key, # pylint: disab
:param db:
:param table:
:param primary_key: Primary key value.
:param wait: If True it will wait for a change in the key
:type wait: bool
:param wait_index: When waiting you can specify index to wait for.
:type wait_index: int
:param kwargs: See below.
:return: Row
:rtype: Row
:Keyword Arguments:
* **wait** (bool) - If True it will wait for a change in the key.
* **wait_index** (int) - When waiting you can specify index to wait for.
"""
key = "/{db}/{tbl}/{pk}".format(db=db,
tbl=table,
pk=primary_key)
kwargs = {}
if wait:
kwargs['wait'] = True
if wait_index:
kwargs['waitIndex'] = wait_index
if kwargs:
etcd_response = etcd_client.read(key, **kwargs)
else:
etcd_response = etcd_client.read(key)
key = "/{db}/{tbl}/{pk}".format(
db=db,
tbl=table,
pk=primary_key
)
client_kwargs = {}
if 'wait' in kwargs:
client_kwargs['wait'] = kwargs.get('wait')
if 'wait_index' in kwargs:
client_kwargs['waitIndex'] = kwargs.get('wait_index')
etcd_response = None
for i in xrange(30):
try:
etcd_response = etcd_client.read(key, **client_kwargs)
break
except EtcdException as err:
LOG.warning("Retry #%d after error: %s", i, err)
time.sleep(1)
if not etcd_response:
raise InternalError('Failed to get response from etcd')

row = ()
field_values = json.loads(etcd_response.node['value'])
table_columns = get_table_columns(etcd_client, db, table)
Expand Down
2 changes: 1 addition & 1 deletion etcdb/resultset.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def next(self):
self._column_position = 0
raise StopIteration()

def __getitem__(self, key):
def __getitem__(self, key): # pylint: disable=inconsistent-return-statements
if isinstance(key, int):
return self._columns[key]
else:
Expand Down
265 changes: 133 additions & 132 deletions etcdb/sqlparser/parsetab.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ pytest-cov
Sphinx
psutil
pytest-timeout
pytest-cov
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.5.12
current_version = 1.5.13
commit = True
tag = False

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

setup(
name='etcdb',
version='1.5.12',
version='1.5.13',
description="PEP 249 compatible driver for Etcd",
long_description=readme + '\n\n' + history,
author="Box TechOps Database Team",
Expand Down
2 changes: 1 addition & 1 deletion support/run_func_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

source /etcdb/support/bootstrap.sh

make -C /etcdb bootstrap test-functional
make -C /etcdb clean bootstrap test-functional

0 comments on commit dbc8a35

Please sign in to comment.