/** * Mock a managed LDAP schema violation */ @Test public void removeUserSchema() { thrown.expect(ValidationJsonException.class); thrown.expect(MatcherUtil.validationMatcher("groups", "last-member-of-group")); final GroupLdapRepository groupRepository = new GroupLdapRepository() { @Override public GroupOrg findById(final String name) { // The group has only the user user we want to remove return new GroupOrg("dc=" + name, name, Collections.singleton("flast1")); } }; groupRepository.setLdapCacheRepository(Mockito.mock(LdapCacheRepository.class)); final LdapTemplate ldapTemplate = Mockito.mock(LdapTemplate.class); groupRepository.setTemplate(ldapTemplate); Mockito.doThrow(new org.springframework.ldap.SchemaViolationException(new SchemaViolationException("any"))).when(ldapTemplate) .modifyAttributes(ArgumentMatchers.any(LdapName.class), ArgumentMatchers.any()); removeUser(groupRepository); }
@Override public void rename(Name nOld, Name nNew) throws NamingException { if (nOld == null || nNew == null) { throw new NullPointerException(); } if (nOld.size() == 0 || nNew.size() == 0) { // ldap.3A=Can't rename empty name throw new InvalidNameException(Messages.getString("ldap.3A")); //$NON-NLS-1$ } if (nOld.size() > 1 || nNew.size() > 1) { // ldap.3B=Can't rename across contexts throw new InvalidNameException(Messages.getString("ldap.3B")); //$NON-NLS-1$ } // ldap.39=Can't rename schema throw new SchemaViolationException(Messages.getString("ldap.39")); //$NON-NLS-1$ }
@Override public void executeOperation(final LdbcShortQuery4MessageContent operation,TitanFTMDb.BasicDbConnectionState dbConnectionState,ResultReporter resultReporter) throws DbException { long mid = operation.messageId(); TitanFTMDb.BasicClient client = dbConnectionState.client(); Vertex m; try { logger.debug("Short Query 4 called on message id: {}", mid); m = client.getVertex(mid, "Comment"); if (m==null) m = client.getVertex(mid, "Post"); String content = m.getProperty("content"); if (content.length() == 0) content = m.getProperty("imageFile"); LdbcShortQuery4MessageContentResult res = new LdbcShortQuery4MessageContentResult( content,(Long)m.getProperty("creationDate")); resultReporter.report(1, res, operation); } catch (SchemaViolationException e) { e.printStackTrace(); resultReporter.report(-1, null, operation); } }
/** * Gets the specified vertices or null if no such vertex is found * * @param label vertex type label * @param limit int value limiting the result. use Integer.MAX_VALUE for unlimited * @param pValueMap PropertyKey->Value map * @return the specified vertices or null if no such vertex is found */ public Iterable<Vertex> getVertices(String label, Map<String, String> pValueMap, int limit) throws SchemaViolationException { Integer suffix = s.getVertexTypes().get(label); Set<Vertex> res = new HashSet<>(); if (suffix == null) throw new SchemaViolationException(label + " vertex type is not defined in the schema for " + s.getClass().getSimpleName()); GraphQuery gq = g.query(); for (String property : pValueMap.keySet()) gq = gq.has(property, pValueMap.get(property)); if (limit != Integer.MAX_VALUE) gq = gq.limit(limit); for (Vertex v : gq.vertices()) if ((((Long) v.getId()) % mult) == suffix) res.add(v); return res; }
/** * Gets the specified vertices or null if no such vertex is found * * @param property name * @param label vertex type label * @param value value in property field * @param limit int value limiting the result. use Integer.MAX_VALUE for unlimited * @return the specified vertices or null if no such vertex is found */ public Set<Vertex> getVertices(String label, String property, Object value, int limit) throws SchemaViolationException { Integer suffix = s.getVertexTypes().get(label); Set<Vertex> res = new HashSet<>(); if (suffix == null) throw new SchemaViolationException(label + " vertex type is not defined in the schema for " + s.getClass().getSimpleName()); Iterable<Vertex> qres; GraphQuery q = g.query().has("label", label).has(property, Cmp.EQUAL, value); if (limit == Integer.MAX_VALUE) qres = q.vertices(); else qres = q.limit(limit).vertices(); for (Vertex v : qres) res.add(v); return res; }
@Override public void executeOperation(LdbcUpdate5AddForumMembership operation, TitanFTMDb.BasicDbConnectionState dbConnectionState, ResultReporter reporter) throws DbException { TitanFTMDb.BasicClient client = dbConnectionState.client(); try { Vertex forum = client.getVertex(operation.forumId(), "Forum"); Vertex person = client.getVertex(operation.personId(), "Person"); if (forum==null) logger.error("Forum membership requested for nonexistent forum id {}", operation.forumId()); if (person==null) logger.error("Forum membership requested for nonexistent person {}", operation.personId()); Map<String, Object> props = new HashMap<>(1); props.put("joinDate", operation.joinDate().getTime()); client.addEdge(forum, person, "hasMember", props); } catch (SchemaViolationException e) { logger.error("invalid vertex label requested by query update"); e.printStackTrace(); } reporter.report(0, LdbcNoResult.INSTANCE,operation); }
@Override public void executeOperation(LdbcUpdate8AddFriendship operation, TitanFTMDb.BasicDbConnectionState dbConnectionState, ResultReporter reporter) throws DbException { TitanFTMDb.BasicClient client = dbConnectionState.client(); try { Map<String, Object> props = new HashMap<>(1); props.put("creationDate", operation.creationDate().getTime()); Vertex person = client.getVertex(operation.person1Id(), "Person"); Vertex friend = client.getVertex(operation.person2Id(), "Person"); client.addEdge(person, friend, "knows", props); } catch (SchemaViolationException e) { logger.error("invalid vertex label requested by query update"); e.printStackTrace(); } reporter.report(0, LdbcNoResult.INSTANCE, operation); }
@Override public void executeOperation(LdbcUpdate2AddPostLike operation, TitanFTMDb.BasicDbConnectionState dbConnectionState, ResultReporter reporter) throws DbException { TitanFTMDb.BasicClient client = dbConnectionState.client(); try { Vertex person = client.getVertex(operation.personId(), "Person"); Vertex post = client.getVertex(operation.postId(), "Post"); Map<String, Object> props = new HashMap<>(1); props.put("creationDate", operation.creationDate().getTime()); client.addEdge(person, post, "likes", props); } catch (SchemaViolationException e) { logger.error("invalid vertex label requested by query update"); e.printStackTrace(); } reporter.report(0, LdbcNoResult.INSTANCE,operation); }
/** * Given a person, returns the set of friends and friends of friends * , excluding that person * * @param rootId personID to start from * @param client TitanFTMDb.BasicClient to use for root retrieval * @return Set<Vertex> of the persons friends and their friends */ public Set<Vertex> getFoF(long rootId, TitanFTMDb.BasicClient client) { Set<Vertex> res = new HashSet<>(); Vertex root = null; try { root = client.getVertex(rootId, "Person"); } catch (SchemaViolationException e) { e.printStackTrace(); } GremlinPipeline<Vertex, Vertex> gp = (new GremlinPipeline<Vertex, Vertex>(root)); gp.out("knows").aggregate(res) .out("knows").aggregate(res).iterate(); res.remove(root); return res; }
@Override public void executeOperation(final LdbcShortQuery1PersonProfile operation,TitanFTMDb.BasicDbConnectionState dbConnectionState,ResultReporter resultReporter) throws DbException { List<LdbcQuery1Result> result = new ArrayList<>(); long person_id = operation.personId(); TitanFTMDb.BasicClient client = dbConnectionState.client(); final Vertex root; try { root = client.getVertex(person_id, "Person"); logger.debug("Short Query 1 called on person id: {}", person_id); Vertex cityV = QueryUtils.getPersonCity(root); LdbcShortQuery1PersonProfileResult res = new LdbcShortQuery1PersonProfileResult( (String) root.getProperty("firstName"),(String) root.getProperty("lastName"), (Long) root.getProperty("birthday"), (String) root.getProperty("locationIP"), (String) root.getProperty("browserUsed"),client.getVLocalId((Long)cityV.getId()), (String) root.getProperty("gender"), (Long) root.getProperty("creationDate")); resultReporter.report(result.size(), res, operation); } catch (SchemaViolationException e) { e.printStackTrace(); resultReporter.report(-1, null, operation); } }
@Override public void executeOperation(LdbcUpdate3AddCommentLike operation, TitanFTMDb.BasicDbConnectionState dbConnectionState, ResultReporter reporter) throws DbException { TitanFTMDb.BasicClient client = dbConnectionState.client(); try { Vertex person = client.getVertex(operation.personId(), "Person"); Vertex post = client.getVertex(operation.commentId(), "Comment"); Map<String, Object> props = new HashMap<>(1); props.put("creationDate", operation.creationDate().getTime()); client.addEdge(person, post, "likes", props); } catch (SchemaViolationException e) { logger.error("invalid vertex label requested by query update"); e.printStackTrace(); } reporter.report(0, LdbcNoResult.INSTANCE,operation); }
@Override public void executeOperation(final LdbcShortQuery5MessageCreator operation,TitanFTMDb.BasicDbConnectionState dbConnectionState,ResultReporter resultReporter) throws DbException { long mid = operation.messageId(); TitanFTMDb.BasicClient client = dbConnectionState.client(); Vertex m; try { logger.debug("Short Query 5 called on message id: {}", mid); m = client.getVertex(mid, "Comment"); if (m==null) m = client.getVertex(mid, "Post"); GremlinPipeline<Vertex,Vertex> gp = new GremlinPipeline<>(m); Vertex person = gp.out("hasCreator").next(); LdbcShortQuery5MessageCreatorResult res = new LdbcShortQuery5MessageCreatorResult( client.getVLocalId((Long)person.getId()), (String) person.getProperty("firstName"),(String) person.getProperty("lastName")); resultReporter.report(1, res, operation); } catch (SchemaViolationException e) { e.printStackTrace(); resultReporter.report(-1, null, operation); } }
@Override public boolean importData(File dir) throws IOException, SchemaViolationException { //Based upon http://s3.thinkaurelius.com/docs/titan/current/bulk-loading.html //Enabled the storage.batch-loading configuration option in bdb.conf //Disabled automatic type creation by setting schema.default=none in bdb.conf //Using a local variation of BatchLoad https://github.com/tinkerpop/blueprints/wiki/Batch-Implementation logger.debug("entered import data, dir is: {}", dir.getAbsolutePath() ); if (!dir.isDirectory()) return false; WorkLoadSchema s = this.workload.getSchema(); Map<String, String> vpMap = s.getVPFileMap(); Map<String, String> eMap = s.getEFileMap(); TypedBatchGraph bgraph = new TypedBatchGraph(g, VertexIDType.NUMBER, 10000); bgraph.setVertexIdKey(IdGraph.ID); loadVertices(bgraph, dir, s.getVertexTypes().keySet()); loadVertexProperties(bgraph, dir, vpMap); loadEdges(bgraph, dir, eMap); logger.debug("completed import data"); return true; }
/** * Mock a managed LDAP schema violation */ @Test public void removeUserNotMember() { final GroupLdapRepository groupRepository = newGroupLdapRepository(); final LdapTemplate ldapTemplate = Mockito.mock(LdapTemplate.class); groupRepository.setTemplate(ldapTemplate); Mockito.doThrow(new org.springframework.ldap.SchemaViolationException(new SchemaViolationException("any"))).when(ldapTemplate) .modifyAttributes(ArgumentMatchers.any(LdapName.class), ArgumentMatchers.any()); removeUser(groupRepository); }
@Override public DirContext createSubcontext(Name name, Attributes attributes) throws NamingException { int size = name.size(); Hashtable<String, Object> subSchemaTree = doLookup(name .getPrefix(size - 1), size - 1); if (null == attributes || attributes.size() == 0) { // jndi.8D=Must supply attributes describing schema throw new SchemaViolationException(Messages.getString("jndi.8D")); //$NON-NLS-1$ } if (level - size == 2) { // jndi.8E=Cannot create new entry under schema root throw new SchemaViolationException(Messages.getString("jndi.8E")); //$NON-NLS-1$ } String subSchemaType = name.getSuffix(size - 1).toString(); if (subSchemaTree.get(subSchemaType.toLowerCase()) != null) { throw new NameAlreadyBoundException(subSchemaType); } String schemaLine = SchemaParser.format(attributes); ModifyOp op = new ModifyOp(ldapContext.subschemasubentry); Name modifySchemaName = name.getPrefix(size - 1).addAll(rdn); BasicAttribute schemaEntry = new LdapAttribute(new BasicAttribute( jndi2ldap(modifySchemaName.toString()), schemaLine), ldapContext); op.addModification(OperationJndi2Ldap[DirContext.ADD_ATTRIBUTE], new LdapAttribute(schemaEntry, ldapContext)); try { doBasicOperation(op); subSchemaTree.put(subSchemaType.toLowerCase(), schemaLine); } catch (ReferralException e) { // TODO } return (DirContext) lookup(name); }
/** * Validates the file header against the schema used by the importer * * @param s schema to validate against * @param vLabel vertex type to validate against * @param header header of csv file * @return suffix of this vertex */ private short validateVHeader(WorkLoadSchema s, String vLabel, String[] header) throws SchemaViolationException { Set<String> props = s.getVertexProperties().get(vLabel); if (props == null) throw new SchemaViolationException("No properties found for the vertex label " + vLabel); if (!header[0].equals("id") && !header[0].endsWith(".id")) throw new SchemaViolationException("First column of " + vLabel + " is not labeled 'id', but:" + header[0]); for (String col : header) { if (col.equals("id") || col.endsWith(".id")) continue; if (!props.contains(col)) { /* This is a due to the fact that Titan has global property keys and language has SINGLE cardinality for Post.language and LIST cardinality in Person.language. */ if (col.equals("language") && props.contains("lang")) continue; else throw new SchemaViolationException("Unknown property for vertex Type" + vLabel + ", found " + col + " expected " + props); } if (s.getVPropertyClass(vLabel, col) == null) throw new SchemaViolationException("Class definition missing for " + vLabel + "." + col); } return typeMultMap.get(vLabel).shortValue(); }
/** * Validates the file header against the schema used by the importer * * @param s schema to validate against * @param eTriple edge triple to validate against (triple = Vertex.Edge.Vertex) * @param header header of csv file * @return short array of size two with the suffixes of * the source ([0]) and target ([1]) vertices */ private short[] validateEHeader(WorkLoadSchema s, String eTriple, String[] header) throws SchemaViolationException, IllegalArgumentException { String[] triple = eTriple.split(TUPLESPLIT); if (triple.length != 3) throw new IllegalArgumentException("Expected parameter eTriple to " + "contain a string with two '.' delimiters, found" + eTriple); String vF = triple[0]; String eLabel = triple[1]; String vT = triple[2]; Set<String> vTypes = s.getVertexTypes().keySet(); if (!vTypes.contains(vF) || !vTypes.contains(vT)) throw new SchemaViolationException("Vertex types not found for triple" + eTriple + ", found " + vTypes); Set<String> eTypes = s.getEdgeTypes(); if (!eTypes.contains(eLabel)) throw new SchemaViolationException("Edge type not found for triple" + eTriple + ", found " + eTypes); //This may be null and that's fine, not all edges have properties Set<String> props = s.getEdgeProperties().get(eLabel); if (!header[0].equals(vF + ".id")) throw new SchemaViolationException("First column is not labeled " + vF + ".id, but:" + header[0]); if (!header[1].equals(vT + ".id")) throw new SchemaViolationException("Second column is not labeled " + vT + ".id, but:" + header[0]); for (String col : header) { if (col.contains(".id")) continue; if (props == null || !props.contains(col)) throw new SchemaViolationException("Unknown property, found " + col + "expected" + props); } return new short[]{typeMultMap.get(vF).shortValue(), typeMultMap.get(vT).shortValue()}; }
@Override public void destroySubcontext(Name name) throws NamingException { int size = name.size(); Hashtable<String, Object> subSchemaTree = doLookup(name .getPrefix(size - 1), size - 1); String subSchemaType = name.getSuffix(size - 1).toString() .toLowerCase(); Object schema = subSchemaTree.get(jndi2ldap(subSchemaType)); if (schema == null) { // Return silently. return; } if (level - size == 2) { // ldap.37=Can't delete schema root throw new SchemaViolationException(Messages.getString("ldap.37")); //$NON-NLS-1$ } if (level == size) { // Return silently. return; } String schemaLine = schema.toString(); if (schema instanceof Hashtable) { Hashtable<String, Object> table = (Hashtable<String, Object>) schema; schemaLine = table.get(SchemaParser.ORIG).toString(); } ModifyOp op = new ModifyOp(ldapContext.subschemasubentry); Name modifySchemaName = name.getPrefix(size - 1).addAll(rdn); BasicAttribute schemaEntry = new LdapAttribute(new BasicAttribute( jndi2ldap(modifySchemaName.toString()), schemaLine), ldapContext); op.addModification(OperationJndi2Ldap[DirContext.REMOVE_ATTRIBUTE], new LdapAttribute(schemaEntry, ldapContext)); try { doBasicOperation(op); subSchemaTree.remove(subSchemaType); } catch (ReferralException e) { // TODO } }
@Override public void executeOperation(final LdbcShortQuery6MessageForum operation,TitanFTMDb.BasicDbConnectionState dbConnectionState,ResultReporter resultReporter) throws DbException { long mid = operation.messageId(); TitanFTMDb.BasicClient client = dbConnectionState.client(); Vertex m; try { boolean isComment = true; logger.debug("Short Query 6 called on message id: {}", mid); m = client.getVertex(mid, "Comment"); if (m==null) { m = client.getVertex(mid, "Post"); isComment = false; } GremlinPipeline<Vertex,Vertex> gp = new GremlinPipeline<>(m); Iterator<Row> qResult; if (isComment) { qResult = gp.as("start").out("replyOf") .loop("start", QueryUtils.LOOPTRUEFUNC, QueryUtils.LOOPTRUEFUNC).filter(QueryUtils.ONLYPOSTS).as("post") .in("containerOf").as("forum").out("hasModerator").as("person").select(); } else { qResult = gp.in("containerOf").as("forum").out("hasModerator").as("person").select(); } if (!qResult.hasNext()) { logger.error("Unexpected empty set"); resultReporter.report(-1, new LdbcShortQuery6MessageForumResult(0,"",0,"",""), operation); } else { Row r = qResult.next(); Vertex forum = (Vertex)r.getColumn("forum"); Vertex person = (Vertex)r.getColumn("person"); LdbcShortQuery6MessageForumResult res = new LdbcShortQuery6MessageForumResult( client.getVLocalId((Long)forum.getId()), (String)forum.getProperty("title"), client.getVLocalId((Long)person.getId()), (String) person.getProperty("firstName"),(String) person.getProperty("lastName")); resultReporter.report(1, res, operation); } } catch (SchemaViolationException e) { e.printStackTrace(); resultReporter.report(-1, new LdbcShortQuery6MessageForumResult(0,"",0,"",""), operation); } }
@Override public void executeOperation(final LdbcQuery7 operation,TitanFTMDb.BasicDbConnectionState dbConnectionState,ResultReporter resultReporter) throws DbException { long person_id = operation.personId(); final int limit = operation.limit(); logger.debug("Query 7 called on Person id: {}", person_id); TitanFTMDb.BasicClient client = dbConnectionState.client(); Vertex root = null; try { root = client.getVertex(person_id, "Person"); } catch (SchemaViolationException e) { e.printStackTrace(); } GremlinPipeline<Vertex, Vertex> gp = (new GremlinPipeline<>(root)); Set<Vertex> friends = new HashSet<>(); gp.out("knows").fill(friends); gp = (new GremlinPipeline<>(root)); Iterable<Row> it = gp.as("root").in("hasCreator").as("post").inE("likes").as("like").outV().as("liker") .select(); Map<Vertex, LdbcQuery7Result> qRes = new HashMap<>(); for (Row r : it) { Vertex post = (Vertex) r.getColumn(1); Edge like = (Edge) r.getColumn(2); Vertex liker = (Vertex) r.getColumn(3); boolean isNotFriend = (!friends.contains(liker)); long id = client.getVLocalId((Long) liker.getId()); String fName = liker.getProperty("firstName"); String lName = liker.getProperty("lastName"); long lcDate = like.getProperty("creationDate"); long pcDate = post.getProperty("creationDate"); long postID = client.getVLocalId((Long) post.getId()); String content = post.getProperty("content"); if (content.length() == 0) content = post.getProperty("imageFile"); int latency = (int) ((lcDate - pcDate) / 60000); LdbcQuery7Result res = new LdbcQuery7Result(id, fName, lName, lcDate, postID, content, latency, isNotFriend); //if liker has res, replace according to recent like, and then lower likeid if time is the same if (qRes.containsKey(liker)) { LdbcQuery7Result other = qRes.get(liker); if (other.likeCreationDate() > res.likeCreationDate()) continue; else if (other.likeCreationDate() == res.likeCreationDate() && other.commentOrPostId() < res.commentOrPostId()) continue; } /*it is implied from the fact that the program reached this point that either this person has not been recorded in qRes yet or that the current like is more recent or it is as recent as the other but with a lower postID */ qRes.put(liker, res); } List<LdbcQuery7Result> result = new ArrayList<>(qRes.values()); Collections.sort(result, new Comparator<LdbcQuery7Result>() { @Override public int compare(LdbcQuery7Result o1, LdbcQuery7Result o2) { if (o1.likeCreationDate() == o2.likeCreationDate()) return Long.compare(o1.personId(), o2.personId()); return Long.compare(o2.likeCreationDate(), o1.likeCreationDate()); } }); if (result.size() > limit) result = result.subList(0, limit); resultReporter.report(result.size(), result, operation); }
@Override public void executeOperation(final LdbcShortQuery7MessageReplies operation,TitanFTMDb.BasicDbConnectionState dbConnectionState,ResultReporter resultReporter) throws DbException { long mid = operation.messageId(); TitanFTMDb.BasicClient client = dbConnectionState.client(); List<LdbcShortQuery7MessageRepliesResult> result = new ArrayList<>(); Vertex m; try { logger.debug("Short Query 7 called on message id: {}", mid); m = client.getVertex(mid, "Comment"); if (m==null) m = client.getVertex(mid, "Post"); GremlinPipeline<Vertex,Vertex> gp = new GremlinPipeline<>(m); Iterable<Row> qResult = gp.in("replyOf").as("reply").out("hasCreator").as("person") .select().order(new PipeFunction<Pair<Row, Row>, Integer>() { @Override public Integer compute(Pair<Row, Row> argument) { long cid1 = (Long)((Vertex)argument.getA().getColumn("reply")).getId(); long cid2 = (Long)((Vertex)argument.getB().getColumn("reply")).getId(); if (cid1==cid2) { long aid1 = (Long)((Vertex)argument.getA().getColumn("person")).getId(); long aid2 = (Long)((Vertex)argument.getB().getColumn("person")).getId(); return Long.compare(aid2,aid1); } else return Long.compare(cid2,cid1); } }); GremlinPipeline<Vertex,Vertex> gpF = new GremlinPipeline<>(m); Set<Vertex> friends = new HashSet<>(); gpF.out("hasCreator").out("knows").fill(friends); for (Row r : qResult) { Vertex reply = (Vertex) r.getColumn("reply"); Vertex person = (Vertex) r.getColumn("person"); String content = reply.getProperty("content"); if (content.length() == 0) content = reply.getProperty("imageFile"); boolean knows = friends.contains(person); LdbcShortQuery7MessageRepliesResult res = new LdbcShortQuery7MessageRepliesResult( client.getVLocalId((Long) reply.getId()),content,(Long)reply.getProperty("creationDate"), client.getVLocalId((Long) person.getId()), (String) person.getProperty("firstName"), (String) person.getProperty("lastName"),knows); resultReporter.report(1, result, operation); result.add(res); } } catch (SchemaViolationException e) { e.printStackTrace(); resultReporter.report(-1, new ArrayList<LdbcShortQuery7MessageRepliesResult>(Collections.singletonList(new LdbcShortQuery7MessageRepliesResult(0,"",0,0,"","",false))), operation); } }
@Override public void executeOperation(final LdbcQuery8 operation,TitanFTMDb.BasicDbConnectionState dbConnectionState,ResultReporter resultReporter) throws DbException { long person_id = operation.personId(); final int limit = operation.limit(); logger.debug("Query 8 called on Person id: {}", person_id); TitanFTMDb.BasicClient client = dbConnectionState.client(); Vertex root = null; try { root = client.getVertex(person_id, "Person"); } catch (SchemaViolationException e) { e.printStackTrace(); } GremlinPipeline<Vertex, Vertex> gp = (new GremlinPipeline<>(root)); Iterable<Row> it = gp.in("hasCreator").in("replyOf").as("comment").out("hasCreator") .as("commenter").select(); List<LdbcQuery8Result> result = new ArrayList<>(); for (Row r : it) { Vertex comment = (Vertex) r.getColumn(0); Vertex commenter = (Vertex) r.getColumn(1); long id = client.getVLocalId((Long) commenter.getId()); String fName = commenter.getProperty("firstName"); String lName = commenter.getProperty("lastName"); long cDate = comment.getProperty("creationDate"); long commentID = client.getVLocalId((Long) comment.getId()); String content = comment.getProperty("content"); LdbcQuery8Result res = new LdbcQuery8Result(id, fName, lName, cDate, commentID, content); result.add(res); } Collections.sort(result, new Comparator<LdbcQuery8Result>() { @Override public int compare(LdbcQuery8Result o1, LdbcQuery8Result o2) { if (o1.commentCreationDate() == o2.commentCreationDate()) return Long.compare(o1.commentId(), o2.commentId()); return Long.compare(o2.commentCreationDate(), o1.commentCreationDate()); } }); if (result.size() > limit) result = result.subList(0, limit); resultReporter.report(result.size(), result, operation); }
@Override public void executeOperation(final LdbcShortQuery3PersonFriends operation,TitanFTMDb.BasicDbConnectionState dbConnectionState,ResultReporter resultReporter) throws DbException { List<LdbcShortQuery3PersonFriendsResult> result = new ArrayList<>(); long person_id = operation.personId(); TitanFTMDb.BasicClient client = dbConnectionState.client(); final Vertex root; try { root = client.getVertex(person_id, "Person"); logger.debug("Short Query 3 called on person id: {}", person_id); GremlinPipeline<Vertex, Vertex> gp = new GremlinPipeline<>(root); Iterable<Row> qResult = gp.outE("knows").as("knowEdge").inV().as("friend").select() .order(new PipeFunction<Pair<Row, Row>, Integer>() { @Override public Integer compute(Pair<Row, Row> argument) { long d1 = ((Edge) argument.getA().getColumn("knowEdge")).getProperty("creationDate"); long d2 = ((Edge) argument.getB().getColumn("knowEdge")).getProperty("creationDate"); if (d1 == d2) return Long.compare((Long) ((Vertex) argument.getA().getColumn("friend")).getId(), (Long) ((Vertex) argument.getB().getColumn("friend")).getId()); else return Long.compare(d2, d1); } }); for (Row r : qResult) { Vertex friend = (Vertex) r.getColumn("friend"); Edge knowsE = (Edge) r.getColumn("knowEdge"); LdbcShortQuery3PersonFriendsResult res = new LdbcShortQuery3PersonFriendsResult( client.getVLocalId((Long) friend.getId()), (String) friend.getProperty("firstName"), (String) friend.getProperty("lastName"), (Long) knowsE.getProperty("creationDate")); result.add(res); } resultReporter.report(result.size(), result, operation); } catch (SchemaViolationException e) { e.printStackTrace(); resultReporter.report(-1, null, operation); } }
/** * Gets the specified vertex or null if no such vertex is found * * @param id A long representing the id of the vertex to be retrieved * @return the specified vertex or null if no such vertex is found */ public Vertex getVertex(long id, String label) throws SchemaViolationException { return g.getVertex(getVId(id, label)); }
/** * * @param dir * @return true if import succeeded */ public boolean importData(File dir) throws IOException, SchemaViolationException;