Package vsql_core :: Package catalog :: Module SchemaHelper
[hide private]
[frames] | no frames]

Source Code for Module vsql_core.catalog.SchemaHelper

 1  """ 
 2  This is responsible for building the metadata tables used by 
 3  VictorSQL to maintain multiple model descriptions and model 
 4  instances. 
 5  """ 
 6   
 7  tuple_values = ["name", "objective", "objective_item", "grad", "prox", "model_type", "data_type"] 
 8  types_names  = ["model_type", "data_type"] 
9 -def make_create_model_statements(l):
10 """ 11 Creates model table and insert it into the Victor_Models table 12 13 @type l: vector 14 @param l: contains index and values in the vector 15 16 @rtype: string 17 @return: insert model and create model table queries 18 """ 19 d = dict(); 20 for (k,v) in l: 21 d[k] = v 22 vals = [] 23 for t in tuple_values: 24 if t in d: 25 if t in types_names: 26 vals.append('(' + ','.join(d[t]) + ')') 27 else: 28 vals.append(d[t]) 29 else: 30 vals.append("NULL") 31 ret = "INSERT INTO Victor_Models VALUES (" +','.join(vals) + ");\n" 32 # now build the table 33 ret += "CREATE TABLE " + d["name"] + "(model_name varchar(1024), instance_name varchar(1024),\n" 34 ret += "\tmodel_instance_id int, data_query varchar(4096),\n\t" 35 model_t = d["model_type"] 36 zz = ["serialized_model_" + str(i) + " " + model_t[i] for i in range(len(model_t))] 37 ret += ',\n\t'.join(zz) + ',\n' 38 ret += "\tFOREIGN KEY (model_name) REFERENCES Victor_Models(name),\n" 39 ret += "\tPRIMARY KEY (instance_name));" 40 return ret
41
42 -def make_create_model_instance(l):
43 """ 44 Creates INSERT statement for the given model instance 45 @type l: tuple 46 @param l: tuple that contains name, model name data view, k, values and initial value 47 """ 48 (name, mname, (data_view,k,vals), initial_model) = l 49 ret = "INSERT INTO Victor_global_instances(model_name) VALUES ('" + name + "');\n"; 50 mid_query = "SELECT mid FROM Victor_global_instances where model_name = '" + name + "'";
51 #ret += "INSERT INTO " + mname + " VALUES (" 52