Question about an error in GSQL V2 - see the picture below.
Running on TG-Cloud v. 3 in the Studio.
The ClassCode is a UINT attribute of RegionClass.
Why am I getting an error:
(52, 12) Error: no type can be inferred for s.ClassCode
Trying to declare the type in the seed like that didn’t work:
start(RegionClass) = {RegionClass.*};
The complete query code follows:
CREATE QUERY insertGradeClass(VERTEX<Country> keyCountry, VERTEX<Region> keyRegion,VERTEX<Grade> keyGrade, UINT gradeClassIndex) FOR GRAPH SkillBlasterDev syntax v2 {
STRING keyGradeClass;
STRING firstClass;
STRING nextClass;
EXCEPTION gradeClassExists (40001);
keyGradeClass = "grade-class-" + to_string(keyCountry.CountryCode) + "-" + to_string(keyGrade.GradeIndex) + "-" + to_string(gradeClassIndex);
//Does grade class exists
start = {GradeClass.*};
vGradeClass = SELECT s FROM start:s WHERE s == to_vertex(keyGradeClass, "GradeClass");
IF vGradeClass.size() > 0 THEN
RAISE gradeClassExists ("Grade Class already exists for this Grade");
END;
//If first grade class - add it as the first in the chain
start = {Grade.*};
vFirstGradeClass = SELECT t FROM start:s-()-GradeClass:t WHERE s == keyGrade
POST-ACCUM firstClass = t.id;
IF vFirstGradeClass.size() > 0 THEN
//Traverse chain to find the last regionClass
WHILE (vFirstGradeClass.size() > 0) DO
nextClass = firstClass;
vFirstGradeClass = SELECT t FROM vFirstGradeClass:s-(nextGradeClass>)-GradeClass:t
POST-ACCUM firstClass = t.id;
END;
//nextClass is the last in the chain - insert new vertex after it with edge
INSERT INTO GradeClass (PRIMARY_ID, GradeClassIndex) VALUES (
keyGradeClass, gradeClassIndex);
INSERT INTO nextGradeClass (FROM, TO) VALUES (
nextClass,
keyGradeClass
);
ELSE
//First grade class of grade to be inserted
INSERT INTO GradeClass (PRIMARY_ID, GradeClassIndex) VALUES (
keyGradeClass, gradeClassIndex);
INSERT INTO firstGradeClass (FROM, TO) VALUES (
keyGrade,
keyGradeClass
);
END;
//Add edge from newly inserted GradeClass to the matching RegionClass
start(RegionClass) = {RegionClass.*}; //Hardcoding the type for start as a workaround for V2 failing here.
//vRegionClass = SELECT s FROM start:s-(firstRegionClass:e)-Region:t WHERE s == keyGrade
vRegionClass = SELECT s FROM start:s-(*1..6)-Region:r-()-Country:t WHERE t == keyCountry AND r == keyRegion
AND s.ClassCode == gradeClassIndex;
PRINT keyGradeClass;
}