MCPcopy Create free account
hub / github.com/SeldonIO/seldon-server / addAttrsToDb

Function addAttrsToDb

python/seldon/shell/attr_schema_utils.py:21–49  ·  view source on GitHub ↗
(db, attrs, item_type)

Source from the content-addressed store, hash-verified

19 return False
20
21def addAttrsToDb(db, attrs, item_type):
22 if not hasAttr(attrs,"content_type"):
23 attrs.append({"name":"content_type", "value_type":["article"]})
24 for attr in attrs:
25 print "adding item type",item_type,"attribute ",attr['name']
26 attrValType = attr['value_type']
27 if type(attrValType) is list:
28 attrValType = 'enum'
29 cur = db.cursor()
30 cur.execute("INSERT INTO ITEM_ATTR (name, type, item_type) "
31 + " VALUES (%s, %s, %s)", (attr['name'], value_types_to_db_map[attrValType], item_type))
32 if attrValType is 'enum':
33 for index,enum in enumerate(attr['value_type'], start=1):
34 cur = db.cursor()
35 cur.execute("SELECT attr_id FROM ITEM_ATTR WHERE NAME = %s and ITEM_TYPE = %s", (attr['name'],item_type))
36 rows = cur.fetchall()
37 attrId = rows[0][0]
38 cur = db.cursor()
39 cur.execute("INSERT INTO ITEM_ATTR_ENUM (attr_id, value_id, value_name) VALUES (%s, %s, %s)",(attrId, index, enum))
40 cur = db.cursor()
41 cur.execute("SELECT e.attr_id, e.value_id, e.value_name FROM ITEM_ATTR_ENUM e join item_attr a on (a.attr_id=e.attr_id and a.item_type=%s)",(item_type,))
42 rows = cur.fetchall()
43 for row in rows:
44 enum_attr_id = row[0]
45 enum_value_id = row[1]
46 enum_value_name = row[2]
47 cur = db.cursor()
48 cur.execute("INSERT INTO DIMENSION (item_type, attr_id, value_id) VALUES"
49 + " (%s, %s, %s)", (item_type, enum_attr_id, enum_value_id))
50
51def doDbChecks(db):
52 cur = db.cursor()

Callers 1

addToDbFunction · 0.70

Calls 2

hasAttrFunction · 0.85
executeMethod · 0.65

Tested by

no test coverage detected