DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

The Latest DevOps and CI/CD Topics

article thumbnail
Neo4j and Cypher: Using MERGE With Schema Indexes/Constraints
I wrote about cypher’s MERGE function a couple of weeks ago, and over the last few days, I’ve been exploring how it works with schema indexes and unique constraints. An Exciting Time to Be a Developer There is so much that could be said about the merging of Neo4j and Cypher right now, but it is certainly reasonable to point out that this merger will likely result in many exciting developments in the programming world. Programmers virtually always appreciate it when they are given the products and tools they require to get their job done properly, and now is the time for steps like this to be taken. The fact that Neo4J and Cypher have decided to merge means that the upsides of both will soon be apparent. You deserve to use all of the best tools to make informed decisions about your next software project, and a great way to make it happen is to use what has been given to you regarding product functionality. This is to say that you can use both the upsides of Neo4J and Cypher to come up with the exact tools you need to make a difference in your sphere of influence. Could Other Products Soon Merge? There has been some strong demand for other software development products to consider merging. Coders and programmers want to use their favorite projects in exactly how they were meant to be used, and this means getting them to merge in ways that are useful to the programmers. They just want to be able to squeeze as much use out of each program as they possibly can. You want to make sure that you can see what is going on with your codes as you are directly applying them to whichever problem you are working on at this time. To be sure, it is not an easy task, but no one ever said it would be easy. The important thing is that you get the work done so that you can start to become more productive in the coding you are doing now. A common use case with Neo4j is to model users and events where an event could be a tweet, Facebook post, or Pinterest pin. The model might look like this: We’d like to ensure that we don’t get duplicate users or events, and MERGE provides the semantics to do this: MERGE (u:User {id: {userId}) MERGE (e:Event {id: {eventId}) MERGE (u)-[:CREATED_EVENT]->(m) RETURN u, e We’d like to ensure that we don’t get duplicate users or events and MERGE provides the semantics to do this: MERGE ensures that a pattern exists in the graph. Either the pattern already exists, or it needs to be created. import org.neo4j.cypher.javacompat.ExecutionEngine; import org.neo4j.cypher.javacompat.ExecutionResult; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.factory.GraphDatabaseFactory; import org.neo4j.helpers.collection.MapUtil; import org.neo4j.kernel.impl.util.FileUtils; ... public class MergeTime { public static void main(String[] args) throws Exception { String pathToDb = "/tmp/foo"; FileUtils.deleteRecursively(new File(pathToDb)); GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase( pathToDb ); final ExecutionEngine engine = new ExecutionEngine( db ); ExecutorService executor = Executors.newFixedThreadPool( 50 ); final Random random = new Random(); final int numberOfUsers = 10; final int numberOfEvents = 50; int iterations = 100; final List userIds = generateIds( numberOfUsers ); final List eventIds = generateIds( numberOfEvents ); List merges = new ArrayList<>( ); for ( int i = 0; i < iterations; i++ ) { Integer userId = userIds.get(random.nextInt(numberOfUsers)); Integer eventId = eventIds.get(random.nextInt(numberOfEvents)); merges.add(executor.submit(mergeAway( engine, userId, eventId) )); } for ( Future merge : merges ) { merge.get(); } executor.shutdown(); ExecutionResult userResult = engine.execute("MATCH (u:User) RETURN u.id as userId, COUNT(u) AS count ORDER BY userId"); System.out.println(userResult.dumpToString()); } private static Runnable mergeAway(final ExecutionEngine engine, final Integer userId, final Integer eventId) { return new Runnable() { @Override public void run() { try { ExecutionResult result = engine.execute( "MERGE (u:User {id: {userId})\n" + "MERGE (e:Event {id: {eventId})\n" + "MERGE (u)-[:CREATED_EVENT]->(m)\n" + "RETURN u, e", MapUtil.map( "userId", userId, "eventId", eventId) ); // throw away for ( Map row : result ) { } } catch ( Exception e ) { e.printStackTrace(); } } }; } private static List generateIds( int amount ) { List ids = new ArrayList<>(); for ( int i = 1; i <= amount; i++ ) { ids.add( i ); } return ids; } } We create a maximum of 10 users and 50 events and then do 100 iterations of random (user, event) pairs with 50 concurrent threads. Afterward, we execute a query that checks how many users of each id have been created and get the following output: +----------------+ | userId | count | +----------------+ | 1 | 6 | | 2 | 3 | | 3 | 4 | | 4 | 8 | | 5 | 9 | | 6 | 7 | | 7 | 5 | | 8 | 3 | | 9 | 3 | | 10 | 2 | +----------------+ 10 rows Next, I added a schema index on users and events to see if that would make any difference, something Javad Karabi recently asked on the user group. CREATE INDEX ON :User(id) CREATE INDEX ON :Event(id) We wouldn’t expect this to make a difference as schema indexes don’t ensure uniqueness, but I ran it anyway t and got the following output: +----------------+ | userId | count | +----------------+ | 1 | 2 | | 2 | 9 | | 3 | 7 | | 4 | 2 | | 5 | 3 | | 6 | 7 | | 7 | 7 | | 8 | 6 | | 9 | 5 | | 10 | 3 | +----------------+ 10 rows If we want to ensure the uniqueness of users and events, we need to add a unique constraint on the id of both of these labels: CREATE CONSTRAINT ON (user:User) ASSERT user.id IS UNIQUE CREATE CONSTRAINT ON (event:Event) ASSERT event.id IS UNIQUE Now if we run the test, we’ll only end up with one of each user: +----------------+ | userId | count | +----------------+ | 1 | 1 | | 2 | 1 | | 3 | 1 | | 4 | 1 | | 5 | 1 | | 6 | 1 | | 7 | 1 | | 8 | 1 | | 9 | 1 | | 10 | 1 | +----------------+ 10 rows We’d see the same result if we ran a similar query checking for the uniqueness of events. As far as I can tell, this duplication of nodes that we merge on only happens if you try to create the same node twice concurrently. Once the node has been created, we can use MERGE with a non-unique index, and a duplicate node won’t get created. All the code from this post is available as a gist if you want to play around with it.
August 13, 2022
by Mark Needham
· 12,646 Views · 2 Likes
article thumbnail
Key Takeaways: Adrian Cockcroft's talk on Netflix, CD, and Microservices
This article was originally published on 3/19/15
August 13, 2022
by Mitch Pronschinske
· 22,241 Views · 1 Like
article thumbnail
Discussing Backend for Front-End
Learn more about discussing backend for front-end.
August 12, 2022
by Nicolas Fränkel
· 12,506 Views · 7 Likes
article thumbnail
Write Your Kubernetes Infrastructure as Go Code - Extend cdk8s With Custom Constructs
Build a Wordpress deployment as a cdk8s construct.
August 12, 2022
by Abhishek Gupta DZone Core CORE
· 34,419 Views · 2 Likes
article thumbnail
DevOps Challenges in 2019 and How to Overcome Them
Although DevOps is rising prominently as the premier cultural transformation technique for developers, it is certainly not without its challenges.
Updated August 12, 2022
by Herman Morgan
· 8,782 Views · 1 Like
article thumbnail
How to Govern Terraform States Using GitLab Enterprise
Most companies relying on Terraform for infrastructure management choose to do so with an orchestration tool. How can you govern Terraform states using GitLab Enterprise?
August 12, 2022
by Sefi Genis
· 5,007 Views · 1 Like
article thumbnail
4 Reasons MSPs Should Monitor Their GitHub Footprint
In this article, we will see why monitoring in real-time code-sharing platforms such as GitHub should be a top priority for any MSP.
August 11, 2022
by Thomas Segura
· 3,977 Views · 3 Likes
article thumbnail
GitHub Events Are Booming! Are Bots the Reason?
This article dives deeply into GitHub event trending, why GitHub events are surging, and whether GitHub's architecture can handle the increasing load.
August 11, 2022
by Mia Zhou
· 4,753 Views · 3 Likes
article thumbnail
Pull Request vs. Merge Request
Pull request vs. merge request, what is the difference?
August 10, 2022
by Yana Zinkevich
· 7,042 Views · 5 Likes
article thumbnail
10 Best Infrastructure-as-Code Tools for Automating Deployments in 2022
With the rapidly changing technology landscape, the traditional approaches to infrastructure are hampering businesses to adapt, innovate, and thrive optimally. Now, Infrastructure as Code (IaC) tools have emerged as the key to navigating this challenge.
August 10, 2022
by Vishnu Vasudevan
· 7,453 Views · 2 Likes
article thumbnail
Back to Basics: Accessing Kubernetes Pods
Kubernetes is a colossal beast. You need to understand many concepts before it starts being useful. Here, learn several ways to access pods outside the cluster.
August 10, 2022
by Nicolas Fränkel
· 4,756 Views · 4 Likes
article thumbnail
Decorator Pattern to Solve Integration Scenarios in Existing Systems
This article provides an example of how the Java Decorator Pattern helps create designs from scratch and fix integration problems in existing systems.
August 10, 2022
by Mario Casari
· 7,646 Views · 6 Likes
article thumbnail
The 2-Minute Test for Kubernetes Pod Security
Learn how to audit your clusters for compliance with the latest Kubernetes Pod Security Standards without installing anything in the cluster.
August 9, 2022
by Jim Bugwadia
· 6,889 Views · 2 Likes
article thumbnail
How To Migrate From ECS to EKS and the #1 Trick To Make EKS Easier
Looking to migrate from ECS to EKS, but you're not sure where to start? Explore this guide and learn how to make your EKS journey easier.
August 9, 2022
by Zilvinas Urbonas
· 3,797 Views · 1 Like
article thumbnail
Building a Slack Integration for Your SaaS Notification System
In this post, we offer details for developers who are planning to build a Slack integration for their notification system.
August 9, 2022
by Suhas Deshpande
· 4,816 Views · 2 Likes
article thumbnail
Auth0 (Okta) vs. Cognito
This article compares two authentication service providers: Auth0 and Amazon Cognito. Both of them are cloud-based identity management services.
August 8, 2022
by Anastasiia Komendantova
· 4,397 Views · 3 Likes
article thumbnail
Build a Java Microservice With AuraDB Free
For today’s adventure, we want to build a Java microservice that connects to, and interacts with, graph data in a Neo4j AuraDB Free database.
Updated August 8, 2022
by Jennifer Reif DZone Core CORE
· 9,857 Views · 5 Likes
article thumbnail
Externalize Microservice Configuration With Spring Cloud Config
How to set up a service that hosts the Spring Cloud Config server and to wire an existing microservice as the config client service.
Updated August 8, 2022
by Jennifer Reif DZone Core CORE
· 14,388 Views · 5 Likes
article thumbnail
6 Characteristics That Make an API Great for Application Integration
Here are a few guidelines about how an API should look to be a perfect fit for integration projects.
Updated August 8, 2022
by Olga Annenko
· 11,135 Views · 9 Likes
article thumbnail
Shared Kubernetes Clusters for Hybrid and Multi-Cloud
This article outlines the different hybrid/multi-cloud approaches and the different kinds of workloads across clouds and data center environments.
August 8, 2022
by Kyle Hunter
· 4,092 Views · 1 Like
  • Previous
  • ...
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • ...
  • Next
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook
×