Skip to content

Commit

Permalink
Merge pull request #18 from axonops/for-issue-330
Browse files Browse the repository at this point in the history
For issue #330
  • Loading branch information
millerjp authored Sep 10, 2024
2 parents f5b5caa + fc94160 commit b708fba
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
28 changes: 21 additions & 7 deletions v6.0.0-ACv4.0.7/cqlshlib/axonOpsWorkbench/cql_desc.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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}")
Expand Down
28 changes: 21 additions & 7 deletions v6.1.0-ACv4.1.0/cqlshlib/axonOpsWorkbench/cql_desc.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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}")
Expand Down

0 comments on commit b708fba

Please sign in to comment.