| /* ----------------------------------------------------------------------- *//** |
| * |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| * |
| */ |
| /* ----------------------------------------------------------------------- */ |
| |
| -- Create vertex and edge tables to represent the graph: |
| DROP TABLE IF EXISTS vertex, edge; |
| CREATE TABLE vertex( |
| id INTEGER, |
| name TEXT |
| ); |
| CREATE TABLE edge( |
| src INTEGER, |
| dest INTEGER, |
| weight FLOAT8 |
| ); |
| INSERT INTO vertex VALUES |
| (0, 'A'), |
| (1, 'B'), |
| (2, 'C'), |
| (3, 'D'), |
| (4, 'E'), |
| (5, 'F'), |
| (6, 'G'), |
| (7, 'H'); |
| INSERT INTO edge VALUES |
| (0, 1, 1.0), |
| (0, 2, 1.0), |
| (0, 4, 10.0), |
| (1, 2, 2.0), |
| (1, 3, 10.0), |
| (2, 3, 1.0), |
| (2, 5, 1.0), |
| (2, 6, 3.0), |
| (3, 0, 1.0), |
| (4, 0, -2.0), |
| (5, 6, 1.0), |
| (6, 7, 1.0); |
| |
| -- Calculate the all-pair shortest paths: |
| DROP TABLE IF EXISTS out_apsp, out_apsp_summary; |
| SELECT graph_apsp('vertex', -- Vertex table |
| 'id', -- Vertix id column (NULL means use default naming) |
| 'edge', -- edge table |
| NULL, |
| 'out_apsp'); -- Output table of shortest paths |
| |
| -- Compute the closeness measure for all nodes: |
| DROP TABLE IF EXISTS out_closeness; |
| SELECT graph_closeness('out_apsp', 'out_closeness'); |
| |
| -- Compute the diameter measure for graph |
| DROP TABLE IF EXISTS out_diameter; |
| SELECT graph_diameter('out_apsp', 'out_diameter'); |
| -- Compute the average path length measure for graph |
| DROP TABLE IF EXISTS out_avg_path_length; |
| SELECT graph_avg_path_length('out_apsp', 'out_avg_path_length'); |
| |
| -- Compute the in and out degrees |
| DROP TABLE IF EXISTS out_degrees; |
| SELECT graph_vertex_degrees('vertex', -- Vertex table |
| 'id', -- Vertix id column (NULL means use default naming) |
| 'edge', -- edge table |
| NULL, |
| 'out_degrees'); |
| |
| |
| DROP TABLE IF EXISTS out_frombfs, out_frombfs_summary; |
| SELECT graph_bfs('vertex',NULL,'edge',NULL,2,'out_frombfs'); |
| |
| DROP TABLE IF EXISTS hits_out, hits_out_summary; |
| SELECT hits( |
| 'vertex', -- Vertex table |
| NULL, -- Vertex id column |
| 'edge', -- edge table |
| NULL, |
| 'hits_out', -- Output table of HITS |
| 2); -- Max number of iteration |
| |
| DROP TABLE IF EXISTS pagerank_out, pagerank_out_summary; |
| SELECT pagerank( |
| 'vertex', -- Vertex table |
| NULL, -- Vertex id column |
| 'edge', -- edge table |
| NULL, |
| 'pagerank_out', -- Output table of HITS |
| NULL, |
| 2); |
| |
| DROP TABLE IF EXISTS sssp_out, sssp_out_summary; |
| SELECT graph_sssp('vertex',NULL,'edge',NULL,0,'sssp_out'); |
| |
| DROP TABLE IF EXISTS wcc_out, wcc_out_summary; |
| SELECT weakly_connected_components( |
| 'vertex', |
| NULL, |
| 'edge', |
| NULL, |
| 'wcc_out'); |