Merge branch 'cassandra-2.2' into cassandra-3.0

This commit is contained in:
Jason Brown 2018-01-15 06:01:38 -08:00
commit 685dde10e3
8 changed files with 50 additions and 7 deletions

View File

@ -25,7 +25,8 @@ Merged from 2.2:
* Fix the inspectJvmOptions startup check (CASSANDRA-14112)
* Fix race that prevents submitting compaction for a table when executor is full (CASSANDRA-13801)
* Rely on the JVM to handle OutOfMemoryErrors (CASSANDRA-13006)
* Grab refs during scrub/index redistribution/cleanup (CASSANDRA-13873)
Merged from 2.1:
* More PEP8 compliance for cqlsh (CASSANDRA-14021)
3.0.15

View File

@ -123,6 +123,7 @@ def find_zip(libprefix):
if zips:
return max(zips) # probably the highest version, if multiple
cql_zip = find_zip(CQL_LIB_PREFIX)
if cql_zip:
ver = os.path.splitext(os.path.basename(cql_zip))[0][len(CQL_LIB_PREFIX):]
@ -591,6 +592,8 @@ def show_warning_without_quoting_line(message, category, filename, lineno, file=
file.write(warnings.formatwarning(message, category, filename, lineno, line=''))
except IOError:
pass
warnings.showwarning = show_warning_without_quoting_line
warnings.filterwarnings('always', category=cql3handling.UnexpectedTableStructure)
@ -2612,12 +2615,12 @@ def main(options, hostname, port):
if options.timezone:
try:
timezone = pytz.timezone(options.timezone)
except:
except Exception:
sys.stderr.write("Warning: could not recognize timezone '%s' specified in cqlshrc\n\n" % (options.timezone))
if 'TZ' in os.environ:
try:
timezone = pytz.timezone(os.environ['TZ'])
except:
except Exception:
sys.stderr.write("Warning: could not recognize timezone '%s' from environment value TZ\n\n" % (os.environ['TZ']))
except ImportError:
sys.stderr.write("Warning: Timezone defined and 'pytz' module for timezone conversion not installed. Timestamps will be displayed in UTC timezone.\n\n")
@ -2673,6 +2676,7 @@ def main(options, hostname, port):
if batch_mode and shell.statement_error:
sys.exit(2)
# always call this regardless of module name: when a sub-process is spawned
# on Windows then the module name is not __main__, see CASSANDRA-9304
insert_driver_hooks()

View File

@ -168,7 +168,7 @@ class SendingChannels(object):
for ch in self.channels:
try:
ch.close()
except:
except Exception:
pass
@ -222,7 +222,7 @@ class ReceivingChannels(object):
for ch in self.channels:
try:
ch.close()
except:
except Exception:
pass
@ -2122,8 +2122,8 @@ class ImportConversion(object):
pk_values = []
for i in partition_key_indexes:
val = serialize(i, row[i])
l = len(val)
pk_values.append(struct.pack(">H%dsB" % l, l, val, 0))
length = len(val)
pk_values.append(struct.pack(">H%dsB" % length, length, val, 0))
return b"".join(pk_values)
if len(partition_key_indexes) == 1:

View File

@ -34,6 +34,7 @@ class UnexpectedTableStructure(UserWarning):
def __str__(self):
return 'Unexpected table structure; may not translate correctly to CQL. ' + self.msg
SYSTEM_KEYSPACES = ('system', 'system_schema', 'system_traces', 'system_auth', 'system_distributed')
NONALTERBALE_KEYSPACES = ('system', 'system_schema')
@ -115,6 +116,7 @@ class Cql3ParsingRuleSet(CqlParsingRuleSet):
cqlword = cqlword[1:-1].replace("''", "'")
return cqlword
CqlRuleSet = Cql3ParsingRuleSet()
# convenience for remainder of module
@ -348,6 +350,7 @@ def prop_equals_completer(ctxt, cass):
return ()
return ['=']
completer_for('property', 'propeq')(prop_equals_completer)
@ -579,6 +582,7 @@ def ks_name_completer(ctxt, cass):
def cf_ks_name_completer(ctxt, cass):
return [maybe_escape_name(ks) + '.' for ks in cass.get_keyspace_names()]
completer_for('columnFamilyName', 'ksname')(cf_ks_name_completer)
completer_for('materializedViewName', 'ksname')(cf_ks_name_completer)
@ -589,6 +593,7 @@ def cf_ks_dot_completer(ctxt, cass):
return ['.']
return []
completer_for('columnFamilyName', 'dot')(cf_ks_dot_completer)
completer_for('materializedViewName', 'dot')(cf_ks_dot_completer)
@ -620,6 +625,7 @@ def mv_name_completer(ctxt, cass):
raise
return map(maybe_escape_name, mvnames)
completer_for('userTypeName', 'ksname')(cf_ks_name_completer)
completer_for('userTypeName', 'dot')(cf_ks_dot_completer)
@ -672,6 +678,7 @@ def working_on_keyspace(ctxt):
return True
return False
syntax_rules += r'''
<useStatement> ::= "USE" <keyspaceName>
;
@ -816,6 +823,7 @@ def select_relation_lhs_completer(ctxt, cass):
filterable.add(idx.index_options["target"])
return map(maybe_escape_name, filterable)
explain_completion('selector', 'colname')
syntax_rules += r'''
@ -891,6 +899,7 @@ def insert_option_completer(ctxt, cass):
opts.discard(opt.split()[0])
return opts
syntax_rules += r'''
<updateStatement> ::= "UPDATE" cf=<columnFamilyName>
( "USING" [updateopt]=<usingOption>
@ -983,6 +992,7 @@ def update_indexbracket_completer(ctxt, cass):
return ['[']
return []
syntax_rules += r'''
<deleteStatement> ::= "DELETE" ( <deleteSelector> ( "," <deleteSelector> )* )?
"FROM" cf=<columnFamilyName>
@ -1010,6 +1020,7 @@ def delete_delcol_completer(ctxt, cass):
layout = get_table_meta(ctxt, cass)
return map(maybe_escape_name, regular_column_names(layout))
syntax_rules += r'''
<batchStatement> ::= "BEGIN" ( "UNLOGGED" | "COUNTER" )? "BATCH"
( "USING" [batchopt]=<usingOption>
@ -1032,6 +1043,7 @@ def batch_opt_completer(ctxt, cass):
opts.discard(opt.split()[0])
return opts
syntax_rules += r'''
<truncateStatement> ::= "TRUNCATE" ("COLUMNFAMILY" | "TABLE")? cf=<columnFamilyName>
;
@ -1051,6 +1063,7 @@ def create_ks_wat_completer(ctxt, cass):
return ['KEYSPACE']
return ['KEYSPACE', 'SCHEMA']
syntax_rules += r'''
<createColumnFamilyStatement> ::= "CREATE" wat=( "COLUMNFAMILY" | "TABLE" ) ("IF" "NOT" "EXISTS")?
( ks=<nonSystemKeyspaceName> dot="." )? cf=<cfOrKsName>
@ -1099,6 +1112,7 @@ def create_cf_wat_completer(ctxt, cass):
return ['TABLE']
return ['TABLE', 'COLUMNFAMILY']
explain_completion('createColumnFamilyStatement', 'cf', '<new_table_name>')
explain_completion('compositeKeyCfSpec', 'newcolname', '<new_column_name>')
@ -1153,6 +1167,7 @@ def create_cf_composite_primary_key_comma_completer(ctxt, cass):
return ()
return [',']
syntax_rules += r'''
<idxName> ::= <identifier>
@ -1216,6 +1231,7 @@ def create_index_col_completer(ctxt, cass):
colnames = [cd.name for cd in layout.columns.values() if cd.name not in idx_targets]
return map(maybe_escape_name, colnames)
syntax_rules += r'''
<dropKeyspaceStatement> ::= "DROP" "KEYSPACE" ("IF" "EXISTS")? ksname=<nonSystemKeyspaceName>
;
@ -1273,6 +1289,7 @@ def idx_ks_idx_name_completer(ctxt, cass):
raise
return map(maybe_escape_name, idxnames)
syntax_rules += r'''
<alterTableStatement> ::= "ALTER" wat=( "COLUMNFAMILY" | "TABLE" ) cf=<columnFamilyName>
<alterInstructions>
@ -1307,6 +1324,7 @@ def alter_type_field_completer(ctxt, cass):
fields = [tuple[0] for tuple in layout]
return map(maybe_escape_name, fields)
explain_completion('alterInstructions', 'newcol', '<new_column_name>')
explain_completion('alterTypeInstructions', 'newcol', '<new_field_name>')
@ -1450,6 +1468,7 @@ def rolename_completer(ctxt, cass):
session = cass.session
return [maybe_quote(row[0].replace("'", "''")) for row in session.execute("LIST ROLES")]
syntax_rules += r'''
<createTriggerStatement> ::= "CREATE" "TRIGGER" ( "IF" "NOT" "EXISTS" )? <cident>
"ON" cf=<columnFamilyName> "USING" class=<stringLiteral>
@ -1473,6 +1492,7 @@ def alter_type_field_completer(ctxt, cass):
names = get_trigger_names(ctxt, cass)
return map(maybe_escape_name, names)
# END SYNTAX/COMPLETION RULE DEFINITIONS
CqlRuleSet.append_rules(syntax_rules)

View File

@ -99,6 +99,7 @@ class FormattedValue:
"""
return self.coloredval + self._pad(width, fill)
DEFAULT_VALUE_COLORS = dict(
default=YELLOW,
text=YELLOW,

View File

@ -42,6 +42,7 @@ def _show_control_chars(match):
txt = txt[1:-1]
return txt
bits_to_turn_red_re = re.compile(r'\\([^uUx]|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2}|U[0-9a-fA-F]{8})')
@ -53,6 +54,7 @@ def _make_turn_bits_red_f(color1, color2):
return color1 + txt + color2
return _turn_bits_red
default_null_placeholder = 'null'
default_float_precision = 3
default_colormap = DEFAULT_VALUE_COLORS
@ -97,6 +99,7 @@ def color_text(bval, colormap, displaywidth=None):
displaywidth -= bval.count(r'\\')
return FormattedValue(bval, coloredval, displaywidth)
DEFAULT_NANOTIME_FORMAT = '%H:%M:%S.%N'
DEFAULT_DATE_FORMAT = '%Y-%m-%d'
DEFAULT_TIMESTAMP_FORMAT = '%Y-%m-%d %H:%M:%S%z'
@ -121,6 +124,7 @@ def format_value_default(val, colormap, **_):
bval = controlchars_re.sub(_show_control_chars, escapedval)
return bval if colormap is NO_COLOR_MAP else color_text(bval, colormap)
# Mapping cql type base names ("int", "map", etc) to formatter functions,
# making format_value a generic function
_formatters = {}
@ -148,6 +152,8 @@ def formatter_for(typname):
def format_value_blob(val, colormap, **_):
bval = '0x' + binascii.hexlify(val)
return colorme(bval, colormap, 'blob')
formatter_for('buffer')(format_value_blob)
@ -208,6 +214,7 @@ def format_floating_point_type(val, colormap, float_precision, decimal_sep=None,
return colorme(bval, colormap, 'float')
formatter_for('float')(format_floating_point_type)
@ -216,6 +223,7 @@ def format_integer_type(val, colormap, thousands_sep=None, **_):
bval = format_integer_with_thousands_sep(val, thousands_sep) if thousands_sep else str(val)
return colorme(bval, colormap, 'int')
# We can get rid of this in cassandra-2.2
if sys.version_info >= (2, 7):
def format_integer_with_thousands_sep(val, thousands_sep=','):
@ -279,6 +287,7 @@ def format_value_text(val, encoding, colormap, quote=False, **_):
return bval if colormap is NO_COLOR_MAP else color_text(bval, colormap, wcwidth.wcswidth(bval.decode(encoding)))
# name alias
formatter_for('unicode')(format_value_text)
@ -324,6 +333,8 @@ def format_value_set(val, encoding, colormap, date_time_format, float_precision,
return format_simple_collection(sorted(val), '{', '}', encoding, colormap,
date_time_format, float_precision, nullval,
decimal_sep, thousands_sep, boolean_styles)
formatter_for('frozenset')(format_value_set)
formatter_for('sortedset')(format_value_set)
formatter_for('SortedSet')(format_value_set)
@ -350,6 +361,8 @@ def format_value_map(val, encoding, colormap, date_time_format, float_precision,
+ rb
displaywidth = 4 * len(subs) + sum(k.displaywidth + v.displaywidth for (k, v) in subs)
return FormattedValue(bval, coloredval, displaywidth)
formatter_for('OrderedDict')(format_value_map)
formatter_for('OrderedMap')(format_value_map)
formatter_for('OrderedMapSerializedKey')(format_value_map)

View File

@ -518,6 +518,7 @@ class ParsingRuleSet:
pattern.match(ctxt, completions)
return completions
import sys

View File

@ -94,6 +94,7 @@ def bisearch(ucs, table):
return 1
return 0
# The following two functions define the column width of an ISO 10646
# character as follows:
#
@ -178,6 +179,7 @@ combining = (
(0xE0100, 0xE01EF)
)
# sorted list of non-overlapping intervals of East Asian Ambiguous
# characters, generated by "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c"
ambiguous = (
@ -321,6 +323,7 @@ def wcwidth_cjk(c):
def wcswidth_cjk(s):
return mk_wcswidth_cjk(map(ord, s))
if __name__ == "__main__":
samples = (
('MUSIC SHARP SIGN', 1),