kaqing 2.0.100__py3-none-any.whl → 2.0.101__py3-none-any.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.

Potentially problematic release.


This version of kaqing might be problematic. Click here for more details.

@@ -62,8 +62,9 @@ class Audit(Command):
62
62
  columns=lambda table: audit_column_names(),
63
63
  partition_columns=lambda table: audit_column_names(partition_cols_only=True),
64
64
  variant='athena'
65
- ) | {
66
- 'desc': {table: None for table in audit_table_names()}}
65
+ )
66
+ # | {
67
+ # 'desc': {table: None for table in audit_table_names()}}
67
68
 
68
69
  return {}
69
70
 
@@ -0,0 +1,9 @@
1
+ from adam.sql.term_completer import TermCompleter
2
+ from adam.utils_athena import audit_table_names
3
+
4
+ class AuditTableNameCompleter(TermCompleter):
5
+ def __init__(self, ignore_case: bool = True):
6
+ super().__init__(audit_table_names(), ignore_case=ignore_case)
7
+
8
+ def __repr__(self) -> str:
9
+ return "AuditTableCompleter()"
@@ -7,6 +7,8 @@ from adam.commands.describe.describe_schema import DescribeSchema
7
7
  from adam.commands.describe.describe_table import DescribeTable
8
8
  from adam.commands.describe.describe_tables import DescribeTables
9
9
  from adam.repl_state import ReplState, RequiredState
10
+ from adam.utils import log2
11
+ from adam.utils_athena import run_audit_query
10
12
 
11
13
  class Describe(Command):
12
14
  COMMAND = 'describe'
@@ -31,15 +33,27 @@ class Describe(Command):
31
33
  if not(args := self.args(cmd)):
32
34
  return super().run(cmd, state)
33
35
 
36
+ if state.device == ReplState.L:
37
+ state, args = self.apply_state(args, state)
38
+ if not args:
39
+ if state.in_repl:
40
+ log2('Please enter table name')
41
+ else:
42
+ log2('* table name is missing.')
43
+ log2()
44
+ Command.display_help()
45
+ return state
46
+
47
+ run_audit_query(f'describe {args[0]}')
48
+
49
+ return state
50
+
34
51
  return super().intermediate_run(cmd, state, args, Describe.cmd_list())
35
52
 
36
53
  def cmd_list():
37
54
  return [DescribeKeyspace(), DescribeKeyspaces(), DescribeSchema(), DescribeTable(), DescribeTables()]
38
55
 
39
- def completion(self, state: ReplState):
40
- if state.sts:
41
- return super().completion(state)
42
-
56
+ def completion(self, _: ReplState):
43
57
  return {}
44
58
 
45
59
  class DescribeCommandHelper(click.Command):
@@ -1,5 +1,5 @@
1
1
  from adam.commands.command import Command
2
- from adam.commands.cql.cql_utils import keyspaces, run_cql
2
+ from adam.commands.cql.cql_utils import run_cql
3
3
  from adam.pod_exec_result import PodExecResult
4
4
  from adam.repl_state import ReplState, RequiredState
5
5
  from adam.utils import log2
@@ -50,9 +50,7 @@ class DescribeKeyspace(Command):
50
50
  # do not continue to cql route
51
51
  return state
52
52
 
53
- def completion(self, state: ReplState) -> dict[str, any]:
54
- if state.sts:
55
- return super().completion(state, {ks: {'&': None} for ks in keyspaces(state, on_any=True)})
53
+ def completion(self, _: ReplState) -> dict[str, any]:
56
54
 
57
55
  return {}
58
56
 
@@ -39,10 +39,7 @@ class DescribeKeyspaces(Command):
39
39
  # do not continue to cql route
40
40
  return state
41
41
 
42
- def completion(self, state: ReplState) -> dict[str, any]:
43
- if state.sts:
44
- return super().completion(state, {'&': None})
45
-
42
+ def completion(self, _: ReplState) -> dict[str, any]:
46
43
  return {}
47
44
 
48
45
  def help(self, _: ReplState) -> str:
@@ -39,10 +39,7 @@ class DescribeSchema(Command):
39
39
  # do not continue to cql route
40
40
  return state
41
41
 
42
- def completion(self, state: ReplState) -> dict[str, any]:
43
- if state.sts:
44
- return super().completion(state, {'&': None})
45
-
42
+ def completion(self, _: ReplState) -> dict[str, any]:
46
43
  return {}
47
44
 
48
45
  def help(self, _: ReplState) -> str:
@@ -1,5 +1,5 @@
1
1
  from adam.commands.command import Command
2
- from adam.commands.cql.cql_utils import run_cql, table_names
2
+ from adam.commands.cql.cql_utils import run_cql
3
3
  from adam.pod_exec_result import PodExecResult
4
4
  from adam.repl_state import ReplState, RequiredState
5
5
  from adam.utils import log2
@@ -50,11 +50,8 @@ class DescribeTable(Command):
50
50
  # do not continue to cql route
51
51
  return state
52
52
 
53
- def completion(self, state: ReplState) -> dict[str, any]:
54
- if state.sts:
55
- return super().completion(state, {t: {'&': None} for t in table_names(state)})
56
-
53
+ def completion(self, _: ReplState) -> dict[str, any]:
57
54
  return {}
58
55
 
59
56
  def help(self, _: ReplState) -> str:
60
- return f'{DescribeTable.COMMAND} <table-name> [&]\t describe Cassandra table'
57
+ return f'{DescribeTable.COMMAND} <table-name> [&]\t describe Cassandra or Athena table'
@@ -39,10 +39,7 @@ class DescribeTables(Command):
39
39
  # do not continue to cql route
40
40
  return state
41
41
 
42
- def completion(self, state: ReplState) -> dict[str, any]:
43
- if state.sts:
44
- return super().completion(state, {'&': None})
45
-
42
+ def completion(self, _: ReplState) -> dict[str, any]:
46
43
  return {}
47
44
 
48
45
  def help(self, _: ReplState) -> str:
adam/commands/ls.py CHANGED
@@ -91,7 +91,7 @@ class Ls(Command):
91
91
  def show_statefulsets(self):
92
92
  ss = StatefulSets.list_sts_names()
93
93
  if len(ss) == 0:
94
- log2('No cassandra statefulsets found.')
94
+ log2('No Cassandra clusters found.')
95
95
  return
96
96
 
97
97
  app_ids = CustomResources.get_app_ids()
@@ -1,5 +1,6 @@
1
1
  import functools
2
2
 
3
+ from adam.commands.audit.audit_table_completer import AuditTableNameCompleter
3
4
  from adam.commands.command import Command
4
5
  from adam.commands.cql.cql_table_completer import CqlTableNameCompleter
5
6
  from adam.commands.cql.cql_utils import run_cql, table_names, tables
@@ -8,6 +9,7 @@ from adam.commands.postgres.psql_table_completer import PsqlTableNameCompleter
8
9
  from adam.config import Config
9
10
  from adam.repl_state import ReplState, RequiredState
10
11
  from adam.utils import lines_to_tabular, log, log2
12
+ from adam.utils_athena import audit_table_names, run_audit_query
11
13
 
12
14
  class PreviewTable(Command):
13
15
  COMMAND = 'preview'
@@ -35,7 +37,7 @@ class PreviewTable(Command):
35
37
  if state.device == ReplState.P:
36
38
  if not self.validate_state(state, RequiredState.PG_DATABASE):
37
39
  return state
38
- else:
40
+ elif state.device != ReplState.L:
39
41
  if not self.validate_state(state):
40
42
  return state
41
43
 
@@ -45,8 +47,10 @@ class PreviewTable(Command):
45
47
  pg = PostgresSession(state.namespace, state.pg_path)
46
48
  lines = [db["name"] for db in pg.tables() if db["schema"] == PostgresSession.default_schema()]
47
49
  log(lines_to_tabular(lines, separator=','))
50
+ elif state.device == ReplState.L:
51
+ log(lines_to_tabular(audit_table_names(), separator=','))
48
52
  else:
49
- run_cql(state, f'describe tables', show_out=True)
53
+ run_cql(state, f'describe tables', show_out=True, on_any=True)
50
54
 
51
55
  if state.in_repl:
52
56
  log2('Table is required.')
@@ -66,14 +70,18 @@ class PreviewTable(Command):
66
70
  rows = Config().get('preview.rows', 10)
67
71
  if state.device == ReplState.P:
68
72
  PostgresSession(state.namespace, state.pg_path).run_sql(f'select * from {table} limit {rows}')
73
+ elif state.device == ReplState.L:
74
+ run_audit_query(f'select * from {table} limit {rows}')
69
75
  else:
70
- run_cql(state, f'select * from {table} limit {rows}', show_out=True, use_single_quotes=True)
76
+ run_cql(state, f'select * from {table} limit {rows}', show_out=True, use_single_quotes=True, on_any=True)
71
77
 
72
78
  return state
73
79
 
74
80
  def completion(self, state: ReplState):
75
81
  if state.device == ReplState.P:
76
82
  return {PreviewTable.COMMAND: PsqlTableNameCompleter(state.namespace, state.pg_path)}
83
+ elif state.device == ReplState.L:
84
+ return {PreviewTable.COMMAND: AuditTableNameCompleter()}
77
85
  elif state.sts:
78
86
  return {PreviewTable.COMMAND: CqlTableNameCompleter(table_names(state))}
79
87
 
adam/embedded_params.py CHANGED
@@ -1,2 +1,2 @@
1
1
  def config():
2
- return {'app': {'console-endpoint': 'https://{host}/{env}/{app}/static/console/index.html', 'cr': {'cluster-regex': '(.*?-.*?)-.*', 'group': 'ops.c3.ai', 'v': 'v2', 'plural': 'c3cassandras'}, 'label': 'c3__app_id-0', 'login': {'admin-group': '{host}/C3.ClusterAdmin', 'ingress': '{app_id}-k8singr-appleader-001', 'timeout': 5, 'session-check-url': 'https://{host}/{env}/{app}/api/8/C3/userSessionToken', 'cache-creds': True, 'cache-username': True, 'url': 'https://{host}/{env}/{app}', 'another': "You're logged in to {has}. However, for this app, you need to log in to {need}.", 'token-server-url': 'http://localhost:{port}', 'password-max-length': 128}, 'strip': '0'}, 'audit': {'endpoint': 'https://4psvtaxlcb.execute-api.us-west-2.amazonaws.com/prod/', 'workers': 3, 'timeout': 10, 'log-audit-queries': False, 'athena': {'auto-repair': {'elapsed_hours': 12}, 'region': 'us-west-2', 'catalog': 'AwsDataCatalog', 'database': 'audit', 'tables': 'audit', 'output': 's3://s3.ops--audit/ddl/results'}}, 'bash': {'workers': 32}, 'cassandra': {'service-name': 'all-pods-service'}, 'cql': {'workers': 32, 'samples': 3, 'secret': {'cluster-regex': '(.*?-.*?)-.*', 'name': '{cluster}-superuser', 'password-item': 'password'}, 'alter-tables': {'excludes': 'system_auth,system_traces,reaper_db,system_distributed,system_views,system,system_schema,system_virtual_schema', 'gc-grace-periods': '3600,86400,864000,7776000', 'batching': True}}, 'checks': {'compactions-threshold': 250, 'cpu-busy-threshold': 98.0, 'cpu-threshold': 0.0, 'cassandra-data-path': '/c3/cassandra', 'root-disk-threshold': 50, 'cassandra-disk-threshold': 50, 'snapshot-size-cmd': "ls /c3/cassandra/data/data/*/*/snapshots | grep snapshots | sed 's/:$//g' | xargs -I {} du -sk {} | awk '{print $1}' | awk '{s+=$1} END {print s}'", 'snapshot-size-threshold': '40G', 'table-sizes-cmd': "ls -Al /c3/cassandra/data/data/ | awk '{print $9}' | sed 's/\\^r//g' | xargs -I {} du -sk /c3/cassandra/data/data/{}"}, 'get-host-id': {'workers': 32}, 'idps': {'ad': {'email-pattern': '.*@c3.ai', 'uri': 'https://login.microsoftonline.com/53ad779a-93e7-485c-ba20-ac8290d7252b/oauth2/v2.0/authorize?response_type=id_token&response_mode=form_post&client_id=00ff94a8-6b0a-4715-98e0-95490012d818&scope=openid+email+profile&redirect_uri=https%3A%2F%2Fplat.c3ci.cloud%2Fc3%2Fc3%2Foidc%2Flogin&nonce={nonce}&state=EMPTY', 'jwks-uri': 'https://login.microsoftonline.com/common/discovery/keys', 'contact': 'Please contact ted.tran@c3.ai.', 'whitelist-file': '/kaqing/members'}, 'okta': {'default': True, 'email-pattern': '.*@c3iot.com', 'uri': 'https://c3energy.okta.com/oauth2/v1/authorize?response_type=id_token&response_mode=form_post&client_id={client_id}&scope=openid+email+profile+groups&redirect_uri=https%3A%2F%2F{host}%2Fc3%2Fc3%2Foidc%2Flogin&nonce={nonce}&state=EMPTY', 'jwks-uri': 'https://c3energy.okta.com/oauth2/v1/keys'}}, 'issues': {'workers': 32}, 'logs': {'path': '/c3/cassandra/logs/system.log'}, 'medusa': {'restore-auto-complete': False}, 'nodetool': {'workers': 32, 'samples': 3, 'commands_in_line': 40}, 'pg': {'name-pattern': '^{namespace}.*-k8spg-.*', 'excludes': '.helm., -admin-secret', 'agent': {'name': 'ops-pg-agent', 'just-in-time': False, 'timeout': 86400, 'image': 'seanahnsf/kaqing'}, 'default-db': 'postgres', 'default-schema': 'postgres', 'secret': {'endpoint-key': 'postgres-db-endpoint', 'port-key': 'postgres-db-port', 'username-key': 'postgres-admin-username', 'password-key': 'postgres-admin-password'}}, 'pod': {'name': 'ops', 'image': 'seanahnsf/kaqing-cloud', 'sa': {'name': 'ops', 'proto': 'c3', 'additional-cluster-roles': 'c3aiops-k8ssandra-operator'}, 'label-selector': 'run=ops'}, 'preview': {'rows': 10}, 'processes': {'columns': 'pod,cpu,mem', 'header': 'POD_NAME,CPU,MEM/LIMIT'}, 'reaper': {'service-name': 'reaper-service', 'port-forward': {'timeout': 86400, 'local-port': 9001}, 'abort-runs-batch': 10, 'show-runs-batch': 100, 'pod': {'cluster-regex': '(.*?-.*?-.*?-.*?)-.*', 'label-selector': 'k8ssandra.io/reaper={cluster}-reaper'}, 'secret': {'cluster-regex': '(.*?-.*?)-.*', 'name': '{cluster}-reaper-ui', 'password-item': 'password'}}, 'repair': {'log-path': '/home/cassrepair/logs/', 'image': 'ci-registry.c3iot.io/cloudops/cassrepair:2.0.14', 'secret': 'ciregistryc3iotio', 'env': {'interval': 24, 'timeout': 60, 'pr': False, 'runs': 1}}, 'repl': {'start-drive': 'a', 'a': {'auto-enter-app': 'c3/c3'}, 'c': {'auto-enter-only-cluster': 'cluster'}, 'history': {'push-cat-remote-log-file': True}, 'background-process': {'auto-nohup': True}}, 'status': {'columns': 'status,address,load,tokens,owns,host_id,gossip,compactions', 'header': '--,Address,Load,Tokens,Owns,Host ID,GOSSIP,COMPACTIONS'}, 'storage': {'columns': 'pod,volume_root,volume_cassandra,snapshots,data,compactions', 'header': 'POD_NAME,VOLUME /,VOLUME CASS,SNAPSHOTS,DATA,COMPACTIONS'}, 'watch': {'auto': 'rollout', 'timeout': 3600, 'interval': 10}, 'debug': False, 'debugs': {'timings': False, 'exit-on-error': False, 'show-parallelism': False}}
2
+ return {'app': {'console-endpoint': 'https://{host}/{env}/{app}/static/console/index.html', 'cr': {'cluster-regex': '(.*?-.*?)-.*', 'group': 'ops.c3.ai', 'v': 'v2', 'plural': 'c3cassandras'}, 'label': 'c3__app_id-0', 'login': {'admin-group': '{host}/C3.ClusterAdmin', 'ingress': '{app_id}-k8singr-appleader-001', 'timeout': 5, 'session-check-url': 'https://{host}/{env}/{app}/api/8/C3/userSessionToken', 'cache-creds': True, 'cache-username': True, 'url': 'https://{host}/{env}/{app}', 'another': "You're logged in to {has}. However, for this app, you need to log in to {need}.", 'token-server-url': 'http://localhost:{port}', 'password-max-length': 128}, 'strip': '0'}, 'audit': {'endpoint': 'https://4psvtaxlcb.execute-api.us-west-2.amazonaws.com/prod/', 'workers': 3, 'timeout': 10, 'log-audit-queries': False, 'athena': {'auto-repair': {'elapsed_hours': 12}, 'region': 'us-west-2', 'catalog': 'AwsDataCatalog', 'database': 'audit', 'tables': 'audit', 'output': 's3://s3.ops--audit/ddl/results'}}, 'bash': {'workers': 32}, 'cassandra': {'service-name': 'all-pods-service'}, 'cql': {'workers': 32, 'samples': 3, 'secret': {'cluster-regex': '(.*?-.*?)-.*', 'name': '{cluster}-superuser', 'password-item': 'password'}, 'alter-tables': {'excludes': 'system_auth,system_traces,reaper_db,system_distributed,system_views,system,system_schema,system_virtual_schema', 'gc-grace-periods': '3600,86400,864000,7776000', 'batching': True}}, 'checks': {'compactions-threshold': 250, 'cpu-busy-threshold': 98.0, 'cpu-threshold': 0.0, 'cassandra-data-path': '/c3/cassandra', 'root-disk-threshold': 50, 'cassandra-disk-threshold': 50, 'snapshot-size-cmd': "ls /c3/cassandra/data/data/*/*/snapshots | grep snapshots | sed 's/:$//g' | xargs -I {} du -sk {} | awk '{print $1}' | awk '{s+=$1} END {print s}'", 'snapshot-size-threshold': '40G', 'table-sizes-cmd': "ls -Al /c3/cassandra/data/data/ | awk '{print $9}' | sed 's/\\^r//g' | xargs -I {} du -sk /c3/cassandra/data/data/{}"}, 'get-host-id': {'workers': 32}, 'idps': {'ad': {'email-pattern': '.*@c3.ai', 'uri': 'https://login.microsoftonline.com/53ad779a-93e7-485c-ba20-ac8290d7252b/oauth2/v2.0/authorize?response_type=id_token&response_mode=form_post&client_id=00ff94a8-6b0a-4715-98e0-95490012d818&scope=openid+email+profile&redirect_uri=https%3A%2F%2Fplat.c3ci.cloud%2Fc3%2Fc3%2Foidc%2Flogin&nonce={nonce}&state=EMPTY', 'jwks-uri': 'https://login.microsoftonline.com/common/discovery/keys', 'contact': 'Please contact ted.tran@c3.ai.', 'whitelist-file': '/kaqing/members'}, 'okta': {'default': True, 'email-pattern': '.*@c3iot.com', 'uri': 'https://c3energy.okta.com/oauth2/v1/authorize?response_type=id_token&response_mode=form_post&client_id={client_id}&scope=openid+email+profile+groups&redirect_uri=https%3A%2F%2F{host}%2Fc3%2Fc3%2Foidc%2Flogin&nonce={nonce}&state=EMPTY', 'jwks-uri': 'https://c3energy.okta.com/oauth2/v1/keys'}}, 'issues': {'workers': 32}, 'logs': {'path': '/c3/cassandra/logs/system.log'}, 'medusa': {'restore-auto-complete': False}, 'nodetool': {'workers': 32, 'samples': 3, 'commands_in_line': 40}, 'pg': {'name-pattern': '^{namespace}.*-k8spg-.*', 'excludes': '.helm., -admin-secret', 'agent': {'name': 'ops-pg-agent', 'just-in-time': False, 'timeout': 86400, 'image': 'seanahnsf/kaqing'}, 'default-db': 'postgres', 'default-schema': 'postgres', 'secret': {'endpoint-key': 'postgres-db-endpoint', 'port-key': 'postgres-db-port', 'username-key': 'postgres-admin-username', 'password-key': 'postgres-admin-password'}}, 'pod': {'name': 'ops', 'image': 'seanahnsf/kaqing-cloud', 'sa': {'name': 'ops', 'proto': 'c3', 'additional-cluster-roles': 'c3aiops-k8ssandra-operator'}, 'label-selector': 'run=ops'}, 'preview': {'rows': 10}, 'processes': {'columns': 'pod,cpu,mem', 'header': 'POD_NAME,CPU,MEM/LIMIT'}, 'reaper': {'service-name': 'reaper-service', 'port-forward': {'timeout': 86400, 'local-port': 9001}, 'abort-runs-batch': 10, 'show-runs-batch': 100, 'pod': {'cluster-regex': '(.*?-.*?-.*?-.*?)-.*', 'label-selector': 'k8ssandra.io/reaper={cluster}-reaper'}, 'secret': {'cluster-regex': '(.*?-.*?)-.*', 'name': '{cluster}-reaper-ui', 'password-item': 'password'}}, 'repair': {'log-path': '/home/cassrepair/logs/', 'image': 'ci-registry.c3iot.io/cloudops/cassrepair:2.0.14', 'secret': 'ciregistryc3iotio', 'env': {'interval': 24, 'timeout': 60, 'pr': False, 'runs': 1}}, 'repl': {'start-drive': 'a', 'a': {'auto-enter': 'c3/c3'}, 'c': {'auto-enter': 'cluster'}, 'history': {'push-cat-remote-log-file': True}, 'background-process': {'auto-nohup': True}}, 'status': {'columns': 'status,address,load,tokens,owns,host_id,gossip,compactions', 'header': '--,Address,Load,Tokens,Owns,Host ID,GOSSIP,COMPACTIONS'}, 'storage': {'columns': 'pod,volume_root,volume_cassandra,snapshots,data,compactions', 'header': 'POD_NAME,VOLUME /,VOLUME CASS,SNAPSHOTS,DATA,COMPACTIONS'}, 'watch': {'auto': 'rollout', 'timeout': 3600, 'interval': 10}, 'debug': False, 'debugs': {'timings': False, 'exit-on-error': False, 'show-parallelism': False}}
adam/repl.py CHANGED
@@ -69,20 +69,21 @@ def enter_repl(state: ReplState):
69
69
  Log.log2(f'kaqing {__version__}')
70
70
 
71
71
  if state.device == ReplState.C:
72
- auto_enter = Config().get('repl.c.auto-enter-only-cluster', 'cluster')
73
- ss = StatefulSets.list_sts_name_and_ns()
74
- if not ss:
75
- raise Exception("no Cassandra clusters found")
76
- elif not state.sts and len(ss) == 1 and auto_enter in ['cluster', 'first-pod']:
77
- cluster = ss[0]
78
- state.sts = cluster[0]
79
- state.namespace = cluster[1]
80
- if auto_enter == 'first-pod':
81
- state.pod = f'{state.sts}-0'
82
- if KubeContext().in_cluster_namespace:
83
- Config().wait_log(f'Moving to the only Cassandra cluster: {state.sts}...')
84
- else:
85
- Config().wait_log(f'Moving to the only Cassandra cluster: {state.sts}@{state.namespace}...')
72
+ auto_enter = Config().get('repl.c.auto-enter', 'cluster')
73
+ if auto_enter and auto_enter in ['cluster', 'first-pod']:
74
+ ss = StatefulSets.list_sts_name_and_ns()
75
+ if not ss:
76
+ log2("No Cassandra clusters found.")
77
+ elif not state.sts and len(ss) == 1:
78
+ cluster = ss[0]
79
+ state.sts = cluster[0]
80
+ state.namespace = cluster[1]
81
+ if auto_enter == 'first-pod':
82
+ state.pod = f'{state.sts}-0'
83
+ if KubeContext().in_cluster_namespace:
84
+ Config().wait_log(f'Moving to the only Cassandra cluster: {state.sts}...')
85
+ else:
86
+ Config().wait_log(f'Moving to the only Cassandra cluster: {state.sts}@{state.namespace}...')
86
87
  elif state.device == ReplState.A:
87
88
  if not state.app_env:
88
89
  if app := Config().get('repl.a.auto-enter-app', 'c3/c3'):
@@ -140,32 +141,34 @@ def enter_repl(state: ReplState):
140
141
  cmd = f'bash {cmd}'
141
142
 
142
143
  if cmd and cmd.strip(' ') and not cmds.run(cmd, state):
143
- c_sql_tried = False
144
- if state.device == ReplState.P:
145
- pg = PostgresSession(state.namespace, state.pg_path)
146
- if pg.db:
147
- c_sql_tried = True
148
- cmd = f'pg {cmd}'
149
- cmds.run(cmd, state)
150
- elif state.device == ReplState.A:
151
- if state.app_app:
152
- c_sql_tried = True
153
- cmd = f'app {cmd}'
154
- cmds.run(cmd, state)
155
- elif state.device == ReplState.L:
156
- c_sql_tried = True
157
- cmd = f'audit {cmd}'
158
- cmds.run(cmd, state)
159
- elif state.sts:
160
- c_sql_tried = True
161
- cmd = f'cql {cmd}'
162
- cmds.run(cmd, state)
163
-
164
- if not c_sql_tried:
165
- log2(f'* Invalid command: {cmd}')
166
- log2()
167
- lines = [c.help(state) for c in cmd_list if c.help(state)]
168
- log2(lines_to_tabular(lines, separator='\t'))
144
+ try_device_default_action(state, cmds, cmd_list)
145
+ # not served by any command in the chain; try SQL query or C3 action
146
+ # c_sql_tried = False
147
+ # if state.device == ReplState.P:
148
+ # pg = PostgresSession(state.namespace, state.pg_path)
149
+ # if pg.db:
150
+ # c_sql_tried = True
151
+ # cmd = f'pg {cmd}'
152
+ # cmds.run(cmd, state)
153
+ # elif state.device == ReplState.A:
154
+ # if state.app_app:
155
+ # c_sql_tried = True
156
+ # cmd = f'app {cmd}'
157
+ # cmds.run(cmd, state)
158
+ # elif state.device == ReplState.L:
159
+ # c_sql_tried = True
160
+ # cmd = f'audit {cmd}'
161
+ # cmds.run(cmd, state)
162
+ # elif state.sts:
163
+ # c_sql_tried = True
164
+ # cmd = f'cql {cmd}'
165
+ # cmds.run(cmd, state)
166
+
167
+ # if not c_sql_tried:
168
+ # log2(f'* Invalid command: {cmd}')
169
+ # log2()
170
+ # lines = [c.help(state) for c in cmd_list if c.help(state)]
171
+ # log2(lines_to_tabular(lines, separator='\t'))
169
172
  except EOFError: # Handle Ctrl+D (EOF) for graceful exit
170
173
  break
171
174
  except Exception as e:
@@ -183,6 +186,34 @@ def enter_repl(state: ReplState):
183
186
  if cmd and (state.device != ReplState.L or Config().get('audit.log-audit-queries', False)):
184
187
  executor.submit(audit_log, cmd, state)
185
188
 
189
+ def try_device_default_action(state: ReplState, cmds: Command, cmd_list: list[Command]):
190
+ c_sql_tried = False
191
+ if state.device == ReplState.P:
192
+ pg = PostgresSession(state.namespace, state.pg_path)
193
+ if pg.db:
194
+ c_sql_tried = True
195
+ cmd = f'pg {cmd}'
196
+ cmds.run(cmd, state)
197
+ elif state.device == ReplState.A:
198
+ if state.app_app:
199
+ c_sql_tried = True
200
+ cmd = f'app {cmd}'
201
+ cmds.run(cmd, state)
202
+ elif state.device == ReplState.L:
203
+ c_sql_tried = True
204
+ cmd = f'audit {cmd}'
205
+ cmds.run(cmd, state)
206
+ elif state.sts:
207
+ c_sql_tried = True
208
+ cmd = f'cql {cmd}'
209
+ cmds.run(cmd, state)
210
+
211
+ if not c_sql_tried:
212
+ log2(f'* Invalid command: {cmd}')
213
+ log2()
214
+ lines = [c.help(state) for c in cmd_list if c.help(state)]
215
+ log2(lines_to_tabular(lines, separator='\t'))
216
+
186
217
  def audit_log(cmd: str, state: ReplState):
187
218
  payload = {
188
219
  'cluster': state.namespace if state.namespace else 'NA',
adam/sql/sql_completer.py CHANGED
@@ -11,7 +11,7 @@ __all__ = [
11
11
  "SqlCompleter",
12
12
  ]
13
13
 
14
- DML_COMPLETER = TermCompleter(['select', 'insert', 'delete', 'update', 'alter'])
14
+ DML_COMPLETER = TermCompleter(['select', 'insert', 'delete', 'update', 'alter', 'describe'])
15
15
 
16
16
  def default_columns(tables: list[str]):
17
17
  return 'id,x.,y.,z.'.split(',')
@@ -98,4 +98,5 @@ class SqlCompleter(Completer):
98
98
  'select': SqlCompleter(table_names, 'select', columns=columns, partition_columns=partition_columns, table_props=table_props, variant=variant),
99
99
  'update': SqlCompleter(table_names, 'update', columns=columns, partition_columns=partition_columns, table_props=table_props, variant=variant),
100
100
  'alter': SqlCompleter(table_names, 'alter', columns=columns, partition_columns=partition_columns, table_props=table_props, variant=variant),
101
+ 'describe': SqlCompleter(table_names, 'describe', columns=columns, partition_columns=partition_columns, table_props=table_props, variant=variant),
101
102
  }
adam/sql/state_machine.py CHANGED
@@ -321,7 +321,8 @@ class SqlSpec:
321
321
  'update', 'where', 'set',
322
322
  'delete',
323
323
  'audit',
324
- 'alter', 'table', 'tables', 'add', 'drop', 'with'
324
+ 'alter', 'table', 'tables', 'add', 'drop', 'with',
325
+ 'describe'
325
326
  ]
326
327
 
327
328
  def spec(self):
@@ -346,11 +347,32 @@ class CqlSpec(SqlSpec):
346
347
  'alter_table_with_ > name > alter_table_with_p ^ table-props',
347
348
  'alter_table_with_p > comparison > alter_table_with_p_op ^ =',
348
349
  'alter_table_with_p_op > name|single|num > alter_table_with_p_op ^ table-prop-values',
350
+
351
+ ' > describe > describe',
352
+ 'describe_ > table > desc_table ^ table,`tables`,keyspace,keyspaces,schema',
353
+ '- > tables > desc_tables',
354
+ '- > keyspace > desc_keyspace',
355
+ '- > keyspaces > desc_keyspaces',
356
+ '- > schema > desc_schema',
357
+ 'desc_table_ > name > desc_table_t ^ tables',
358
+ 'desc_table_t > name > desc_table_t ^ tables',
359
+ 'desc_table_t_ > & > desc_table_t_bg ^ &',
360
+ 'desc_tables_ > & > desc_tables_bg ^ &',
361
+ 'desc_keyspace_ > name > desc_keyspace_k',
362
+ 'desc_keyspace_k_ > & > desc_keyspace_k_bg ^ &',
363
+ 'desc_schema_ > & > desc_schema_bg ^ &',
364
+ ]
365
+
366
+ KEYWORDS = SqlSpec.KEYWORDS + [
367
+ 'schema', 'keyspace', 'keyspaces', 'tables'
349
368
  ]
350
369
 
351
370
  def spec(self):
352
371
  return CqlSpec.SPEC
353
372
 
373
+ def keywords(self):
374
+ return CqlSpec.KEYWORDS
375
+
354
376
  class AthenaSpec(SqlSpec):
355
377
  SPEC = SqlSpec.SPEC + [
356
378
  'alter_table_t_ > add > alter_table_add ^ add partition,drop partition',
@@ -362,6 +384,11 @@ class AthenaSpec(SqlSpec):
362
384
  'alter_partition_lp_a_op > single > alter_partition_lp_a_op_v ^ single',
363
385
  'alter_partition_lp_a_op_v > , > alter_partition_lp_sc ^ single',
364
386
  'alter_partition_lp_sc > name|) > alter_partition_lp_a ^ partition-columns',
387
+
388
+ ' > describe > describe',
389
+ 'describe_ > name > desc_t ^ tables',
390
+ 'desc_t > name > desc_t ^ tables',
391
+ 'desc_t_ > name > desc_t_',
365
392
  ]
366
393
 
367
394
  KEYWORDS = SqlSpec.KEYWORDS + [
adam/version.py CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
- __version__ = "2.0.100" #: the working version
4
+ __version__ = "2.0.101" #: the working version
5
5
  __release__ = "1.0.0" #: the release version
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kaqing
3
- Version: 2.0.100
3
+ Version: 2.0.101
4
4
  Summary: UNKNOWN
5
5
  Home-page: UNKNOWN
6
6
  License: UNKNOWN
@@ -6,17 +6,17 @@ adam/cli.py,sha256=03pIZdomAu7IL-GSP6Eun_PKwwISShRAmfx6eVRPGC0,458
6
6
  adam/cli_group.py,sha256=W3zy1BghCtVcEXizq8fBH-93ZRVVwgAyGPzy0sHno1Y,593
7
7
  adam/config.py,sha256=GRtfpGgGwfeYdVSPfk3LKCRXlOEJZ2vmXM3ADr7IhVk,2880
8
8
  adam/embedded_apps.py,sha256=lKPx63mKzJbNmwz0rgL4gF76M9fDGxraYTtNAIGnZ_s,419
9
- adam/embedded_params.py,sha256=-S3OU1WLL2mh5MgbN8C8amoG7KEYsCpNzc9wQpfTRVo,5026
9
+ adam/embedded_params.py,sha256=7HLYppBdHk_HdV0afngj-NTu83Q3FbiT44WJySRUBHk,5009
10
10
  adam/log.py,sha256=gg5DK52wLPc9cjykeh0WFHyAk1qI3HEpGaAK8W2dzXY,1146
11
11
  adam/pod_exec_result.py,sha256=WBXJSvxzXp9TfsfXeHtIvgz8GvfMAAcH5M03GISLqzw,1046
12
- adam/repl.py,sha256=vGlmdlD5TiNBlz7v5zkvaCB6V4NY7pFCuspOd32wBhI,9672
12
+ adam/repl.py,sha256=RSbw2SYFmF3lz8hg7k4vI2D1TNiG0DWuXg0Z8jhB3d4,10843
13
13
  adam/repl_commands.py,sha256=GKdpHm4e0it7qVwjzBrsIoa5szpvZC30kJmHbWCvooA,4691
14
14
  adam/repl_session.py,sha256=uIogcvWBh7wd8QQ-p_JgLsyJ8YJgINw5vOd6JIsd7Vo,472
15
15
  adam/repl_state.py,sha256=VlQpV19Sg5vL8H3o8lQxZB5atyuTuN5iEQsd6xpSkQQ,8774
16
16
  adam/utils.py,sha256=sbsNZP3qGJtb6fXCa4dDXHry5ay9ev583cCZIQzy07s,7382
17
17
  adam/utils_athena.py,sha256=6OYed6dQ4dg2GZ3MPYt7fArWweEwyMpx2SUky0lb8Pc,3314
18
18
  adam/utils_net.py,sha256=65fhBnWMCkhGtyHqz95qcHaCo35q-WX1RBkkXG8dKpI,416
19
- adam/version.py,sha256=plo08z_STEg-gXDR8OpU9lpUw2fzboE_9Qem6N3gAyQ,140
19
+ adam/version.py,sha256=68swXPI-eaVV2ykpQpwZBM0hQRNQRORKjENYlrRJQLA,140
20
20
  adam/checks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
21
  adam/checks/check.py,sha256=Qopr3huYcMu2bzQgb99dEUYjFzkjKHRI76S6KA9b9Rk,702
22
22
  adam/checks/check_context.py,sha256=FEHkQ32jY1EDopQ2uYWqy9v7aEEX1orLpJWhopwAlh4,402
@@ -66,12 +66,12 @@ adam/commands/help.py,sha256=4IzR4p8UiXr00o1TaymHWm8957EWbWRyuvhrJzZzvc0,1734
66
66
  adam/commands/issues.py,sha256=VS-PC7e-2lywsa-lbmoUX8IY77OPGzFudwbw1g8XmQc,2599
67
67
  adam/commands/login.py,sha256=bj95WWIF7mJDJhnyS9T8xvaZUGL37dj7GlH8TgmODbk,1877
68
68
  adam/commands/logs.py,sha256=GBVztFlCQfd4jfMtqydPjWS9xsB5mV4Aj4ohSQFm6i0,1165
69
- adam/commands/ls.py,sha256=HzfKvaFTrPMKl7N3PtVciuBGj2lZIe9eeEohgDyyav8,5798
69
+ adam/commands/ls.py,sha256=y2r35I_Oa2tYqlkfpmcGHAdxCVCuJmCjrhlimbV142Y,5794
70
70
  adam/commands/nodetool.py,sha256=j_DS5Tqe_NLpq2d0kTCC9IyNcl9krEHsB-URwBPeHVU,2356
71
71
  adam/commands/nodetool_commands.py,sha256=5IgWC3rmeDD1cgwqQjiiWzi-wJpJ3n_8pAzz_9phXuk,2635
72
72
  adam/commands/param_get.py,sha256=kPAAppK2T0tEFRnSIVFLDPIIGHhgLA7drJhn8TRyvvE,1305
73
73
  adam/commands/param_set.py,sha256=QDIuqfU80aWCB16OK49yf7XRaRTWwiLkwMsJuVikq9I,1271
74
- adam/commands/preview_table.py,sha256=5im47Uk6RclgkZD-Ci0lBs1eosnfvBtKt2lgsb_bohs,3068
74
+ adam/commands/preview_table.py,sha256=Xz4-FVSAzLtZFY1moUBuWdzZK7MOsmKtGWCxXV8ZgFM,3613
75
75
  adam/commands/pwd.py,sha256=izzMhIcbHjky2VA-84w5pt4nQDDUqahg3t34qy5yxMM,2446
76
76
  adam/commands/report.py,sha256=Ky45LIzSlB_X4V12JZWjU3SA2u4_FKRencRTq7psOWU,1944
77
77
  adam/commands/restart.py,sha256=SAxWHvglTckQJ0tJe5t-HWsVerbreNMM-7Nb9PAqno4,2044
@@ -79,8 +79,9 @@ adam/commands/rollout.py,sha256=Db9P4Owd3aPcRLIGhwyEElBNm_2Ke54KbiXyVKmztcE,2959
79
79
  adam/commands/shell.py,sha256=wY_PIx7Lt6vuxhFArlfxdEnBbrouCJ3yNHhFn17DEqw,848
80
80
  adam/commands/watch.py,sha256=fU2LGll-Igl08HpUQALOnh8l3s3AMGFX26NCLhqbfcw,2438
81
81
  adam/commands/audit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
82
- adam/commands/audit/audit.py,sha256=SOsh0FucedxfD7TQi2mvPdhu21ikTRTQQq06oueBf28,2664
82
+ adam/commands/audit/audit.py,sha256=mPn5uGb_wF8xf0KAIuw54NDsU-CwhCuaNsugBg7YGhM,2676
83
83
  adam/commands/audit/audit_repair_tables.py,sha256=ciKmacngg1r14uR8Z_uzgNH_sk0QlCQvJHLjcWeeDnQ,3330
84
+ adam/commands/audit/audit_table_completer.py,sha256=6xqPhAicic_-04dckaMn1v6a8utL5GY-HsE0mhpA4YM,336
84
85
  adam/commands/cql/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
85
86
  adam/commands/cql/cql_completions.py,sha256=PxARSyVnNHNfpC-6-8sfgChdUI5KGxs64U5EMgU6lvQ,616
86
87
  adam/commands/cql/cql_table_completer.py,sha256=Tth6lmZ1eCEbJeAVZojTx594ttQeeVf-OjhhkSLyRnI,312
@@ -100,12 +101,12 @@ adam/commands/deploy/undeploy_frontend.py,sha256=gHekPn7l19JgVbhneKpQ7ModNoDFmzW
100
101
  adam/commands/deploy/undeploy_pg_agent.py,sha256=RYME8no1FT94WpVg-HXDGL1NmLlpE1I9R4htitjaxpo,1319
101
102
  adam/commands/deploy/undeploy_pod.py,sha256=I-pNfdcfBGLJ5YssTjSHoM4miygqoiGN233wUSIUG9Y,1905
102
103
  adam/commands/describe/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
103
- adam/commands/describe/describe.py,sha256=h300tQRWPNCil9KXM1mUdNHiNcXb3Gq1x92anpJHtKA,1594
104
- adam/commands/describe/describe_keyspace.py,sha256=clqDM5-mS_8R90vjz14Z7P7dr38JbKft3v-KN5WAs-w,1901
105
- adam/commands/describe/describe_keyspaces.py,sha256=3oYiHoCFoTrgFG0xfWgU60412n9C0jLY38d_w0mghnQ,1576
106
- adam/commands/describe/describe_schema.py,sha256=mOiFqWe_M1JwtL-qSvGsXjlQxgViX0AWZl9f4ho58zY,1555
107
- adam/commands/describe/describe_table.py,sha256=wMAsi0bZuehDzj5LtkQfLFyiAGTlyfM_aou4Nvg53TE,1867
108
- adam/commands/describe/describe_tables.py,sha256=rtZtPZ8bHI6XXfKW0TcEXqmdgeOiC73QUoY4ig4xsEw,1555
104
+ adam/commands/describe/describe.py,sha256=k1nQc4ZyilDxFwwLS97Ss-x90z5719Oa4IV16K_gpXE,2056
105
+ adam/commands/describe/describe_keyspace.py,sha256=-75hJSsiHCLhGGnjXgRFPCsSEcCt9m3L5qPowA7N2D4,1760
106
+ adam/commands/describe/describe_keyspaces.py,sha256=9AFQRa7pAkNMWKkhao97fx0w2No9bah_7uGqTS_yuZc,1491
107
+ adam/commands/describe/describe_schema.py,sha256=AdMMR6U9L2OC-XaVxr4JQjKGh_T0H4IU9UpenOoqfOo,1470
108
+ adam/commands/describe/describe_table.py,sha256=HQRAx_UzDHJ1OzbqBhzFNIOO5puQBIGnWXu6Egv-Up4,1746
109
+ adam/commands/describe/describe_tables.py,sha256=_dBCyN-YKmDIEqb7hi12XoFfbrR5ltQhBtS8j61W6b8,1470
109
110
  adam/commands/medusa/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
110
111
  adam/commands/medusa/medusa.py,sha256=KNFjStvilIuOJt3wTtcWmKvdm8FdCnrDY2ltEWbratk,1402
111
112
  adam/commands/medusa/medusa_backup.py,sha256=Tns-nBbqTnry8zoCFtXCisco3ipcOgArQbN5rc7SRGY,1801
@@ -156,8 +157,8 @@ adam/commands/show/show_processes.py,sha256=K7sBSyvCukp3bfoi0SBaqMV5a4Af8paEQXVZ
156
157
  adam/commands/show/show_repairs.py,sha256=m82ukc6YxjvJc9rdKXsiJLtXrEUCiaE-VPqgxDsIOeM,1477
157
158
  adam/commands/show/show_storage.py,sha256=WuBB5AEFm4g7oBz_YCbtkrF2GEeJ-J2tqCVmvzwmwuI,1837
158
159
  adam/sql/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
159
- adam/sql/sql_completer.py,sha256=QOdMu5ZFGikoE121WpJ9zGew58968M0_n5dN_ar4dNk,4538
160
- adam/sql/state_machine.py,sha256=gDktPZKwi88o7flExAAPBCFeQkzE_XrAf8QCVv3sFrA,31797
160
+ adam/sql/sql_completer.py,sha256=FoCYlDWF_6a7CE752kkzNsuVZ_gPBxEUHZYDiefmegg,4709
161
+ adam/sql/state_machine.py,sha256=3FPDvAeqBkzyh_Sdedn7_vYwqwAjOZ7P8JGcpF7-Bx8,33609
161
162
  adam/sql/term_completer.py,sha256=bNnHAVf9NZl52xS_BQpikbOK39gDBJADnT9gSvG0iqI,2539
162
163
  adam/sso/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
163
164
  adam/sso/authenticator.py,sha256=BCm16L9zf5aLU47-sTCnudn2zLPwd8M2wwRminJfsqw,615
@@ -184,8 +185,8 @@ adam/utils_k8s/service_accounts.py,sha256=v2oQSqCrNvt2uRnKlNwR3fjtpUG7oF5nqgzEB7
184
185
  adam/utils_k8s/services.py,sha256=EOJJGACVbbRvu5T3rMKqIJqgYic1_MSJ17EA0TJ6UOk,3156
185
186
  adam/utils_k8s/statefulsets.py,sha256=5g7KxGRHgEewT8rnZneDTaJDylUf-dHH2edWJEoorr8,4667
186
187
  adam/utils_k8s/volumes.py,sha256=RIBmlOSWM3V3QVXLCFT0owVOyh4rGG1ETp521a-6ndo,1137
187
- kaqing-2.0.100.dist-info/METADATA,sha256=0p2IqYuUnvRJxY7pPZPlQhFwsg86H2FRqDzAwEoLRmc,133
188
- kaqing-2.0.100.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
189
- kaqing-2.0.100.dist-info/entry_points.txt,sha256=SkzhuQJUWsXOzHeZ5TgQ2c3_g53UGK23zzJU_JTZOZI,39
190
- kaqing-2.0.100.dist-info/top_level.txt,sha256=8_2PZkwBb-xDcnc8a2rAbQeJhXKXskc7zTP7pSPa1fw,5
191
- kaqing-2.0.100.dist-info/RECORD,,
188
+ kaqing-2.0.101.dist-info/METADATA,sha256=a3PcWNTCr-Bt2UZcbymVhgAahRASALulZtxdEjY1xhM,133
189
+ kaqing-2.0.101.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
190
+ kaqing-2.0.101.dist-info/entry_points.txt,sha256=SkzhuQJUWsXOzHeZ5TgQ2c3_g53UGK23zzJU_JTZOZI,39
191
+ kaqing-2.0.101.dist-info/top_level.txt,sha256=8_2PZkwBb-xDcnc8a2rAbQeJhXKXskc7zTP7pSPa1fw,5
192
+ kaqing-2.0.101.dist-info/RECORD,,