Hello I want to get the name of all tables in a cllection, but I do not know to do it.
I write this line
Tablas = RS.Collection.list(workspace = WorkSpace)
for tabla in Tablas:
print(type(tabla))
print(tabla)
tabla is <class ‘rockset.collection.Collection’>
I want to get the key name
For example
{‘client’: <rockset.client.Client object at 0x7f313071e950>, ‘workspace’: ‘sandbox’, ‘name’: ‘Transactions’, ‘dropped’: False, …}
When I write print(tabla[‘name’]) this is the error
<class ‘rockset.collection.Collection’>
Traceback (most recent call last):
…
print(tabla[‘name’])
TypeError: ‘Collection’ object is not subscriptable
How can I get data o transform rockset.collection.Collection in json object to choose all values of this data?
def ListaColecciones(Credenciales, WorkSpace):
'''
Dadas unas credenciales válidas y un workspace (espquema de BBDD) válido
devolvemos la lista de tablas que tiene ese esquema
'''
import json
from rockset import Client, exception
RS = ClienteRD(Credenciales)
ListaTablas = []
try:
Tablas = RS.Collection.list(workspace = WorkSpace)
for tabla in Tablas:
# Convierto el objeto de Rockset en un diccionario de datos, usando un string como ayuda
str_data = str(tabla).replace("'", '"')
str_data = str_data.replace("False", 'false')
str_data = str_data.replace("True", 'true')
str_data = str_data.replace(": None", ": null")
Aux = str_data.split(',') # Parto la cadena de caracteres y quito el primer elemento
i = 0
while i < len(Aux):
if i == 0:
AuxString = '{'
else:
if i == 1:
AuxString = AuxString + Aux[i]
else:
AuxString = AuxString + ',' + Aux[i]
i = i + 1
json_object = json.loads(AuxString)
if "name" in json_object:
ListaTablas.append(json_object['name'])
except:
print('No he podido conectar')
return ListaTablas
def ClienteRD(Credenciales):
'''
Devuelvo un cliente RS
'''
from rockset import Client, exception
rs = Client(api_key=Credenciales['Clave_Api'], api_server=Credenciales['ServidorRockSet'])
# Esto no valida nada contra la máquina
return rs