diff --git a/v6.0.0-ACv4.0.7/cqlshlib/axonOpsWorkbench/cql_desc.py b/v6.0.0-ACv4.0.7/cqlshlib/axonOpsWorkbench/cql_desc.py index 957a80d..35f04dc 100644 --- a/v6.0.0-ACv4.0.7/cqlshlib/axonOpsWorkbench/cql_desc.py +++ b/v6.0.0-ACv4.0.7/cqlshlib/axonOpsWorkbench/cql_desc.py @@ -1,12 +1,21 @@ -# Custom module to print the CQL description of an entire cluster, keyspace, or a specific table +# Custom module to print the CQL description of an entire cluster, keyspace, or a specific table, or an index from os import path import tempfile -def extractTableSchema(full_schema, keyspace_name, table_name): - tables = full_schema.split("CREATE TABLE") - for table in tables: - if f"{keyspace_name}.{table_name}" in table: - return "CREATE TABLE" + table.split(";")[0] + ";" +def extractTableSchema(full_schema, keyspace_name, table_name, index_name = None): + try: + tables = full_schema.split("CREATE TABLE") + for table in tables: + if f"{keyspace_name}.{table_name}" in table: + if index_name is None: + return "CREATE TABLE" + table.split(";")[0] + ";" + else: + parts = table.split(";") + index = list(filter(lambda statement: (index_name in statement) and ((f"{keyspace_name}.{table_name}") in statement), parts)) + return "/* Description of the index table */\n" + "CREATE TABLE" + parts[0] + ";\n\n" + "/* Description of the index */" + index[0] + ";" + except: + pass + return "" def printCQLDescBackground(id, scope, session): @@ -20,8 +29,13 @@ def printCQLDescBackground(id, scope, session): cql_desc = session.cluster.metadata.keyspaces[keyspace].export_as_string() else: # Keyspace with specific table table = parts[1] + index = table.split("index>") keyspace_schema = session.cluster.metadata.keyspaces[keyspace].export_as_string() - cql_desc = extractTableSchema(keyspace_schema, keyspace, table) + if len(index) == 1: + cql_desc = extractTableSchema(keyspace_schema, keyspace, table) + else: + cql_desc = extractTableSchema(keyspace_schema, keyspace, table[:len("index>") - 1], index[1]) + file_name = path.join(tempfile.gettempdir(), f"{id}.cqldesc") file = open(file_name,"w") file.write(f"{cql_desc}") diff --git a/v6.1.0-ACv4.1.0/cqlshlib/axonOpsWorkbench/cql_desc.py b/v6.1.0-ACv4.1.0/cqlshlib/axonOpsWorkbench/cql_desc.py index 957a80d..35f04dc 100644 --- a/v6.1.0-ACv4.1.0/cqlshlib/axonOpsWorkbench/cql_desc.py +++ b/v6.1.0-ACv4.1.0/cqlshlib/axonOpsWorkbench/cql_desc.py @@ -1,12 +1,21 @@ -# Custom module to print the CQL description of an entire cluster, keyspace, or a specific table +# Custom module to print the CQL description of an entire cluster, keyspace, or a specific table, or an index from os import path import tempfile -def extractTableSchema(full_schema, keyspace_name, table_name): - tables = full_schema.split("CREATE TABLE") - for table in tables: - if f"{keyspace_name}.{table_name}" in table: - return "CREATE TABLE" + table.split(";")[0] + ";" +def extractTableSchema(full_schema, keyspace_name, table_name, index_name = None): + try: + tables = full_schema.split("CREATE TABLE") + for table in tables: + if f"{keyspace_name}.{table_name}" in table: + if index_name is None: + return "CREATE TABLE" + table.split(";")[0] + ";" + else: + parts = table.split(";") + index = list(filter(lambda statement: (index_name in statement) and ((f"{keyspace_name}.{table_name}") in statement), parts)) + return "/* Description of the index table */\n" + "CREATE TABLE" + parts[0] + ";\n\n" + "/* Description of the index */" + index[0] + ";" + except: + pass + return "" def printCQLDescBackground(id, scope, session): @@ -20,8 +29,13 @@ def printCQLDescBackground(id, scope, session): cql_desc = session.cluster.metadata.keyspaces[keyspace].export_as_string() else: # Keyspace with specific table table = parts[1] + index = table.split("index>") keyspace_schema = session.cluster.metadata.keyspaces[keyspace].export_as_string() - cql_desc = extractTableSchema(keyspace_schema, keyspace, table) + if len(index) == 1: + cql_desc = extractTableSchema(keyspace_schema, keyspace, table) + else: + cql_desc = extractTableSchema(keyspace_schema, keyspace, table[:len("index>") - 1], index[1]) + file_name = path.join(tempfile.gettempdir(), f"{id}.cqldesc") file = open(file_name,"w") file.write(f"{cql_desc}")