Skip to content

Commit 78b0c51

Browse files
authored
Cypher: Change handling of singelton operations
Change handling of singelton operations
2 parents 89b59fa + 5ac23ed commit 78b0c51

File tree

3 files changed

+109
-66
lines changed

3 files changed

+109
-66
lines changed

cypher/queries/interactive-complex-13.cypher

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
*/
88
MATCH
99
(person1:Person {id: $person1Id}),
10-
(person2:Person {id: $person2Id})
11-
OPTIONAL MATCH
10+
(person2:Person {id: $person2Id}),
1211
path = shortestPath((person1)-[:KNOWS*]-(person2))
1312
RETURN
1413
CASE path IS NULL
1514
WHEN true THEN -1
1615
ELSE length(path)
17-
END AS shortestPathLength
16+
END AS shortestPathLength

cypher/src/main/java/org/ldbcouncil/snb/impls/workloads/cypher/CypherDb.java

Lines changed: 100 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import java.util.*;
1616
import java.util.stream.Collectors;
1717

18-
import org.neo4j.driver.Driver;
1918
import org.neo4j.driver.Record;
2019
import org.neo4j.driver.Value;
2120

@@ -479,7 +478,14 @@ public Map<String, Object> getParameters(CypherDbConnectionState state, LdbcQuer
479478
@Override
480479
public LdbcQuery13Result toResult( Record record )
481480
{
482-
return new LdbcQuery13Result( record.get( 0 ).asInt() );
481+
if(record != null)
482+
{
483+
return new LdbcQuery13Result( record.get( 0 ).asInt() );
484+
}
485+
else
486+
{
487+
return new LdbcQuery13Result(-1);
488+
}
483489
}
484490
}
485491

@@ -498,7 +504,14 @@ public Map<String, Object> getParameters(CypherDbConnectionState state, LdbcQuer
498504
@Override
499505
public LdbcQuery13Result toResult( Record record )
500506
{
501-
return new LdbcQuery13Result( record.get( 0 ).asInt() );
507+
if(record != null)
508+
{
509+
return new LdbcQuery13Result( record.get( 0 ).asInt() );
510+
}
511+
else
512+
{
513+
return new LdbcQuery13Result(-1);
514+
}
502515
}
503516
}
504517

@@ -572,23 +585,30 @@ public Map<String, Object> getParameters(CypherDbConnectionState state, LdbcShor
572585
@Override
573586
public LdbcShortQuery1PersonProfileResult toResult( Record record ) throws ParseException
574587
{
575-
String firstName = record.get( 0 ).asString();
576-
String lastName = record.get( 1 ).asString();
577-
long birthday = record.get( 2 ).asLong();
578-
String locationIP = record.get( 3 ).asString();
579-
String browserUsed = record.get( 4 ).asString();
580-
long cityId = record.get( 5 ).asLong();
581-
String gender = record.get( 6 ).asString();
582-
long creationDate = record.get( 7 ).asLong();
583-
return new LdbcShortQuery1PersonProfileResult(
584-
firstName,
585-
lastName,
586-
birthday,
587-
locationIP,
588-
browserUsed,
589-
cityId,
590-
gender,
591-
creationDate );
588+
if (record != null){
589+
String firstName = record.get( 0 ).asString();
590+
String lastName = record.get( 1 ).asString();
591+
long birthday = record.get( 2 ).asLong();
592+
String locationIP = record.get( 3 ).asString();
593+
String browserUsed = record.get( 4 ).asString();
594+
long cityId = record.get( 5 ).asLong();
595+
String gender = record.get( 6 ).asString();
596+
long creationDate = record.get( 7 ).asLong();
597+
return new LdbcShortQuery1PersonProfileResult(
598+
firstName,
599+
lastName,
600+
birthday,
601+
locationIP,
602+
browserUsed,
603+
cityId,
604+
gender,
605+
creationDate );
606+
}
607+
else
608+
{
609+
return null;
610+
}
611+
592612
}
593613
}
594614

@@ -607,21 +627,27 @@ public Map<String, Object> getParameters(CypherDbConnectionState state, LdbcShor
607627
@Override
608628
public LdbcShortQuery2PersonPostsResult toResult( Record record ) throws ParseException
609629
{
610-
long messageId = record.get( 0 ).asLong();
611-
String messageContent = record.get( 1 ).asString();
612-
long messageCreationDate = record.get( 2 ).asLong();
613-
long originalPostId = record.get( 3 ).asLong();
614-
long originalPostAuthorId = record.get( 4 ).asLong();
615-
String originalPostAuthorFirstName = record.get( 5 ).asString();
616-
String originalPostAuthorLastName = record.get( 6 ).asString();
617-
return new LdbcShortQuery2PersonPostsResult(
618-
messageId,
619-
messageContent,
620-
messageCreationDate,
621-
originalPostId,
622-
originalPostAuthorId,
623-
originalPostAuthorFirstName,
624-
originalPostAuthorLastName );
630+
if (record != null){
631+
long messageId = record.get( 0 ).asLong();
632+
String messageContent = record.get( 1 ).asString();
633+
long messageCreationDate = record.get( 2 ).asLong();
634+
long originalPostId = record.get( 3 ).asLong();
635+
long originalPostAuthorId = record.get( 4 ).asLong();
636+
String originalPostAuthorFirstName = record.get( 5 ).asString();
637+
String originalPostAuthorLastName = record.get( 6 ).asString();
638+
return new LdbcShortQuery2PersonPostsResult(
639+
messageId,
640+
messageContent,
641+
messageCreationDate,
642+
originalPostId,
643+
originalPostAuthorId,
644+
originalPostAuthorFirstName,
645+
originalPostAuthorLastName );
646+
}
647+
else
648+
{
649+
return null;
650+
}
625651
}
626652
}
627653

@@ -667,12 +693,18 @@ public Map<String, Object> getParameters(CypherDbConnectionState state, LdbcShor
667693
@Override
668694
public LdbcShortQuery4MessageContentResult toResult( Record record ) throws ParseException
669695
{
696+
if (record != null){
670697
// Pay attention, the spec's and the implementation's parameter orders are different.
671698
long messageCreationDate = record.get( 0 ).asLong();
672699
String messageContent = record.get( 1 ).asString();
673700
return new LdbcShortQuery4MessageContentResult(
674701
messageContent,
675702
messageCreationDate );
703+
}
704+
else{
705+
return null;
706+
}
707+
676708
}
677709
}
678710

@@ -691,13 +723,20 @@ public Map<String, Object> getParameters(CypherDbConnectionState state, LdbcShor
691723
@Override
692724
public LdbcShortQuery5MessageCreatorResult toResult( Record record )
693725
{
694-
long personId = record.get( 0 ).asLong();
695-
String firstName = record.get( 1 ).asString();
696-
String lastName = record.get( 2 ).asString();
697-
return new LdbcShortQuery5MessageCreatorResult(
698-
personId,
699-
firstName,
700-
lastName );
726+
if (record != null){
727+
long personId = record.get( 0 ).asLong();
728+
String firstName = record.get( 1 ).asString();
729+
String lastName = record.get( 2 ).asString();
730+
return new LdbcShortQuery5MessageCreatorResult(
731+
personId,
732+
firstName,
733+
lastName );
734+
}
735+
else
736+
{
737+
return null;
738+
}
739+
701740
}
702741
}
703742

@@ -716,17 +755,25 @@ public Map<String, Object> getParameters(CypherDbConnectionState state, LdbcShor
716755
@Override
717756
public LdbcShortQuery6MessageForumResult toResult( Record record )
718757
{
719-
long forumId = record.get( 0 ).asLong();
720-
String forumTitle = record.get( 1 ).asString();
721-
long moderatorId = record.get( 2 ).asLong();
722-
String moderatorFirstName = record.get( 3 ).asString();
723-
String moderatorLastName = record.get( 4 ).asString();
724-
return new LdbcShortQuery6MessageForumResult(
725-
forumId,
726-
forumTitle,
727-
moderatorId,
728-
moderatorFirstName,
729-
moderatorLastName );
758+
if (record != null)
759+
{
760+
761+
long forumId = record.get( 0 ).asLong();
762+
String forumTitle = record.get( 1 ).asString();
763+
long moderatorId = record.get( 2 ).asLong();
764+
String moderatorFirstName = record.get( 3 ).asString();
765+
String moderatorLastName = record.get( 4 ).asString();
766+
return new LdbcShortQuery6MessageForumResult(
767+
forumId,
768+
forumTitle,
769+
moderatorId,
770+
moderatorFirstName,
771+
moderatorLastName );
772+
}
773+
else
774+
{
775+
return null;
776+
}
730777
}
731778
}
732779

cypher/src/main/java/org/ldbcouncil/snb/impls/workloads/cypher/operationhandlers/CypherSingletonOperationHandler.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,17 @@ public void executeOperation( TOperation operation, CypherDbConnectionState stat
3838
final Result result = session.run( query, parameters );
3939
if ( result.hasNext() )
4040
{
41-
try
42-
{
43-
resultReporter.report( 1, toResult( result.next() ), operation );
44-
final ResultSummary summary = result.consume();
45-
}
46-
catch ( ParseException e )
47-
{
48-
throw new DbException( e );
49-
}
41+
resultReporter.report( 1, toResult( result.next() ), operation );
42+
final ResultSummary summary = result.consume();
5043
}
5144
else
5245
{
53-
resultReporter.report( 0, null, operation );
46+
resultReporter.report( 0, toResult(null), operation );
5447
}
5548
}
49+
catch ( ParseException e )
50+
{
51+
throw new DbException( e );
52+
}
5653
}
5754
}

0 commit comments

Comments
 (0)