iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 9
1
自我挑戰組

圖形資料庫是什麼,可以吃嗎 - Neo4j系列 第 9

Neo4j 獨創 Cypher Query Language

前情提要

上一篇講了 Neo4j DB 的基礎結構

是時候要來講講如何製造這些結構了

SQL Server 有 SQL 語法

那 Neo4j 身為獨步全球的 Graph Database (?)

自然會有屬於 Neo4j 的 GQL

沒錯 ! 就是今天的主題 Cypher

Cypher

Cypher,起源於 2011 年

為 Neo4j 的工程師針對 Neo4j Graph Database 開發的查詢語言

並基於 SQL 語法所開發而成

所以如果你熟悉 SQL 語法的話,你之後會看到許多非常類似的東西

那我們先來看看基本結構吧

如果你要簡單表達一個關係 ( A Call B ),那你可以寫成這樣

( A )-[ Call ]->( B )

Node

首先你要表達一個節點 Node 那你要寫成這樣 --> ()

還記得上篇講過的 Label 嗎,加上 Label 吧 --> (:Label)

Property 呢 --> (:Label{Property:"I am Property"})

這樣一個完整的 Cypher 表示 Node 語法就完成了

這邊值得一提的是,你會發現 Property 的內容是用 {} 包起來的

實際上,裡面就是 Json 的結構

不過要記得上一篇說的,巢狀結構是不允許的

Relationship

Relationship 呢 --> []

一樣加上 TypeProperty 吧 --> [:Label{Property:"I am Property"}]

嗯 ... 這部份 Node 跟 Relationship 長的一樣啦 (゚∀゚)

那加上連接線吧

(:Person{Name:"A"})-[:Call]->(:Person{Name:"B"})

這樣 A 連到 B 的基本結構就完成了

小細節

這樣是代表有指向的關係

()-[]->()

當然有沒指向的關係

()-[]-()

嗯 對 > 箭頭拿掉而已

基本結構講完了,下面這張官方的圖你是不是也看得懂了呢 ?


Source : Property-Graph-Cypher

openCypher

繼續講故事

Cypher 發展自 2015 年,隨著圖形資料的技術漸漸變得重要

Neo4j 決定將 Cypher 標準化,並視下方四個關鍵項目

  • Cypher reference documentation

    不負責任翻譯 : 完整 Cypher 使用文件

  • Technology compatibility kit (TCK)

    不負責任翻譯 : 軟體技術版本支援
    大概是說,所有用 Cypher 的軟體必須提供,軟體版本對應 Cypher 版本的內容

  • Reference implementation

    不負責任翻譯 : ************
    看得懂英文內容,中文翻譯不能@@

    Distributed under the Apache 2.0 license, the reference implementation is a fully functional implementation of key parts of the stack needed to support Cypher inside a data platform or tool. The first planned deliverable is a parser that will take a Cypher statement and parse it into an AST (abstract syntax tree) representation. The reference implementation complements the documentation and tests by providing working implementations of Cypher – which are permissively licensed – and can be used as examples or as a foundation for one’s own implementation.
    Source : Meet openCypher: The SQL for Graphs

  • Cypher language specification

    不負責任翻譯 : Cypher 語法標準規範

將 Cypher 推廣為圖形資料的技術的主要圖形查詢語法

並開始了 openCypher 這個開源項目,持續堆動相關技術的發展


總算是寫完了@@

一直搞不定這篇文章的內容大綱跟順序

所以這篇文章一個一拖再拖

從鐵人賽 Day3 一路拖到 Day5 才寫完

我的積稿量阿QQ

明天 Cypher 語法簡介 Part1 : 基礎中的基礎 MATCH & RETURN

期待明日的降臨吧 Ciao!


參考資料

Wikipedia - Cypher (query language)

Neo4j Developer - Cypher Query Language

Neo4j - Cypher-Graph-Query-Language

openCypher

Meet openCypher: The SQL for Graphs


排版好看的版本同步更新在我的 HackMD


上一篇
Neo4j 結構基礎概念,終於進到比較技術的部份了
下一篇
Cypher 語法簡介 Part1 : 基礎中的基礎 MATCH & RETURN
系列文
圖形資料庫是什麼,可以吃嗎 - Neo4j30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言