kaqing 2.0.102__py3-none-any.whl → 2.0.105__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.
- adam/batch.py +0 -14
- adam/commands/audit/audit.py +12 -16
- adam/commands/audit/audit_repair_tables.py +14 -37
- adam/commands/audit/audit_run.py +51 -0
- adam/commands/bash.py +60 -2
- adam/commands/cd.py +8 -8
- adam/commands/commands_utils.py +1 -2
- adam/commands/cql/cql_completions.py +4 -4
- adam/commands/cql/cql_utils.py +1 -1
- adam/commands/cql/cqlsh.py +1 -1
- adam/commands/deploy/deploy_pg_agent.py +2 -2
- adam/commands/deploy/undeploy_pg_agent.py +2 -2
- adam/commands/ls.py +14 -14
- adam/commands/nodetool.py +1 -1
- adam/commands/postgres/postgres.py +3 -3
- adam/commands/postgres/{postgres_session.py → postgres_context.py} +26 -27
- adam/commands/postgres/postgres_utils.py +5 -5
- adam/commands/postgres/psql_completions.py +1 -1
- adam/commands/preview_table.py +11 -30
- adam/commands/pwd.py +2 -2
- adam/embedded_params.py +1 -1
- adam/repl.py +3 -3
- adam/repl_commands.py +4 -7
- adam/repl_state.py +2 -2
- adam/sql/sql_completer.py +67 -76
- adam/sql/sql_state_machine.py +518 -0
- adam/sql/term_completer.py +3 -0
- adam/utils_audits.py +167 -0
- adam/utils_k8s/pods.py +2 -2
- adam/version.py +1 -1
- {kaqing-2.0.102.dist-info → kaqing-2.0.105.dist-info}/METADATA +1 -1
- {kaqing-2.0.102.dist-info → kaqing-2.0.105.dist-info}/RECORD +35 -44
- adam/commands/audit/audit_table_completer.py +0 -9
- adam/commands/cql/cql_table_completer.py +0 -8
- adam/commands/describe/__init__.py +0 -0
- adam/commands/describe/describe.py +0 -61
- adam/commands/describe/describe_keyspace.py +0 -58
- adam/commands/describe/describe_keyspaces.py +0 -46
- adam/commands/describe/describe_schema.py +0 -46
- adam/commands/describe/describe_table.py +0 -57
- adam/commands/describe/describe_tables.py +0 -46
- adam/commands/postgres/psql_table_completer.py +0 -11
- adam/sql/state_machine.py +0 -576
- adam/utils_athena.py +0 -95
- {kaqing-2.0.102.dist-info → kaqing-2.0.105.dist-info}/WHEEL +0 -0
- {kaqing-2.0.102.dist-info → kaqing-2.0.105.dist-info}/entry_points.txt +0 -0
- {kaqing-2.0.102.dist-info → kaqing-2.0.105.dist-info}/top_level.txt +0 -0
adam/utils_athena.py
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import functools
|
|
2
|
-
import time
|
|
3
|
-
import boto3
|
|
4
|
-
|
|
5
|
-
from adam.config import Config
|
|
6
|
-
from adam.utils import lines_to_tabular, log, log2
|
|
7
|
-
|
|
8
|
-
@functools.lru_cache()
|
|
9
|
-
def audit_table_names():
|
|
10
|
-
region_name = Config().get('audit.athena.region', 'us-west-2')
|
|
11
|
-
database_name = Config().get('audit.athena.database', 'audit')
|
|
12
|
-
catalog_name = Config().get('audit.athena.catalog', 'AwsDataCatalog')
|
|
13
|
-
|
|
14
|
-
athena_client = boto3.client('athena', region_name=region_name)
|
|
15
|
-
paginator = athena_client.get_paginator('list_table_metadata')
|
|
16
|
-
|
|
17
|
-
table_names = []
|
|
18
|
-
for page in paginator.paginate(CatalogName=catalog_name, DatabaseName=database_name):
|
|
19
|
-
for table_metadata in page.get('TableMetadataList', []):
|
|
20
|
-
table_names.append(table_metadata['Name'])
|
|
21
|
-
|
|
22
|
-
return table_names
|
|
23
|
-
|
|
24
|
-
@functools.lru_cache()
|
|
25
|
-
def audit_column_names(tables: list[str] = [], database: str = None, partition_cols_only = False):
|
|
26
|
-
if not database:
|
|
27
|
-
database = Config().get('audit.athena.database', 'audit')
|
|
28
|
-
|
|
29
|
-
if not tables:
|
|
30
|
-
tables = Config().get('audit.athena.tables', 'audit').split(',')
|
|
31
|
-
|
|
32
|
-
table_names = "'" + "','".join([table.strip() for table in tables]) + "'"
|
|
33
|
-
|
|
34
|
-
query = f"select column_name from information_schema.columns where table_name in ({table_names}) and table_schema = '{database}'"
|
|
35
|
-
if partition_cols_only:
|
|
36
|
-
query = f"{query} and extra_info = 'partition key'"
|
|
37
|
-
|
|
38
|
-
_, _, rs = audit_query(query)
|
|
39
|
-
if rs:
|
|
40
|
-
return [row['Data'][0].get('VarCharValue') for row in rs[1:]]
|
|
41
|
-
|
|
42
|
-
return []
|
|
43
|
-
|
|
44
|
-
def run_audit_query(sql: str, database: str = None):
|
|
45
|
-
state, reason, rs = audit_query(sql, database)
|
|
46
|
-
|
|
47
|
-
if state == 'SUCCEEDED':
|
|
48
|
-
if rs:
|
|
49
|
-
column_info = rs[0]['Data']
|
|
50
|
-
columns = [col.get('VarCharValue') for col in column_info]
|
|
51
|
-
lines = []
|
|
52
|
-
for row in rs[1:]:
|
|
53
|
-
row_data = [col.get('VarCharValue') for col in row['Data']]
|
|
54
|
-
lines.append('\t'.join(row_data))
|
|
55
|
-
|
|
56
|
-
log(lines_to_tabular(lines, header='\t'.join(columns), separator='\t'))
|
|
57
|
-
else:
|
|
58
|
-
log2(f"Query failed or was cancelled. State: {state}")
|
|
59
|
-
log2(f"Reason: {reason}")
|
|
60
|
-
|
|
61
|
-
def audit_query(sql: str, database: str = None) -> tuple[str, str, list]:
|
|
62
|
-
athena_client = boto3.client('athena')
|
|
63
|
-
|
|
64
|
-
if not database:
|
|
65
|
-
database = Config().get('audit.athena.database', 'audit')
|
|
66
|
-
|
|
67
|
-
s3_output_location = Config().get('audit.athena.output', 's3://s3.ops--audit/ddl/results')
|
|
68
|
-
|
|
69
|
-
response = athena_client.start_query_execution(
|
|
70
|
-
QueryString=sql,
|
|
71
|
-
QueryExecutionContext={
|
|
72
|
-
'Database': database
|
|
73
|
-
},
|
|
74
|
-
ResultConfiguration={
|
|
75
|
-
'OutputLocation': s3_output_location
|
|
76
|
-
}
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
query_execution_id = response['QueryExecutionId']
|
|
80
|
-
|
|
81
|
-
while True:
|
|
82
|
-
query_status = athena_client.get_query_execution(QueryExecutionId=query_execution_id)
|
|
83
|
-
state = query_status['QueryExecution']['Status']['State']
|
|
84
|
-
if state in ['SUCCEEDED', 'FAILED', 'CANCELLED']:
|
|
85
|
-
break
|
|
86
|
-
time.sleep(1)
|
|
87
|
-
|
|
88
|
-
if state == 'SUCCEEDED':
|
|
89
|
-
results_response = athena_client.get_query_results(QueryExecutionId=query_execution_id)
|
|
90
|
-
if results_response['ResultSet']['Rows']:
|
|
91
|
-
return (state, None, results_response['ResultSet']['Rows'])
|
|
92
|
-
|
|
93
|
-
return (state, None, [])
|
|
94
|
-
else:
|
|
95
|
-
return (state, query_status['QueryExecution']['Status'].get('StateChangeReason'), [])
|
|
File without changes
|
|
File without changes
|
|
File without changes
|