Merge branch 'cassandra-1.2' into trunk

Conflicts:
	bin/cqlsh
	pylib/cqlshlib/test/test_cqlsh_output.py
	pylib/cqlshlib/test/test_keyspace_init2.cql
This commit is contained in:
Aleksey Yeschenko 2013-06-27 01:01:18 +03:00
commit f89784339c
7 changed files with 44 additions and 15 deletions

View File

@ -70,6 +70,7 @@
1.2.7
* Fix serialization of the LEFT gossip value (CASSANDRA-5696)
* cqlsh: Don't show 'null' in place of empty values (CASSANDRA-5675)
1.2.6
* Fix tracing when operation completes before all responses arrive (CASSANDRA-5668)

View File

@ -528,6 +528,17 @@ class Shell(cmd.Cmd):
def myformat_colname(self, name, nametype):
return self.myformat_value(name, nametype, colormap=COLUMN_NAME_COLORS)
# cql/cursor.py:Cursor.decode_row() function, modified to not turn '' into None.
def decode_row(self, cursor, row):
values = []
bytevals = cursor.columnvalues(row)
for val, vtype, nameinfo in zip(bytevals, cursor.column_types, cursor.name_info):
if val == '':
values.append(val)
else:
values.append(cursor.decoder.decode_value(val, vtype, nameinfo[0]))
return values
def report_connection(self):
self.show_host()
self.show_version()
@ -941,7 +952,7 @@ class Shell(cmd.Cmd):
colnames = [d[0] for d in cursor.description]
colnames_t = [(name, self.get_nametype(cursor, n)) for (n, name) in enumerate(colnames)]
formatted_names = [self.myformat_colname(name, nametype) for (name, nametype) in colnames_t]
formatted_values = [map(self.myformat_value, row, cursor.column_types) for row in cursor]
formatted_values = [map(self.myformat_value, self.decode_row(cursor, row), cursor.column_types) for row in cursor.result]
if self.expand_enabled:
self.print_formatted_result_vertically(formatted_names, formatted_values)
else:
@ -1418,14 +1429,18 @@ class Shell(cmd.Cmd):
def do_import_row(self, columns, nullval, layout, row):
rowmap = {}
for name, value in zip(columns, row):
type = layout.get_column(name).cqltype
if issubclass(type, ReversedType):
type = type.subtypes[0]
cqltype = type.cql_parameterized_type()
if value != nullval:
type = layout.get_column(name).cqltype
if issubclass(type, ReversedType):
type = type.subtypes[0]
if type.cql_parameterized_type() in ('ascii', 'text', 'timestamp', 'inet'):
if cqltype in ('ascii', 'text', 'timestamp', 'inet'):
rowmap[name] = self.cql_protect_value(value)
else:
rowmap[name] = value
elif name in layout.column_aliases and not type.empty_binary_ok:
rowmap[name] = 'blobAs%s(0x)' % cqltype.title()
else:
rowmap[name] = 'null'
return self.do_import_insert(layout, rowmap)

View File

@ -93,7 +93,7 @@ DEFAULT_VALUE_COLORS = dict(
default=YELLOW,
text=YELLOW,
error=RED,
hex=DARK_MAGENTA,
blob=DARK_MAGENTA,
timestamp=GREEN,
int=GREEN,
float=GREEN,
@ -107,6 +107,6 @@ DEFAULT_VALUE_COLORS = dict(
COLUMN_NAME_COLORS = defaultdict(lambda: MAGENTA,
error=RED,
hex=DARK_MAGENTA,
blob=DARK_MAGENTA,
reset=ANSI_RESET,
)

View File

@ -79,7 +79,7 @@ def color_text(bval, colormap, displaywidth=None):
if displaywidth is None:
displaywidth = len(bval)
tbr = _make_turn_bits_red_f(colormap['hex'], colormap['text'])
tbr = _make_turn_bits_red_f(colormap['blob'], colormap['text'])
coloredval = colormap['text'] + bits_to_turn_red_re.sub(tbr, bval) + colormap['reset']
if colormap['text']:
displaywidth -= bval.count(r'\\')
@ -96,6 +96,8 @@ def format_value_default(val, colormap, **_):
_formatters = {}
def format_value(cqltype, val, **kwargs):
if val == '' and not cqltype.empty_binary_ok:
return format_value_default(val, **kwargs)
formatter = _formatters.get(cqltype.typename, format_value_default)
return formatter(val, subtypes=cqltype.subtypes, **kwargs)
@ -108,7 +110,7 @@ def formatter_for(typname):
@formatter_for('blob')
def format_value_blob(val, colormap, **_):
bval = '0x' + ''.join('%02x' % ord(c) for c in val)
return colorme(bval, colormap, 'hex')
return colorme(bval, colormap, 'blob')
def format_python_formatted_type(val, colormap, color):
bval = str(val)

View File

@ -125,7 +125,7 @@ class TestCqlshCompletion(CqlshCompletionCase):
pass
def test_complete_in_create_keyspace(self):
self.trycompletions('create keyspace ', '', choices=('<identifier>', '<quotedName>'))
self.trycompletions('create keyspace ', '', choices=('<identifier>', '<quotedName>', 'IF'))
self.trycompletions('create keyspace moo ',
"WITH replication = {'class': '")
self.trycompletions('create keyspace "12SomeName" with ',

View File

@ -141,7 +141,7 @@ class TestCqlshOutput(BaseTestCase):
MMMMM
-------
4
5
G
@ -301,7 +301,7 @@ class TestCqlshOutput(BaseTestCase):
self.assertCqlverQueriesGiveColoredOutput((
('''select intcol, bigintcol, varintcol \
from has_all_types \
where num in (0, 1, 2, 3);''', """
where num in (0, 1, 2, 3, 4);''', """
intcol | bigintcol | varintcol
MMMMMM MMMMMMMMM MMMMMMMMM
-------------+----------------------+-----------------------------
@ -314,15 +314,17 @@ class TestCqlshOutput(BaseTestCase):
GGGGGGGGGGG GGGGGGGGGGGGGGGGGGGG GGGGGGGGGGGGGGGGGGGGGGGGGGG
-2147483648 | -9223372036854775808 | -10000000000000000000000000
GGGGGGGGGGG GGGGGGGGGGGGGGGGGGGG GGGGGGGGGGGGGGGGGGGGGGGGGGG
| |
nnnnnnnnnnn nnnnnnnnnnnnnnnnnnnn nnnnnnnnnnnnnnnnnnnnnnnnnnn
(4 rows)
(5 rows)
nnnnnnnn
"""),
('''select decimalcol, doublecol, floatcol \
from has_all_types \
where num in (0, 1, 2, 3);''', """
where num in (0, 1, 2, 3, 4);''', """
decimalcol | doublecol | floatcol
MMMMMMMMMM MMMMMMMMM MMMMMMMM
------------------+-----------+----------
@ -335,9 +337,11 @@ class TestCqlshOutput(BaseTestCase):
GGGGGGGGGGGGGGGG GGGGGGG GGGGG
10.0000000000000 | -1004.1 | 1e+08
GGGGGGGGGGGGGGGG GGGGGGG GGGGG
| |
nnnnnnnnnnnnnnnn nnnnnnn nnnnn
(4 rows)
(5 rows)
nnnnnnnn
"""),
), cqlver=3)
@ -654,6 +658,7 @@ class TestCqlshOutput(BaseTestCase):
comment='' AND
dclocal_read_repair_chance=0.000000 AND
gc_grace_seconds=864000 AND
index_interval=128 AND
read_repair_chance=0.100000 AND
replicate_on_write='true' AND
populate_io_cache_on_flush='false' AND

View File

@ -44,6 +44,12 @@ VALUES (3, -2147483648, '''''''', -9223372036854775808, 0x80, false,
10.0000000000000, -1004.10, 100000000.9, '龍馭鬱', '2038-01-19T03:14-1200',
ffffffff-ffff-1fff-8fff-ffffffffffff, '''', -10000000000000000000000000);
INSERT INTO has_all_types (num, intcol, asciicol, bigintcol, blobcol, booleancol,
decimalcol, doublecol, floatcol, textcol,
timestampcol, uuidcol, varcharcol, varintcol)
VALUES (4, blobAsInt(0x), '', blobAsBigint(0x), 0x, blobAsBoolean(0x), blobAsDecimal(0x),
blobAsDouble(0x), blobAsFloat(0x), '', blobAsTimestamp(0x), blobAsUuid(0x), '',
blobAsVarint(0x));
CREATE TABLE has_value_encoding_errors (