Skip to content

Commit f87569a

Browse files
Ajit GeorgeAjit George
authored andcommitted
Fix for Git Issue 528 and 537
1 parent e5992b9 commit f87569a

File tree

1 file changed

+80
-13
lines changed

1 file changed

+80
-13
lines changed

test-complete/src/test/java/com/marklogic/client/functionaltest/TestOpticOnTriples.java

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import com.marklogic.client.expression.PlanBuilder.ExportablePlan;
5050
import com.marklogic.client.expression.PlanBuilder.ModifyPlan;
5151
import com.marklogic.client.expression.PlanBuilder.ViewPlan;
52+
import com.marklogic.client.expression.SemExpr;
5253
import com.marklogic.client.io.DocumentMetadataHandle;
5354
import com.marklogic.client.io.FileHandle;
5455
import com.marklogic.client.io.JacksonHandle;
@@ -61,6 +62,8 @@
6162
import com.marklogic.client.type.PlanSystemColumn;
6263
import com.marklogic.client.type.PlanTriplePatternSeq;
6364
import com.marklogic.client.type.PlanTripleVal;
65+
import com.marklogic.client.type.SemIriSeqVal;
66+
import com.marklogic.client.type.SemStoreExpr;
6467
import com.marklogic.client.type.XsStringVal;
6568

6669
public class TestOpticOnTriples extends BasicJavaClientREST {
@@ -684,9 +687,8 @@ public void testJoinInnerWithGraphIRI() throws KeyManagementException, NoSuchAlg
684687
public void testJoinInnerWithSemStore() throws KeyManagementException, NoSuchAlgorithmException, IOException, SAXException, ParserConfigurationException
685688
{
686689
System.out.println("In testJoinInnerWithSemStore method");
687-
// TODO Uncomment when Git #537 is fixed for sem.store ambiguous issue.
688690

689-
/*// Create a new Plan.
691+
// Create a new Plan.
690692
RowManager rowMgr = client.newRowManager();
691693
PlanBuilder p = rowMgr.newPlanBuilder();
692694
PlanBuilder.Prefixer bb = p.prefixer("http://marklogic.com/baseball/players");
@@ -707,14 +709,16 @@ public void testJoinInnerWithSemStore() throws KeyManagementException, NoSuchAlg
707709
p.pattern(playerIdCol, bb.iri("name"), playerNameCol),
708710
p.pattern(playerIdCol, bb.iri("team"), playerTeamCol)
709711
);
710-
711-
ModifyPlan player_plan = p.fromTriples(patPlayerSeq, null, p.sem.store("/optic/player/triple/test", "/optic/team/triple/test"),
712+
SemIriSeqVal storeIris = p.sem.iris("/optic/player/triple/test", "/optic/team/triple/test" );
713+
SemStoreExpr storeExpr = p.sem.store("any");
714+
ModifyPlan player_plan = p.fromTriples(patPlayerSeq, (String)null, storeExpr,
712715
p.tripleOptions(PlanBuilder.PlanTriples.DEDUPLICATED));
713-
716+
714717
PlanTriplePatternSeq patTeamSeq = p.patterns(p.pattern(teamIdCol, tm.iri("name"), teamNameCol),
715718
p.pattern(teamIdCol, tm.iri("city"), teamCityCol)
716719
);
717720
ModifyPlan team_plan = p.fromTriples(patTeamSeq,
721+
(String)null,
718722
null,
719723
null,
720724
p.tripleOptions(PlanBuilder.PlanTriples.DEDUPLICATED)
@@ -739,17 +743,47 @@ public void testJoinInnerWithSemStore() throws KeyManagementException, NoSuchAlg
739743
assertEquals("Row 1 PlayerName value incorrect", "Juan Leone", jsonResults.get(0).path("PlayerName").path("value").asText());
740744
assertEquals("Row 1 PlayerAge value incorrect", "27", jsonResults.get(0).path("PlayerAge").path("value").asText());
741745
assertEquals("Row 1 TeamName value incorrect", "San Francisco Giants", jsonResults.get(0).path("TeamName").path("value").asText());
742-
assertEquals("Row 1 GraphName value incorrect", "/optic/player/triple/test", jsonResults.get(0).path("GraphName").path("value").asText());
743746

744747
assertEquals("Row 2 PlayerName value incorrect", "Josh Ream", jsonResults.get(1).path("PlayerName").path("value").asText());
745748
assertEquals("Row 2 PlayerAge value incorrect", "29", jsonResults.get(1).path("PlayerAge").path("value").asText());
746749
assertEquals("Row 2 TeamName value incorrect", "San Francisco Giants", jsonResults.get(1).path("TeamName").path("value").asText());
747-
assertEquals("Row 2 GraphName value incorrect", "/optic/player/triple/test", jsonResults.get(1).path("GraphName").path("value").asText());
748750

749751
assertEquals("Row 3 PlayerName value incorrect", "John Doe", jsonResults.get(2).path("PlayerName").path("value").asText());
750752
assertEquals("Row 3 PlayerAge value incorrect", "31", jsonResults.get(2).path("PlayerAge").path("value").asText());
751753
assertEquals("Row 3 TeamName value incorrect", "San Francisco Giants", jsonResults.get(2).path("TeamName").path("value").asText());
752-
assertEquals("Row 3 GraphName value incorrect", "/optic/player/triple/test", jsonResults.get(2).path("GraphName").path("value").asText());*/
754+
755+
// Verify overloaded fromTriples() with graphIRI
756+
ModifyPlan player_plan1 = p.fromTriples(patPlayerSeq, (String)null, "/optic/player/triple/test", null, p.tripleOptions(PlanBuilder.PlanTriples.DEDUPLICATED));
757+
ModifyPlan output1 = player_plan.joinInner(team_plan)
758+
.where(p.eq(teamNameCol, p.xs.string("Giants")))
759+
.orderBy(p.asc(playerAgeCol))
760+
.select(
761+
p.as("PlayerName", playerNameCol),
762+
p.as("PlayerAge", playerAgeCol),
763+
p.as("TeamName", p.fn.concat(teamCityCol, p.xs.string(" "), teamNameCol)),
764+
p.as("PlayerGraph", playerGraphCol));
765+
jacksonHandle = new JacksonHandle();
766+
jacksonHandle.setMimetype("application/json");
767+
768+
rowMgr.resultDoc(output1, jacksonHandle);
769+
jsonResults = jacksonHandle.get().path("rows");
770+
771+
// Should have 3 nodes returned.
772+
assertEquals("Three nodes not returned from testJoinInnerWithGraphIRI method ", 3, jsonResults.size());
773+
assertEquals("Row 1 PlayerName value incorrect", "Juan Leone", jsonResults.get(0).path("PlayerName").path("value").asText());
774+
assertEquals("Row 1 PlayerAge value incorrect", "27", jsonResults.get(0).path("PlayerAge").path("value").asText());
775+
assertEquals("Row 1 TeamName value incorrect", "San Francisco Giants", jsonResults.get(0).path("TeamName").path("value").asText());
776+
assertEquals("Row 1 GraphName value incorrect", "/optic/player/triple/test", jsonResults.get(0).path("PlayerGraph").path("value").asText());
777+
778+
assertEquals("Row 2 PlayerName value incorrect", "Josh Ream", jsonResults.get(1).path("PlayerName").path("value").asText());
779+
assertEquals("Row 2 PlayerAge value incorrect", "29", jsonResults.get(1).path("PlayerAge").path("value").asText());
780+
assertEquals("Row 2 TeamName value incorrect", "San Francisco Giants", jsonResults.get(1).path("TeamName").path("value").asText());
781+
assertEquals("Row 2 GraphName value incorrect", "/optic/player/triple/test", jsonResults.get(1).path("PlayerGraph").path("value").asText());
782+
783+
assertEquals("Row 3 PlayerName value incorrect", "John Doe", jsonResults.get(2).path("PlayerName").path("value").asText());
784+
assertEquals("Row 3 PlayerAge value incorrect", "31", jsonResults.get(2).path("PlayerAge").path("value").asText());
785+
assertEquals("Row 3 TeamName value incorrect", "San Francisco Giants", jsonResults.get(2).path("TeamName").path("value").asText());
786+
assertEquals("Row 3 GraphName value incorrect", "/optic/player/triple/test", jsonResults.get(2).path("PlayerGraph").path("value").asText());
753787
}
754788

755789
/* This test checks access with qualifier.
@@ -1371,7 +1405,7 @@ public void testNullAvgFunction() throws KeyManagementException, NoSuchAlgorithm
13711405
@Test
13721406
public void testFromTriplesWithbindParam() throws KeyManagementException, NoSuchAlgorithmException, IOException, SAXException, ParserConfigurationException
13731407
{
1374-
/*System.out.println("In testFromTriplesWithbindParam method");
1408+
System.out.println("In testFromTriplesWithbindParam method");
13751409

13761410
// Create a new Plan.
13771411
RowManager rowMgr = client.newRowManager();
@@ -1388,16 +1422,49 @@ public void testFromTriplesWithbindParam() throws KeyManagementException, NoSuch
13881422
ModifyPlan player_plan = p.fromTriples(p.pattern(playerIdCol, bb.iri("age"), ageParam),
13891423
p.pattern(playerIdCol, bb.iri("name"), playerNameCol),
13901424
p.pattern(playerIdCol, bb.iri("team"), playerTeamCol));
1391-
player_plan.bindParam(ageParam, p.xs.intVal(26));
1425+
player_plan.bindParam(ageParam, p.xs.intVal(27));
13921426
JacksonHandle jacksonHandle = new JacksonHandle();
13931427
jacksonHandle.setMimetype("application/json");
13941428

13951429
rowMgr.resultDoc(player_plan, jacksonHandle);
13961430
JsonNode jsonResults = jacksonHandle.get();
13971431
JsonNode jsonBindingsNodes = jsonResults.path("rows");
1398-
// Should have 13 nodes returned.
1399-
assertEquals("Thirteen nodes not returned from testFromTriplesWithbindParam method ", 13, jsonBindingsNodes.size());
1400-
*/}
1432+
// Should have 1 nodes returned.
1433+
assertEquals("One node not returned from testFromTriplesWithbindParam method ", 1, jsonBindingsNodes.size());
1434+
assertEquals("Row 1 player name value incorrect", "Juan Leone", jsonBindingsNodes.path(0).path("player_name").path("value").asText());
1435+
assertEquals("Row 1 player team value incorrect", "http://marklogic.com/mlb/team/id/001", jsonBindingsNodes.path(0).path("player_team").path("value").asText());
1436+
1437+
// Verify bind value with different types, values.
1438+
player_plan.bindParam(ageParam, p.xs.intVal(0));
1439+
jacksonHandle = new JacksonHandle();
1440+
jacksonHandle.setMimetype("application/json");
1441+
1442+
rowMgr.resultDoc(player_plan, jacksonHandle);
1443+
jsonResults = jacksonHandle.get();
1444+
1445+
assertTrue("No data should have been returned", jsonResults == null);
1446+
1447+
// Should not throw an exception, but return null results
1448+
player_plan.bindParam(ageParam, p.xs.intVal(-1));
1449+
jacksonHandle = new JacksonHandle();
1450+
jacksonHandle.setMimetype("application/json");
1451+
1452+
rowMgr.resultDoc(player_plan, jacksonHandle);
1453+
jsonResults = jacksonHandle.get();
1454+
// Should have null nodes returned.
1455+
assertTrue("No data should have been returned", jsonResults == null);
1456+
1457+
// Should not throw an exception, but return null results
1458+
player_plan.bindParam(ageParam, p.xs.string("abcd"));
1459+
jacksonHandle = new JacksonHandle();
1460+
jacksonHandle.setMimetype("application/json");
1461+
1462+
rowMgr.resultDoc(player_plan, jacksonHandle);
1463+
jsonResults = jacksonHandle.get();
1464+
// Should have null nodes returned.
1465+
assertTrue("No data should have been returned", jsonResults == null);
1466+
1467+
}
14011468

14021469
@AfterClass
14031470
public static void tearDownAfterClass() throws Exception

0 commit comments

Comments
 (0)