# Data loading to Schema

**URL:** <https://forum.typedb.com/t/data-loading-to-schema/199>\
**Category:** TypeDB\
**Tags:** schema-design\
**Created:** [10 September 2022 09:27 UTC](https://forum.typedb.com/t/data-loading-to-schema/199 "2022-09-10T09:27:19Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mamngri](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/mamngri/32/65_2.png) [@mamngri](https://forum.typedb.com/u/mamngri)\
**Post date:** [10 September 2022 09:27 UTC](https://forum.typedb.com/t/data-loading-to-schema/199/1 "2022-09-10T09:27:19Z")

</div>

my data is successfully loading to schema via Python client … and when I am accessing by query I can access data of all relations and all entities successfully … but one relation named “exp” is returning null not returning the loaded data … following screenshots can show you the successfully loaded data, return null on query respectively…

 ![qqq](https://europe1.discourse-cdn.com/flex005/uploads/vaticle/original/1X/c34beacd889ec3e9e398abdf0fde85331a690b8b.png)

---

<div class="post-metadata">

**Author:** ![alex](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/alex/32/148_2.png) [@alex](https://forum.typedb.com/u/alex)\
**Post date:** [12 September 2022 09:33 UTC](https://forum.typedb.com/t/data-loading-to-schema/199/2 "2022-09-12T09:33:52Z")

</div>

Can you show the source code used to load the data?

Perhaps you’re forgetting to **commit** the transaction?

---

<div class="post-metadata">

**Author:** ![mamngri](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/mamngri/32/65_2.png) [@mamngri](https://forum.typedb.com/u/mamngri)\
**Post date:** [12 September 2022 12:50 UTC](https://forum.typedb.com/t/data-loading-to-schema/199/3 "2022-09-12T12:50:55Z")

</div>

thanks for the response yes I can show it.

---

<div class="post-metadata">

**Author:** ![mamngri](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/mamngri/32/65_2.png) [@mamngri](https://forum.typedb.com/u/mamngri)\
**Post date:** [12 September 2022 13:16 UTC](https://forum.typedb.com/t/data-loading-to-schema/199/4 "2022-09-12T13:16:58Z")

</div>

please check the above code. the data is loaded to schema successfully but the problem is when I am trying to get data it only returns an empty array. the problem is only in the last relationship named “exp”

---

<div class="post-metadata">

**Author:** ![alex](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/alex/32/148_2.png) [@alex](https://forum.typedb.com/u/alex)\
**Post date:** [12 September 2022 13:41 UTC](https://forum.typedb.com/t/data-loading-to-schema/199/5 "2022-09-12T13:41:08Z")

</div>

Hi @mamngri - sorry, I don’t see any code?

---

<div class="post-metadata">

**Author:** ![mamngri](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/mamngri/32/65_2.png) [@mamngri](https://forum.typedb.com/u/mamngri)\
**Post date:** [12 September 2022 14:30 UTC](https://forum.typedb.com/t/data-loading-to-schema/199/6 "2022-09-12T14:30:39Z")

</div>

Please check the below file

(Attachment Doc1.pdf is missing)

---

<div class="post-metadata">

**Author:** ![mamngri](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/mamngri/32/65_2.png) [@mamngri](https://forum.typedb.com/u/mamngri)\
**Post date:** [12 September 2022 14:33 UTC](https://forum.typedb.com/t/data-loading-to-schema/199/7 "2022-09-12T14:33:03Z")

</div>

I can’t attach more than one screenshot system not allowing me I don’t know why

 ![page 3.PNG](https://europe1.discourse-cdn.com/flex005/uploads/vaticle/original/1X/fc749b915b652689ca0a25d69cddc867e719905e.png)

---

<div class="post-metadata">

**Author:** ![alex](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/alex/32/148_2.png) [@alex](https://forum.typedb.com/u/alex)\
**Post date:** [12 September 2022 14:53 UTC](https://forum.typedb.com/t/data-loading-to-schema/199/8 "2022-09-12T14:53:13Z")

</div>

Hi there, a screenshot of code is not really ideal - it would be more helpful to copy and paste the code into your post, formatted in a [code block](https://www.markdownguide.org/extended-syntax/#fenced-code-blocks).

Anyhow, there are 3 possible issues here:

1. the `match` block in your match-insert is not returning any results, therefore no data is inserted. You can verify this by just running the `match` portion.
2. You aren’t [committing the transaction](https://docs.vaticle.com/docs/client-api/python#commit-a-write-transaction).
3. Some other bug in the code causes the insert query to not run.

---

<div class="post-metadata">

**Author:** ![mamngri](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/mamngri/32/65_2.png) [@mamngri](https://forum.typedb.com/u/mamngri)\
**Post date:** [12 September 2022 15:25 UTC](https://forum.typedb.com/t/data-loading-to-schema/199/9 "2022-09-12T15:25:06Z")

</div>

please see this code the above-mentioned 3 possible issues are not in my code…

```auto
from typedb.client import TypeDB, SessionType, TransactionType
import csv

def build_BioKGdb_graph(inputs):
with TypeDB.core_client("localhost:1729") as client:
with client.session("BioKGdb", SessionType.DATA) as session:
for input in inputs:
print("Loading from [" + input["data_path"] + "] into TypeDB ...")
load_data_into_typedb(input, session)

def load_data_into_typedb(input, session):
items = parse_data_to_dictionaries(input)

with session.transaction(TransactionType.WRITE) as transaction:
for item in items:
typeql_insert_query = input["template"](item)
print("Executing TypeQL Query: " + typeql_insert_query)
transaction.query().insert(typeql_insert_query)
transaction.commit()

print("\nInserted " + str(len(items)) + " items from [" + input["data_path"] + "] into TypeDB.\n")

def parse_data_to_dictionaries(input):
items = []
with open(input["data_path"] + ".csv") as data: # 1
for row in csv.DictReader(data, skipinitialspace = True):
item = { key: value for key, value in row.items() }
items.append(item) # 2
return items

#entity
#cancer template
def cancer_template(cancer):
#insert query for cancer
typeql_insert_query = 'insert $cancer isa cancer, has cancer-id "' + cancer["Cancer_ID"] + '"'
typeql_insert_query += ', has cancer-type "' + cancer["Cancer_Type"] + '"'
typeql_insert_query += ', has cancer-type-detail "' + cancer["Cancer_Type_Detailed"] + '"'
typeql_insert_query += ', has oncotree-code "' + cancer["Oncotree_Code"] + '"'
typeql_insert_query += ', has ICD-10-classification "' + cancer["ICD-10_Classification"] + '"'
typeql_insert_query += ', has international-classification-of-diseases-for-oncology-3rd-edition-ICD-O-3-histology-code "' + cancer["International_Classification_of_Diseases_for_Oncology,_Third_Edition_ICD-O-3_Histology_Code"] + '"'
typeql_insert_query += ', has international-classification-of-diseases-for-oncology-3rd-edition-ICD-O-3-site-code "' + cancer["International_Classification_of_Diseases_for_Oncology,_Third_Edition_ICD-O-3_Site_Code"] + '"'
typeql_insert_query += ', has year-cancer-initial-diagnosis "' + cancer["Year_Cancer_Initial_Diagnosis"] + '"'
typeql_insert_query += ', has primary-tumor-laterality "' + cancer["Primary_Tumor_Laterality"] + '"'
typeql_insert_query += ', has fraction-genomic-altered "' + cancer["Fraction_Genome_Altered"] + '"'
typeql_insert_query += ', has extrathyroidal-extension "' + cancer["Extrathyroidal_Extension"] + '"'
typeql_insert_query += ";"
return typeql_insert_query

#entity
#sample template
def sample_template(sample):
#insert cancer
typeql_insert_query = 'insert $sample isa sample, has sample-id "' + sample["Sample_ID"] + '"'
typeql_insert_query += ', has sample-type "' + sample["Sample_Type"] + '"'
typeql_insert_query += ', has sample-type-id "' + sample["Sample_Type_ID"] + '"'
typeql_insert_query += ', has other-sample-id "' + sample["Other_Sample_ID"] + '"'
typeql_insert_query += ', has sample-initial-weight "' + sample["Sample_Initial_Weight"] + '"'
typeql_insert_query += ', has days-to-sample-collection"' + sample["Days_to_Sample_Collection"] + '"'
typeql_insert_query += ', has number-of-samples-per-patient "' + sample["Number_of_Samples_Per_Patient"] + '"'
typeql_insert_query += ', has vial-number "' + sample["Vial_number"] + '"'
typeql_insert_query += ";"
return typeql_insert_query

#entity
#tumorstagging template
def tumor_stagging_template(tumorstagging):
#insert tumorstagging
typeql_insert_query = 'insert $tumorstagging isa tumorstagging, has tumor-stagging-id "' + tumorstagging["Tumor_Stagging_ID"] + '"'
typeql_insert_query += ', has american-joint-committee-on-cancer-publication-version-type "' + tumorstagging["American_Joint_Committee_on_Cancer_Publication_Version_Type"] + '"'
typeql_insert_query += ";"
return typeql_insert_query

#entity
#person template
def person_template(person):
#insert person
typeql_insert_query = 'insert $person isa person, has patient-id "' + person["Patient_ID"] + '"'
typeql_insert_query += ', has other-patient-id "' + person["Other_Patient_ID"] + '"'
typeql_insert_query += ', has sex "' + person["Sex"] + '"'
typeql_insert_query += ', has diagnosis-age "' + person["Diagnosis_Age"] + '"'
typeql_insert_query += ', has race-category "' + person["Race_Category"] + '"'
typeql_insert_query += ', has form-completion-date"' + person["Form_completion_date"] + '"'
typeql_insert_query += ', has ethnicity-category "' + person["Ethnicity_Category"] + '"'
typeql_insert_query += ";"
return typeql_insert_query

#entity
#program template
def program_template(program):
#insert person
return'insert $program isa program, has name "' + program["Program_Name"] + '";'

#entity
#gene template
def gene_template(gene):
#insert genes
typeql_insert_query='insert $gene isa gene, has entrez-id"' + gene["Entrez_ID"] + '"'
typeql_insert_query += ', has hugo-symbol"' + gene["Hugo_Symbol"]+'"'
typeql_insert_query += ";"
return typeql_insert_query

```

---

<div class="post-metadata">

**Author:** ![mamngri](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/mamngri/32/65_2.png) [@mamngri](https://forum.typedb.com/u/mamngri)\
**Post date:** [14 September 2022 15:21 UTC](https://forum.typedb.com/t/data-loading-to-schema/199/10 "2022-09-14T15:21:11Z")

</div>

@alex please check the above code my error is still solved …

---

<div class="post-metadata">

**Author:** ![alex](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/alex/32/148_2.png) [@alex](https://forum.typedb.com/u/alex)\
**Post date:** [15 September 2022 13:33 UTC](https://forum.typedb.com/t/data-loading-to-schema/199/11 "2022-09-15T13:33:58Z")

</div>

@mamngri Could you possibly produce a minimal reproducible example of the issue? The code is too long to be easily examined in its current form.
