GraphDB study notes - 01

basic concepts

  • 1. The concept of literacy:
    • GraphDB is an enterprise graph data storage engine. It is developed in C# and is open source. It is free to download for non-commercial purposes, but requires a commercial license if it is used for commercial purposes.
    • GraphDB is a type of NoSQL database that uses graph theory to store relational information between entities. The most common example is the relationship between people in a social network. Relational databases are not very effective for storing "relational" data, and their queries are complex, slow, and beyond expectations, and the unique design of graph databases just makes up for this shortcoming.
    • Graph databases are based on graph theory and take nodes (vertices), edges, and attributes as basic concepts.
      • Node: Represents an entity, such as a person, commodity, or an account.
      • Edge: Also known as relation, it represents the connection between points, for example, user A bought product B. Usually the edge is directional. For example, if user A buys product B, it is expressed as A->B; if user A and user C know each other, the relationship is bidirectional, expressed as A<->B.
      • Properties: Represents the information attached to Nodes and Edges, such as a user, whose properties may be age 30, hobby basketball, and so on. It should be noted that the properties of each point are dynamic, for example, users A and C are the same, A has the attribute "age 30", but C does not. But it does contain the attribute "professional engineer".
  • Highlights:
    • Full ACID support
    • high availability
    • Easily scale to hundreds of millions of nodes and relationships
    • High-speed retrieval of data with traversal tools
  • Features:

    • SQL like simple query language Neo4j CQL

    • It follows the property graph data model

    • It supports indexing by using Apache Lucence

    • It supports UNIQUE constraints

    • It contains a UI for executing CQL commands: Neo4j Data Browser

    • It supports full ACID (Atomicity, Consistency, Isolation and Durability) rules

    • It uses native graphics library with native GPE (Graphics Processing Engine)

    • It supports exporting queried data to JSON and XLS formats

    • It provides a REST API that can be accessed by any programming language like Java, Spring, Scala, etc.

    • It provides Javascript which can be accessed by any UI MVC framework like Node JS

    • It supports two Java APIs: Cypher API and Native Java API to develop Java applications

  • advantage:

    • It's easy to represent connected data

      • Retrieving/traversing/navigating more connected data is very easy and fast
    • It represents semi-structured data very easily

    • Neo4j CQL query language commands are human readable format, very easy to learn

    • It uses a simple and powerful data model

    • It doesn't require complex joins to retrieve connected/related data as it's easy to retrieve its adjacent nodes or relationship details without joins or indexes

  • Property graph model rules:

    • Represents data in nodes, relationships and attributes

    • Both nodes and relationships contain properties

    • relationship connection node

    • Properties are key-value pairs

    • Nodes are represented by circles and relationships are represented by arrow keys.

    • Relationships have directions: one-way and two-way.

    • Each relationship contains a "start node" or "from node" and a "to node" or "end node"

CQL Cypher query language.

  • CQL

    • It is the query language for the Neo4j graph database.

    • It is a declarative pattern matching language

    • It follows SQL syntax.

    • Its syntax is very simple and user-friendly, readable format.

  • Common Neo4j CQL commands:

    • 1. CREATE: create

      • Create Nodes, Relationships and Properties
      • scenes to be used:

        • Create a node without attributes
          • CREATE (<node-name>:<label-name>)
          • <node-name>It is the node name we want to create.
          • <label-name>it is a node label name
        • Create a node with properties
          • CREATE (
            <node-name>:<label-name>
            {
            <Property1-name>:<Property1-Value>
            ........
            <Propertyn-name>:<Propertyn-Value>
            }
            )
          • <node-name>It is the node name we will create.
        • <label-name>it is a node label name
        • <Property1-name>...<Propertyn-name>Properties are key-value pairs. Defines the name of the property that will be assigned to the created node
        • <Property1-value>...<Propertyn-value>Properties are key-value pairs. Defines the value that will be assigned to the property of the created node
        • Create a relationship between nodes without attributes

        • Use properties to create relationships between nodes

        • Create single or multiple labels for nodes or relationships

    • 2. MATCH: match
      • Retrieve data about nodes, relationships and attributes
      • MATCH (<node-name>:<label-name>)
    • 3. RETURN: return
      • return query result
      • RETURN <node-name>.<property1-name>,........<node-name>.<propertyn-name>
      • scenes to be used:
        • Retrieve some properties of a node
        • Retrieve all attributes of a node
        • Retrieve certain properties of nodes and associations
        • Retrieve all properties of nodes and relationships
    • 4.MATCH & RETURN match and return
      • Syntax:
        -MATCH Command RETURN Command
      • Retrieve some properties of a node
      • Retrieve all attributes of a node
      • Retrieve certain properties of nodes and associations
      • Retrieve all properties of nodes and relationships
    • 5. Relationship Basics:
      • Relationship with no attribute to existing node
        • MATCH (<node1-label-name>:<node1-name>),(<node2-label-name>:<node2-name>)
          CREATE
          (<node1-label-name>)-[<relationship-label-name>:<relationship-name>]->(<node2-label-name>)
          RETURN <relationship-label-name>
        • 1.MATCH,CREATE,RETURN They are Neo4J CQL keywords.
        • 2. <node1-name>The name of the "From Node" it uses to create the relationship.
        • 3. <node1-label-name>The label name of the "From Node" it uses to create the relationship.
        • 4. <node2-name>The name of the "To Node" it uses to create the relationship.
        • 5. <node2-label-name>The label name of the "To Node" it uses to create the relationship.
        • 6. <relationship-name>This is the name of a relationship.
        • 7. <relationship-label-name>It is the label name of a relationship.
      • Relationship to an attribute of an existing node
        • MATCH (<node1-label-name>:<node1-name>),(<node2-label-name>:<node2-name>)
          CREATE
          (<node1-label-name>)-[<relationship-label-name>:<relationship-name>
          {<define-properties-list>}]->(<node2-label-name>)
          RETURN <relationship-label-name>

          • 8. <define-properties-list>It is a list of attributes (name-value pairs) assigned to the newly created relationship.
      • Create a relationship with no attributes using a new node
        • CREATE
          (<node1-label-name>:<node1-name>)-
          [<relationship-label-name>:<relationship-name>]->
          (<node1-label-name>:<node1-name>)
          RETURN <relationship-label-name>
      • Create a relationship with an attribute using a new node
        • CREATE
          (<node1-label-name>:<node1-name>{<define-properties-list>})-
          [<relationship-label-name>:<relationship-name>{<define-properties-list>}]
          ->(<node1-label-name>:<node1-name>{<define-properties-list>})
          RETURN <relationship-label-name>
      • Retrieve the details of a relationship node
        • MATCH
          (<node1-label-name>)-[<relationship-label-name>:<relationship-name>]->(<node2-label-name>)
          RETURN <relationship-label-name>
      • single label to relationship
        • CREATE (<node1-name>:<label1-name>)-
          [(<relationship-name>:<relationship-label-name>)]
          ->(<node2-name>:<label2-name>)
    • 6. WHERE: where
      • Provide conditional filtering to retrieve data
      • Simple WHERE clause syntax
        • WHERE <condition>
      • Complex WHERE clause syntax
        • WHERE <condition> <boolean-operator> <condition>
        • <condition>grammar:
          • <property-name> <comparison-operator> <value>
        • WHERE It is a Neo4j CQL keyword.
        • <property-name><property name> It is the property name of the node or relationship.
        • <comparison-operator><comparison operator> It is one of Neo4j CQL comparison operators. Please refer to the next section to see the comparison operators available in Neo4j CQL.
        • <value><value> It is a literal value such as a number literal, string literal, etc.
      • Use the WHERE clause to create relationships:
        • MATCH (<node1-label-name>:<node1-name>),(<node2-label-name>:<node2-name>)
          WHERE <condition>
          CREATE (<node1-label-name>)-[<relationship-label-name>:<relationship-name>
          {<relationship-properties>}]->(<node2-label-name>)
    • 5. DELETE: delete
      • Delete nodes and relationships
    • 6. REMOVE: remove
      • Deleting properties of nodes and relationships
    • 7. ORDER BY: sort by
      • Sort retrieved data
  • Neo4j CQL functions:
    • 1. String: string
      • They are used to use String literals.
        • UPPER It is used to change all letters to uppercase.
        • LOWER It is used to change all letters to lowercase.MATCH (e:Employee)
          RETURN e.id,LOWER(e.name),e.sal,e.deptno
        • SUBSTRING It is used to get a substring of a given String.
        • REPLACE It is used to replace a substring of a string
    • 2. Aggregation: Aggregation
      • They are used to perform some aggregation operations on CQL query results.
        • COUNT It returns the number of rows returned by the MATCH command.
        • MAX It returns the maximum value from a set of rows returned by the MATCH command.
        • MIN It returns the minimum value of a set of rows returned by the MATCH command.
        • SUM It returns the sum of all rows returned by the MATCH command.
        • AVG It returns the average of all rows returned by the MATCH command.
        • MATCH (e:Employee) RETURN COUNT(*)
    • 3. Relationship: Relationship
      • They are used to get the details of the relationship like startnode, endnode etc.
    • -

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325992400&siteId=291194637