ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

从SQLFlow的json格式中学习数据血缘json格式设计

2021-10-09 15:34:47  阅读:462  来源: 互联网

标签:SQLFlow coordinates hashCode width json n0 格式 height id


0.

数据血缘可视化这块目前比较优秀的就是SQLFlow(马哈鱼数据血缘分析器)了。我们可以从SQLFlow的json格式中学习数据血缘json格式设计。

1.实例

如何获取SQLFlow的json?在可视化画布上右键–》Download as json
在这里插入图片描述
以SQLFlow带的的 Hive sample sql 为例。

SELECT pageid, adid
FROM pageAds LATERAL VIEW explode(adid_list) adTable AS adid;

为了观感我们一段一段的讲,文章末尾有完整json。

1.1 核心概况

json中血缘关系定义在sqlflow这个对象中,有一个字段两个数组

  • dbvendor :什么类型的数据库,这里是hive
  • dbobjs:节点数组,每个节点就是sqlflow里画布里一块块表格
  • relations:关系数组,每个关系就是sqlflow里画布里的连线
"sqlflow": {
            "dbvendor": "dbvhive",
            "dbobjs": [],
            "relations": []
            }

1.2 dbobjs数组

dbobjs数组存着多个节点对象,节点对象结果如下。每个节点对象内有这个表的所有列和坐标。

  {
  "id": "2",
  "name": "pageAds",
  "type": "table",
  "columns": [
    {
      "id": "9",
      "name": "adid_list",
      "coordinates": [
        {
          "x": 3,
          "y": 35,
          "hashCode": "0"
        },
        {
          "x": 3,
          "y": 44,
          "hashCode": "0"
        }
      ]
    },
    {
      "id": "13",
      "name": "pageid",
      "coordinates": [
        {
          "x": 2,
          "y": 8,
          "hashCode": "0"
        },
        {
          "x": 2,
          "y": 14,
          "hashCode": "0"
        }
      ]
    }
  ],
  "coordinates": [
    {
      "x": 3,
      "y": 6,
      "hashCode": "0"
    },
    {
      "x": 3,
      "y": 61,
      "hashCode": "0"
    }
  ]
}

在这里插入图片描述
json中表和列的二元坐标组都有这样方便前端渲染关系图。表和字段有各自编号方便后面关系定位自己的父节点

relations

relations里的每个关系对象有最重要的 target和sources字段。从relations里我们也可以发现sqlflow的json格式和hive利用hook被动采集的字段级血缘关系的日志格式基本相似。

{
  "id": "101",
  //sqlflow自己定义的几种关系
  "type": "fdd",
  "effectType": "select",
  "target": {
    "id": "14",
    "column": "adid",
    "parentId": "11",
    "parentName": "RS-1",
    "coordinates": [
      {
        "x": 2,
        "y": 16,
        "hashCode": "0"
      },
      {
        "x": 2,
        "y": 20,
        "hashCode": "0"
      }
    ]
  },
  "sources": [
    {
      "id": "8",
      "column": "adid",
      "parentId": "7",
      "parentName": "adTable",
      "coordinates": [
        {
          "x": 3,
          "y": 57,
          "hashCode": "0"
        },
        {
          "x": 3,
          "y": 61,
          "hashCode": "0"
        }
      ]
    }
  ]
}

在这里插入图片描述
在这里插入图片描述

完整json

{
  "code": 200,
  "data": {
    "mode": "global",
    "summary": {
      "schema": 0,
      "process": 0,
      "database": 0,
      "view": 0,
      "mostRelationTables": [
        {
          "table": "PAGEADS"
        },
        {
          "table": "ADTABLE"
        }
      ],
      "column": 3,
      "table": 2,
      "relation": 3
    },
    "sqlflow": {
      "dbvendor": "dbvhive",
      "dbobjs": [
        {
          "id": "2",
          "name": "pageAds",
          "type": "table",
          "columns": [
            {
              "id": "9",
              "name": "adid_list",
              "coordinates": [
                {
                  "x": 3,
                  "y": 35,
                  "hashCode": "0"
                },
                {
                  "x": 3,
                  "y": 44,
                  "hashCode": "0"
                }
              ]
            },
            {
              "id": "13",
              "name": "pageid",
              "coordinates": [
                {
                  "x": 2,
                  "y": 8,
                  "hashCode": "0"
                },
                {
                  "x": 2,
                  "y": 14,
                  "hashCode": "0"
                }
              ]
            }
          ],
          "coordinates": [
            {
              "x": 3,
              "y": 6,
              "hashCode": "0"
            },
            {
              "x": 3,
              "y": 61,
              "hashCode": "0"
            }
          ]
        },
        {
          "id": "7",
          "name": "adTable",
          "type": "table",
          "columns": [
            {
              "id": "8",
              "name": "adid",
              "coordinates": [
                {
                  "x": 3,
                  "y": 57,
                  "hashCode": "0"
                },
                {
                  "x": 3,
                  "y": 61,
                  "hashCode": "0"
                }
              ]
            }
          ],
          "coordinates": [
            {
              "x": 3,
              "y": 46,
              "hashCode": "0"
            },
            {
              "x": 3,
              "y": 53,
              "hashCode": "0"
            }
          ]
        },
        {
          "id": "11",
          "name": "RS-1",
          "type": "select_list",
          "columns": [
            {
              "id": "12",
              "name": "pageid",
              "coordinates": [
                {
                  "x": 2,
                  "y": 8,
                  "hashCode": "0"
                },
                {
                  "x": 2,
                  "y": 14,
                  "hashCode": "0"
                }
              ]
            },
            {
              "id": "14",
              "name": "adid",
              "coordinates": [
                {
                  "x": 2,
                  "y": 16,
                  "hashCode": "0"
                },
                {
                  "x": 2,
                  "y": 20,
                  "hashCode": "0"
                }
              ]
            }
          ],
          "coordinates": [
            {
              "x": 2,
              "y": 8,
              "hashCode": "0"
            },
            {
              "x": 2,
              "y": 20,
              "hashCode": "0"
            }
          ]
        }
      ],
      "relations": [
        {
          "id": "101",
          "type": "fdd",
          "effectType": "select",
          "target": {
            "id": "14",
            "column": "adid",
            "parentId": "11",
            "parentName": "RS-1",
            "coordinates": [
              {
                "x": 2,
                "y": 16,
                "hashCode": "0"
              },
              {
                "x": 2,
                "y": 20,
                "hashCode": "0"
              }
            ]
          },
          "sources": [
            {
              "id": "8",
              "column": "adid",
              "parentId": "7",
              "parentName": "adTable",
              "coordinates": [
                {
                  "x": 3,
                  "y": 57,
                  "hashCode": "0"
                },
                {
                  "x": 3,
                  "y": 61,
                  "hashCode": "0"
                }
              ]
            }
          ]
        },
        {
          "id": "102",
          "type": "fdd",
          "effectType": "select",
          "target": {
            "id": "12",
            "column": "pageid",
            "parentId": "11",
            "parentName": "RS-1",
            "coordinates": [
              {
                "x": 2,
                "y": 8,
                "hashCode": "0"
              },
              {
                "x": 2,
                "y": 14,
                "hashCode": "0"
              }
            ]
          },
          "sources": [
            {
              "id": "13",
              "column": "pageid",
              "parentId": "2",
              "parentName": "pageAds",
              "coordinates": [
                {
                  "x": 2,
                  "y": 8,
                  "hashCode": "0"
                },
                {
                  "x": 2,
                  "y": 14,
                  "hashCode": "0"
                }
              ]
            }
          ]
        },
        {
          "id": "103",
          "type": "fdd",
          "effectType": "select",
          "target": {
            "id": "8",
            "column": "adid",
            "parentId": "7",
            "parentName": "adTable",
            "coordinates": [
              {
                "x": 3,
                "y": 57,
                "hashCode": "0"
              },
              {
                "x": 3,
                "y": 61,
                "hashCode": "0"
              }
            ]
          },
          "sources": [
            {
              "id": "9",
              "column": "adid_list",
              "parentId": "2",
              "parentName": "pageAds",
              "coordinates": [
                {
                  "x": 3,
                  "y": 35,
                  "hashCode": "0"
                },
                {
                  "x": 3,
                  "y": 44,
                  "hashCode": "0"
                }
              ]
            }
          ]
        }
      ]
    },
    "graph": {
      "elements": {
        "tables": [
          {
            "columns": [
              {
                "height": 16,
                "id": "n0::n0",
                "label": {
                  "content": "pageid",
                  "fontFamily": "Segoe UI Symbol",
                  "fontSize": "12",
                  "height": 13.96875,
                  "width": 59,
                  "x": 0,
                  "y": 0
                },
                "width": 160,
                "x": 445,
                "y": -59.49261
              },
              {
                "height": 16,
                "id": "n0::n1",
                "label": {
                  "content": "adid",
                  "fontFamily": "Segoe UI Symbol",
                  "fontSize": "12",
                  "height": 13.96875,
                  "width": 43,
                  "x": 0,
                  "y": 0
                },
                "width": 160,
                "x": 445,
                "y": -43.49261
              }
            ],
            "height": 57.96875,
            "id": "n0",
            "label": {
              "content": "RS-1",
              "fontFamily": "Segoe UI Symbol",
              "fontSize": "12",
              "height": 17.96875,
              "width": 162,
              "x": 0,
              "y": 0
            },
            "width": 162,
            "x": 444,
            "y": -81.46136
          },
          {
            "columns": [
              {
                "height": 16,
                "id": "n1::n0",
                "label": {
                  "content": "adid_list",
                  "fontFamily": "Segoe UI Symbol",
                  "fontSize": "12",
                  "height": 13.96875,
                  "width": 67,
                  "x": 0,
                  "y": 0
                },
                "width": 160,
                "x": 1,
                "y": -59.49261
              },
              {
                "height": 16,
                "id": "n1::n1",
                "label": {
                  "content": "pageid",
                  "fontFamily": "Segoe UI Symbol",
                  "fontSize": "12",
                  "height": 13.96875,
                  "width": 59,
                  "x": 0,
                  "y": 0
                },
                "width": 160,
                "x": 1,
                "y": -43.49261
              }
            ],
            "height": 57.96875,
            "id": "n1",
            "label": {
              "content": "pageAds",
              "fontFamily": "Segoe UI Symbol",
              "fontSize": "12",
              "height": 17.96875,
              "width": 162,
              "x": 0,
              "y": 0
            },
            "width": 162,
            "x": 0,
            "y": -81.46136
          },
          {
            "columns": [
              {
                "height": 16,
                "id": "n2::n0",
                "label": {
                  "content": "adid",
                  "fontFamily": "Segoe UI Symbol",
                  "fontSize": "12",
                  "height": 13.96875,
                  "width": 43,
                  "x": 0,
                  "y": 0
                },
                "width": 160,
                "x": 223,
                "y": -30.000149
              }
            ],
            "height": 41.96875,
            "id": "n2",
            "label": {
              "content": "adTable",
              "fontFamily": "Segoe UI Symbol",
              "fontSize": "12",
              "height": 17.96875,
              "width": 162,
              "x": 0,
              "y": 0
            },
            "width": 162,
            "x": 222,
            "y": -51.9689
          }
        ],
        "edges": [
          {
            "id": "e0",
            "sourceId": "n1::n0",
            "targetId": "n2::n0"
          },
          {
            "id": "e1",
            "sourceId": "n2::n0",
            "targetId": "n0::n1"
          },
          {
            "id": "e2",
            "sourceId": "n1::n1",
            "targetId": "n0::n0"
          }
        ]
      },
      "tooltip": {
        
      },
      "relationIdMap": {
        "e0": "fdd",
        "e1": "fdd",
        "e2": "fdd"
      },
      "listIdMap": {
        "n0": [
          "11"
        ],
        "n0::n0": [
          "12"
        ],
        "n0::n1": [
          "14"
        ],
        "n1": [
          "2"
        ],
        "n1::n0": [
          "9"
        ],
        "n1::n1": [
          "13"
        ],
        "n2": [
          "7"
        ],
        "n2::n0": [
          "8"
        ]
      }
    }
  },
  "sessionId": "a91895aadcb9d674e7d3edd5ddd12d4fefcda4ff797881d3b4823fe1ec9ff367_1633745113743"
}

标签:SQLFlow,coordinates,hashCode,width,json,n0,格式,height,id
来源: https://blog.csdn.net/qq_44831907/article/details/120671264

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有