missing_selects.append("case when i{}=1 then NULL ELSE {} END".format(v,v))
elifnotv.lower().startswith('i'):
elifis_var(v):
missing_selects.append(v)
missing_data_table="{}_star".format(table_name)
deletion_sql="DROP TABLE IF EXISTS {};".format(missing_data_table)
cursor.execute(deletion_sql)
missing_data_sql="CREATE TABLE {} AS SELECT {} FROM {}".format(missing_data_table,",".join(missing_selects),table_name)
missing_selects_text=",".join(missing_selects)
missing_data_sql="CREATE TABLE {} AS SELECT {}, md5(CAST(({}) AS text)) AS superblock FROM {}".format(missing_data_table,missing_selects_text,missing_selects_text,table_name)
print(missing_data_sql)
cursor.execute(missing_data_sql)
# superblock definitions
superblock_table="{}_sb".format(table_name)
deletion_sql="DROP TABLE IF EXISTS {};".format(superblock_table)
cursor.execute(deletion_sql)
vars=list(filter(is_var,var_names))
col_def=map(lambdaname:"{} int NOT NULL".format(name),vars)
creation_sql="CREATE TABLE {}(superblock text, {}, prob float NOT NULL);".format(superblock_table,",".join(col_def))
cursor.execute(creation_sql)
cursor.execute("SELECT DISTINCT * FROM {}".format(missing_data_table))
ie=gum.LazyPropagation(bn)
insert_sql="INSERT INTO {}({}, superblock, prob) VALUES({},%s,%s)".format(superblock_table,",".join(vars),",".join(["%s"for_invars]))