Data loading to Schema

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…

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

Perhaps you’re forgetting to commit the transaction?

thanks for the response yes I can show it.

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”

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

Please check the below file

(Attachment Doc1.pdf is missing)

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

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.

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.
  3. Some other bug in the code causes the insert query to not run.

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

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

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

@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.