scylla-cqlsh 6.0.29__cp310-cp310-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,333 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # code for dealing with CQL's syntax, rules, interpretation
18
+ # i.e., stuff that's not necessarily cqlsh-specific
19
+
20
+ import traceback
21
+
22
+ import cassandra
23
+ from cqlshlib import pylexotron, util
24
+
25
+ Hint = pylexotron.Hint
26
+
27
+ cql_keywords_reserved = {'add', 'allow', 'alter', 'and', 'apply', 'asc', 'authorize', 'batch', 'begin', 'by',
28
+ 'columnfamily', 'create', 'delete', 'desc', 'describe', 'drop', 'entries', 'execute', 'from',
29
+ 'full', 'grant', 'if', 'in', 'index', 'infinity', 'insert', 'into', 'is', 'keyspace', 'limit',
30
+ 'materialized', 'modify', 'nan', 'norecursive', 'not', 'null', 'of', 'on', 'or', 'order',
31
+ 'primary', 'rename', 'revoke', 'schema', 'select', 'set', 'table', 'to', 'token', 'truncate',
32
+ 'unlogged', 'update', 'use', 'using', 'view', 'where', 'with'}
33
+ """
34
+ Set of reserved keywords in CQL.
35
+
36
+ Derived from .../cassandra/src/java/org/apache/cassandra/cql3/ReservedKeywords.java
37
+ """
38
+
39
+
40
+ class CqlParsingRuleSet(pylexotron.ParsingRuleSet):
41
+
42
+ available_compression_classes = (
43
+ 'DeflateCompressor',
44
+ 'SnappyCompressor',
45
+ 'LZ4Compressor',
46
+ 'ZstdCompressor',
47
+ )
48
+
49
+ available_compaction_classes = (
50
+ 'LeveledCompactionStrategy',
51
+ 'SizeTieredCompactionStrategy',
52
+ 'DateTieredCompactionStrategy',
53
+ 'TimeWindowCompactionStrategy'
54
+ )
55
+
56
+ replication_strategies = (
57
+ 'SimpleStrategy',
58
+ 'NetworkTopologyStrategy'
59
+ )
60
+
61
+ def __init__(self, *args, **kwargs):
62
+ pylexotron.ParsingRuleSet.__init__(self)
63
+
64
+ # note: commands_end_with_newline may be extended by callers.
65
+ self.commands_end_with_newline = set()
66
+ self.set_reserved_keywords()
67
+
68
+ def set_reserved_keywords(self):
69
+ """
70
+ We cannot let reserved cql keywords be simple 'identifier' since this caused
71
+ problems with completion, see CASSANDRA-10415
72
+ """
73
+ cassandra.metadata.cql_keywords_reserved = cql_keywords_reserved
74
+ syntax = '<reserved_identifier> ::= /(' + '|'.join(r'\b{}\b'.format(k) for k in cql_keywords_reserved) + ')/ ;'
75
+ self.append_rules(syntax)
76
+
77
+ def completer_for(self, rulename, symname):
78
+ def registrator(f):
79
+ def completerwrapper(ctxt):
80
+ cass = ctxt.get_binding('cassandra_conn', None)
81
+ if cass is None:
82
+ return ()
83
+ return f(ctxt, cass)
84
+ completerwrapper.__name__ = 'completerwrapper_on_' + f.__name__
85
+ self.register_completer(completerwrapper, rulename, symname)
86
+ return completerwrapper
87
+ return registrator
88
+
89
+ def explain_completion(self, rulename, symname, explanation=None):
90
+ if explanation is None:
91
+ explanation = '<%s>' % (symname,)
92
+
93
+ @self.completer_for(rulename, symname)
94
+ def explainer(ctxt, cass):
95
+ return [Hint(explanation)]
96
+
97
+ return explainer
98
+
99
+ def cql_massage_tokens(self, toklist):
100
+ curstmt = []
101
+ output = []
102
+
103
+ term_on_nl = False
104
+
105
+ for t in toklist:
106
+ if t[0] == 'endline':
107
+ if term_on_nl:
108
+ t = ('endtoken',) + t[1:]
109
+ else:
110
+ # don't put any 'endline' tokens in output
111
+ continue
112
+
113
+ curstmt.append(t)
114
+ if t[0] == 'endtoken':
115
+ term_on_nl = False
116
+ output.extend(curstmt)
117
+ curstmt = []
118
+ else:
119
+ if len(curstmt) == 1:
120
+ # first token in statement; command word
121
+ cmd = t[1].lower()
122
+ term_on_nl = bool(cmd in self.commands_end_with_newline)
123
+
124
+ output.extend(curstmt)
125
+ return output
126
+
127
+ def cql_parse(self, text, startsymbol='Start'):
128
+ tokens = self.lex(text)
129
+ tokens = self.cql_massage_tokens(tokens)
130
+ return self.parse(startsymbol, tokens, init_bindings={'*SRC*': text})
131
+
132
+ def cql_whole_parse_tokens(self, toklist, srcstr=None, startsymbol='Start'):
133
+ return self.whole_match(startsymbol, toklist, srcstr=srcstr)
134
+
135
+ def cql_split_statements(self, text):
136
+ tokens = self.lex(text)
137
+ tokens = self.cql_massage_tokens(tokens)
138
+ stmts = util.split_list(tokens, lambda t: t[0] == 'endtoken')
139
+ output = []
140
+ in_batch = False
141
+ in_pg_string = len([st for st in tokens if len(st) > 0 and st[0] == 'unclosedPgString']) == 1
142
+ for stmt in stmts:
143
+ if in_batch:
144
+ output[-1].extend(stmt)
145
+ else:
146
+ output.append(stmt)
147
+ if len(stmt) > 2:
148
+ if stmt[-3][1].upper() == 'APPLY':
149
+ in_batch = False
150
+ elif stmt[0][1].upper() == 'BEGIN':
151
+ in_batch = True
152
+ return output, in_batch or in_pg_string
153
+
154
+ def cql_complete_single(self, text, partial, init_bindings=None, ignore_case=True,
155
+ startsymbol='Start'):
156
+ tokens = (self.cql_split_statements(text)[0] or [[]])[-1]
157
+ bindings = {} if init_bindings is None else init_bindings.copy()
158
+
159
+ # handle some different completion scenarios- in particular, completing
160
+ # inside a string literal
161
+ prefix = None
162
+ dequoter = util.identity
163
+ lasttype = None
164
+ if tokens:
165
+ lasttype = tokens[-1][0]
166
+ if lasttype == 'unclosedString':
167
+ prefix = self.token_dequote(tokens[-1])
168
+ tokens = tokens[:-1]
169
+ partial = prefix + partial
170
+ dequoter = self.dequote_value
171
+ requoter = self.escape_value
172
+ elif lasttype == 'unclosedName':
173
+ prefix = self.token_dequote(tokens[-1])
174
+ tokens = tokens[:-1]
175
+ partial = prefix + partial
176
+ dequoter = self.dequote_name
177
+ requoter = self.escape_name
178
+ elif lasttype == 'unclosedComment':
179
+ return []
180
+ bindings['partial'] = partial
181
+ bindings['*LASTTYPE*'] = lasttype
182
+ bindings['*SRC*'] = text
183
+
184
+ # find completions for the position
185
+ completions = self.complete(startsymbol, tokens, bindings)
186
+
187
+ hints, strcompletes = util.list_bifilter(pylexotron.is_hint, completions)
188
+
189
+ # it's possible to get a newline token from completion; of course, we
190
+ # don't want to actually have that be a candidate, we just want to hint
191
+ if '\n' in strcompletes:
192
+ strcompletes.remove('\n')
193
+ if partial == '':
194
+ hints.append(Hint('<enter>'))
195
+
196
+ # find matches with the partial word under completion
197
+ if ignore_case:
198
+ partial = partial.lower()
199
+ f = lambda s: s and dequoter(s).lower().startswith(partial)
200
+ else:
201
+ f = lambda s: s and dequoter(s).startswith(partial)
202
+ candidates = list(filter(f, strcompletes))
203
+
204
+ if prefix is not None:
205
+ # dequote, re-escape, strip quotes: gets us the right quoted text
206
+ # for completion. the opening quote is already there on the command
207
+ # line and not part of the word under completion, and readline
208
+ # fills in the closing quote for us.
209
+ candidates = [requoter(dequoter(c))[len(prefix) + 1:-1] for c in candidates]
210
+
211
+ # the above process can result in an empty string; this doesn't help for
212
+ # completions
213
+ candidates = [_f for _f in candidates if _f]
214
+
215
+ # prefix a space when desirable for pleasant cql formatting
216
+ if tokens:
217
+ newcandidates = []
218
+ for c in candidates:
219
+ if self.want_space_between(tokens[-1], c) \
220
+ and prefix is None \
221
+ and not text[-1].isspace() \
222
+ and not c[0].isspace():
223
+ c = ' ' + c
224
+ newcandidates.append(c)
225
+ candidates = newcandidates
226
+
227
+ # append a space for single, complete identifiers
228
+ if len(candidates) == 1 and candidates[0][-1].isalnum() \
229
+ and lasttype != 'unclosedString' \
230
+ and lasttype != 'unclosedName':
231
+ candidates[0] += ' '
232
+ return candidates, hints
233
+
234
+ @staticmethod
235
+ def want_space_between(tok, following):
236
+ if following in (',', ')', ':'):
237
+ return False
238
+ if tok[0] == 'op' and tok[1] in (',', ')', '='):
239
+ return True
240
+ if tok[0] == 'stringLiteral' and following[0] != ';':
241
+ return True
242
+ if tok[0] == 'star' and following[0] != ')':
243
+ return True
244
+ if tok[0] == 'endtoken':
245
+ return True
246
+ if tok[1][-1].isalnum() and following[0] != ',':
247
+ return True
248
+ return False
249
+
250
+ def cql_complete(self, text, partial, cassandra_conn=None, ignore_case=True, debug=False,
251
+ startsymbol='Start'):
252
+ init_bindings = {'cassandra_conn': cassandra_conn}
253
+ if debug:
254
+ init_bindings['*DEBUG*'] = True
255
+ print("cql_complete(%r, partial=%r)" % (text, partial))
256
+
257
+ completions, hints = self.cql_complete_single(text, partial, init_bindings,
258
+ startsymbol=startsymbol)
259
+
260
+ if hints:
261
+ hints = [h.text for h in hints]
262
+ hints.append('')
263
+
264
+ if len(completions) == 1 and len(hints) == 0:
265
+ c = completions[0]
266
+ if debug:
267
+ print("** Got one completion: %r. Checking for further matches...\n" % (c,))
268
+ if not c.isspace():
269
+ new_c = self.cql_complete_multiple(text, c, init_bindings, startsymbol=startsymbol)
270
+ completions = [new_c]
271
+ if debug:
272
+ print("** New list of completions: %r" % (completions,))
273
+
274
+ return hints + completions
275
+
276
+ def cql_complete_multiple(self, text, first, init_bindings, startsymbol='Start'):
277
+ debug = init_bindings.get('*DEBUG*', False)
278
+ try:
279
+ completions, hints = self.cql_complete_single(text + first, '', init_bindings,
280
+ startsymbol=startsymbol)
281
+ except Exception:
282
+ if debug:
283
+ print("** completion expansion had a problem:")
284
+ traceback.print_exc()
285
+ return first
286
+ if hints:
287
+ if not first[-1].isspace():
288
+ first += ' '
289
+ if debug:
290
+ print("** completion expansion found hints: %r" % (hints,))
291
+ return first
292
+ if len(completions) == 1 and completions[0] != '':
293
+ if debug:
294
+ print("** Got another completion: %r." % (completions[0],))
295
+ if completions[0][0] in (',', ')', ':') and first[-1] == ' ':
296
+ first = first[:-1]
297
+ first += completions[0]
298
+ else:
299
+ common_prefix = util.find_common_prefix(completions)
300
+ if common_prefix == '':
301
+ return first
302
+ if common_prefix[0] in (',', ')', ':') and first[-1] == ' ':
303
+ first = first[:-1]
304
+ if debug:
305
+ print("** Got a partial completion: %r." % (common_prefix,))
306
+ return first + common_prefix
307
+ if debug:
308
+ print("** New total completion: %r. Checking for further matches...\n" % (first,))
309
+ return self.cql_complete_multiple(text, first, init_bindings, startsymbol=startsymbol)
310
+
311
+ @staticmethod
312
+ def cql_extract_orig(toklist, srcstr):
313
+ # low end of span for first token, to high end of span for last token
314
+ return srcstr[toklist[0][2][0]:toklist[-1][2][1]]
315
+
316
+ @staticmethod
317
+ def token_dequote(tok):
318
+ if tok[0] == 'unclosedName':
319
+ # strip one quote
320
+ return tok[1][1:].replace('""', '"')
321
+ if tok[0] == 'quotedStringLiteral':
322
+ # strip quotes
323
+ return tok[1][1:-1].replace("''", "'")
324
+ if tok[0] == 'unclosedString':
325
+ # strip one quote
326
+ return tok[1][1:].replace("''", "'")
327
+ if tok[0] == 'unclosedComment':
328
+ return ''
329
+ return tok[1]
330
+
331
+ @staticmethod
332
+ def token_is_word(tok):
333
+ return tok[0] == 'identifier'
@@ -0,0 +1,314 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ import os
18
+
19
+ from cqlshlib import cqlhandling
20
+
21
+ # we want the cql parser to understand our cqlsh-specific commands too
22
+ my_commands_ending_with_newline = (
23
+ 'help',
24
+ '?',
25
+ 'consistency',
26
+ 'serial',
27
+ 'describe',
28
+ 'desc',
29
+ 'show',
30
+ 'source',
31
+ 'capture',
32
+ 'login',
33
+ 'debug',
34
+ 'tracing',
35
+ 'expand',
36
+ 'paging',
37
+ 'exit',
38
+ 'quit',
39
+ 'clear',
40
+ 'cls'
41
+ )
42
+
43
+ cqlsh_syntax_completers = []
44
+
45
+
46
+ def cqlsh_syntax_completer(rulename, termname):
47
+ def registrator(f):
48
+ cqlsh_syntax_completers.append((rulename, termname, f))
49
+ return f
50
+
51
+ return registrator
52
+
53
+
54
+ cqlsh_cmd_syntax_rules = r'''
55
+ <cqlshCommand> ::= <CQL_Statement>
56
+ | <specialCommand> ( ";" | "\n" )
57
+ ;
58
+ '''
59
+
60
+ cqlsh_special_cmd_command_syntax_rules = r'''
61
+ <specialCommand> ::= <describeCommand>
62
+ | <consistencyCommand>
63
+ | <serialConsistencyCommand>
64
+ | <showCommand>
65
+ | <sourceCommand>
66
+ | <captureCommand>
67
+ | <copyCommand>
68
+ | <loginCommand>
69
+ | <debugCommand>
70
+ | <helpCommand>
71
+ | <tracingCommand>
72
+ | <expandCommand>
73
+ | <exitCommand>
74
+ | <pagingCommand>
75
+ | <clearCommand>
76
+ ;
77
+ '''
78
+
79
+ cqlsh_describe_cmd_syntax_rules = r'''
80
+ <describeCommand> ::= ( "DESCRIBE" | "DESC" )
81
+ ( ( "FUNCTIONS"
82
+ | "FUNCTION" udf=<anyFunctionName>
83
+ | "AGGREGATES"
84
+ | "AGGREGATE" uda=<userAggregateName>
85
+ | "KEYSPACES"
86
+ | "ONLY"? "KEYSPACE" ksname=<keyspaceName>?
87
+ | ( "COLUMNFAMILY" | "TABLE" ) cf=<columnFamilyName>
88
+ | "INDEX" idx=<indexName>
89
+ | "MATERIALIZED" "VIEW" mv=<materializedViewName>
90
+ | ( "COLUMNFAMILIES" | "TABLES" )
91
+ | "FULL"? "SCHEMA"
92
+ | "CLUSTER"
93
+ | "TYPES"
94
+ | "TYPE" ut=<userTypeName>
95
+ | (ksname=<keyspaceName> | cf=<columnFamilyName> | idx=<indexName> | mv=<materializedViewName>)
96
+ ) ("WITH" "INTERNALS")?
97
+ )
98
+ ;
99
+ '''
100
+
101
+ cqlsh_consistency_cmd_syntax_rules = r'''
102
+ <consistencyCommand> ::= "CONSISTENCY" ( level=<consistencyLevel> )?
103
+ ;
104
+ '''
105
+
106
+ cqlsh_consistency_level_syntax_rules = r'''
107
+ <consistencyLevel> ::= "ANY"
108
+ | "ONE"
109
+ | "TWO"
110
+ | "THREE"
111
+ | "QUORUM"
112
+ | "ALL"
113
+ | "LOCAL_QUORUM"
114
+ | "EACH_QUORUM"
115
+ | "SERIAL"
116
+ | "LOCAL_SERIAL"
117
+ | "LOCAL_ONE"
118
+ | "NODE_LOCAL"
119
+ ;
120
+ '''
121
+
122
+ cqlsh_serial_consistency_cmd_syntax_rules = r'''
123
+ <serialConsistencyCommand> ::= "SERIAL" "CONSISTENCY" ( level=<serialConsistencyLevel> )?
124
+ ;
125
+ '''
126
+
127
+ cqlsh_serial_consistency_level_syntax_rules = r'''
128
+ <serialConsistencyLevel> ::= "SERIAL"
129
+ | "LOCAL_SERIAL"
130
+ ;
131
+ '''
132
+
133
+ cqlsh_show_cmd_syntax_rules = r'''
134
+ <showCommand> ::= "SHOW" what=( "VERSION" | "HOST" | "SESSION" sessionid=<uuid> | "REPLICAS" token=<integer> (keyspace=<keyspaceName>)? )
135
+ ;
136
+ '''
137
+
138
+ cqlsh_source_cmd_syntax_rules = r'''
139
+ <sourceCommand> ::= "SOURCE" fname=<stringLiteral>
140
+ ;
141
+ '''
142
+
143
+ cqlsh_capture_cmd_syntax_rules = r'''
144
+ <captureCommand> ::= "CAPTURE" ( fname=( <stringLiteral> | "OFF" ) )?
145
+ ;
146
+ '''
147
+
148
+ cqlsh_copy_cmd_syntax_rules = r'''
149
+ <copyCommand> ::= "COPY" cf=<columnFamilyName>
150
+ ( "(" [colnames]=<colname> ( "," [colnames]=<colname> )* ")" )?
151
+ ( dir="FROM" ( fname=<stringLiteral> | "STDIN" )
152
+ | dir="TO" ( fname=<stringLiteral> | "STDOUT" ) )
153
+ ( "WITH" <copyOption> ( "AND" <copyOption> )* )?
154
+ ;
155
+ '''
156
+
157
+ cqlsh_copy_option_syntax_rules = r'''
158
+ <copyOption> ::= [optnames]=(<identifier>|<reserved_identifier>) "=" [optvals]=<copyOptionVal>
159
+ ;
160
+ '''
161
+
162
+ cqlsh_copy_option_val_syntax_rules = r'''
163
+ <copyOptionVal> ::= <identifier>
164
+ | <reserved_identifier>
165
+ | <term>
166
+ ;
167
+ '''
168
+
169
+ cqlsh_debug_cmd_syntax_rules = r'''
170
+ # avoiding just "DEBUG" so that this rule doesn't get treated as a terminal
171
+ <debugCommand> ::= "DEBUG" "THINGS"?
172
+ ;
173
+ '''
174
+
175
+ cqlsh_help_cmd_syntax_rules = r'''
176
+ <helpCommand> ::= ( "HELP" | "?" ) [topic]=( /[a-z_]*/ )*
177
+ ;
178
+ '''
179
+
180
+ cqlsh_tracing_cmd_syntax_rules = r'''
181
+ <tracingCommand> ::= "TRACING" ( switch=( "ON" | "OFF" ) )?
182
+ ;
183
+ '''
184
+
185
+ cqlsh_expand_cmd_syntax_rules = r'''
186
+ <expandCommand> ::= "EXPAND" ( switch=( "ON" | "OFF" ) )?
187
+ ;
188
+ '''
189
+
190
+ cqlsh_paging_cmd_syntax_rules = r'''
191
+ <pagingCommand> ::= "PAGING" ( switch=( "ON" | "OFF" | /[0-9]+/) )?
192
+ ;
193
+ '''
194
+
195
+ cqlsh_login_cmd_syntax_rules = r'''
196
+ <loginCommand> ::= "LOGIN" username=<username> (password=<stringLiteral>)?
197
+ ;
198
+ '''
199
+
200
+ cqlsh_exit_cmd_syntax_rules = r'''
201
+ <exitCommand> ::= "exit" | "quit"
202
+ ;
203
+ '''
204
+
205
+ cqlsh_clear_cmd_syntax_rules = r'''
206
+ <clearCommand> ::= "CLEAR" | "CLS"
207
+ ;
208
+ '''
209
+
210
+ cqlsh_question_mark = r'''
211
+ <qmark> ::= "?" ;
212
+ '''
213
+
214
+ cqlsh_extra_syntax_rules = cqlsh_cmd_syntax_rules + \
215
+ cqlsh_special_cmd_command_syntax_rules + \
216
+ cqlsh_describe_cmd_syntax_rules + \
217
+ cqlsh_consistency_cmd_syntax_rules + \
218
+ cqlsh_consistency_level_syntax_rules + \
219
+ cqlsh_serial_consistency_cmd_syntax_rules + \
220
+ cqlsh_serial_consistency_level_syntax_rules + \
221
+ cqlsh_show_cmd_syntax_rules + \
222
+ cqlsh_source_cmd_syntax_rules + \
223
+ cqlsh_capture_cmd_syntax_rules + \
224
+ cqlsh_copy_cmd_syntax_rules + \
225
+ cqlsh_copy_option_syntax_rules + \
226
+ cqlsh_copy_option_val_syntax_rules + \
227
+ cqlsh_debug_cmd_syntax_rules + \
228
+ cqlsh_help_cmd_syntax_rules + \
229
+ cqlsh_tracing_cmd_syntax_rules + \
230
+ cqlsh_expand_cmd_syntax_rules + \
231
+ cqlsh_paging_cmd_syntax_rules + \
232
+ cqlsh_login_cmd_syntax_rules + \
233
+ cqlsh_exit_cmd_syntax_rules + \
234
+ cqlsh_clear_cmd_syntax_rules + \
235
+ cqlsh_question_mark
236
+
237
+
238
+ def complete_source_quoted_filename(ctxt, cqlsh):
239
+ partial_path = ctxt.get_binding('partial', '')
240
+ head, tail = os.path.split(partial_path)
241
+ exhead = os.path.expanduser(head)
242
+ try:
243
+ contents = os.listdir(exhead or '.')
244
+ except OSError:
245
+ return ()
246
+ matches = [f for f in contents if f.startswith(tail)]
247
+ annotated = []
248
+ for f in matches:
249
+ match = os.path.join(head, f)
250
+ if os.path.isdir(os.path.join(exhead, f)):
251
+ match += '/'
252
+ annotated.append(match)
253
+ return annotated
254
+
255
+
256
+ cqlsh_syntax_completer('sourceCommand', 'fname')(complete_source_quoted_filename)
257
+ cqlsh_syntax_completer('captureCommand', 'fname')(complete_source_quoted_filename)
258
+
259
+
260
+ @cqlsh_syntax_completer('copyCommand', 'fname')
261
+ def copy_fname_completer(ctxt, cqlsh):
262
+ lasttype = ctxt.get_binding('*LASTTYPE*')
263
+ if lasttype == 'unclosedString':
264
+ return complete_source_quoted_filename(ctxt, cqlsh)
265
+ partial_path = ctxt.get_binding('partial')
266
+ if partial_path == '':
267
+ return ["'"]
268
+ return ()
269
+
270
+
271
+ @cqlsh_syntax_completer('copyCommand', 'colnames')
272
+ def complete_copy_column_names(ctxt, cqlsh):
273
+ existcols = list(map(cqlsh.cql_unprotect_name, ctxt.get_binding('colnames', ())))
274
+ ks = cqlsh.cql_unprotect_name(ctxt.get_binding('ksname', None))
275
+ cf = cqlsh.cql_unprotect_name(ctxt.get_binding('cfname'))
276
+ colnames = cqlsh.get_column_names(ks, cf)
277
+ if len(existcols) == 0:
278
+ return [colnames[0]]
279
+ return set(colnames[1:]) - set(existcols)
280
+
281
+
282
+ COPY_COMMON_OPTIONS = ['DELIMITER', 'QUOTE', 'ESCAPE', 'HEADER', 'NULL', 'DATETIMEFORMAT',
283
+ 'MAXATTEMPTS', 'REPORTFREQUENCY', 'DECIMALSEP', 'THOUSANDSSEP', 'BOOLSTYLE',
284
+ 'NUMPROCESSES', 'CONFIGFILE', 'RATEFILE']
285
+ COPY_FROM_OPTIONS = ['CHUNKSIZE', 'INGESTRATE', 'MAXBATCHSIZE', 'MINBATCHSIZE', 'MAXROWS',
286
+ 'SKIPROWS', 'SKIPCOLS', 'MAXPARSEERRORS', 'MAXINSERTERRORS', 'ERRFILE', 'PREPAREDSTATEMENTS',
287
+ 'TTL']
288
+ COPY_TO_OPTIONS = ['ENCODING', 'PAGESIZE', 'PAGETIMEOUT', 'BEGINTOKEN', 'ENDTOKEN', 'MAXOUTPUTSIZE', 'MAXREQUESTS',
289
+ 'FLOATPRECISION', 'DOUBLEPRECISION']
290
+
291
+
292
+ @cqlsh_syntax_completer('copyOption', 'optnames')
293
+ def complete_copy_options(ctxt, cqlsh):
294
+ optnames = list(map(str.upper, ctxt.get_binding('optnames', ())))
295
+ direction = ctxt.get_binding('dir').upper()
296
+ if direction == 'FROM':
297
+ opts = set(COPY_COMMON_OPTIONS + COPY_FROM_OPTIONS) - set(optnames)
298
+ elif direction == 'TO':
299
+ opts = set(COPY_COMMON_OPTIONS + COPY_TO_OPTIONS) - set(optnames)
300
+ return opts
301
+
302
+
303
+ @cqlsh_syntax_completer('copyOption', 'optvals')
304
+ def complete_copy_opt_values(ctxt, cqlsh):
305
+ optnames = ctxt.get_binding('optnames', ())
306
+ lastopt = optnames[-1].lower()
307
+ if lastopt == 'header':
308
+ return ['true', 'false']
309
+ return [cqlhandling.Hint('<single_character_string>')]
310
+
311
+
312
+ @cqlsh_syntax_completer('helpCommand', 'topic')
313
+ def complete_help(ctxt, cqlsh):
314
+ return sorted([t.upper() for t in cqlsh.cqldocs.get_help_topics() + cqlsh.get_help_topics()])