PGQL Property Graph 查询语言

来源:互联网 发布:利用python写网络爬虫 编辑:程序博客网 时间:2024/05/22 15:57

http://pgql-lang.org/

m,n,o,p等只是一个节点的代号,e1,e2是边的名称代号



package net.wonderslife.src;


import java.io.IOException;
import java.util.concurrent.ExecutionException;


import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;


import oracle.pg.hbase.OraclePropertyGraph;
import oracle.pgx.api.PgqlResultSet;
import oracle.pgx.api.Pgx;
import oracle.pgx.api.PgxGraph;
import oracle.pgx.api.PgxSession;
import oracle.pgx.common.types.PropertyType;
import oracle.pgx.config.GraphConfigBuilder;
import oracle.pgx.config.PgHbaseGraphConfig;


public class PQL {
public static void main(String[] args) throws MasterNotRunningException, ZooKeeperConnectionException, IOException,
ExecutionException, InterruptedException {
pql1();
pql2();
pql3();
pql4();
}


private static void pql1() throws MasterNotRunningException, ZooKeeperConnectionException, IOException,
ExecutionException, InterruptedException {
String hbQuorum = "mypc1,mypc1";
String hbClientPort = "2181";
String hbGraphName = "people";
int splitsPerRegion = 2;
int dop = 8; // 并行度
int iClientPort = Integer.parseInt(hbClientPort);
PgHbaseGraphConfig cfg = GraphConfigBuilder.forPropertyGraphHbase().setName(hbGraphName).setZkQuorum(hbQuorum)
.setZkClientPort(iClientPort).setZkSessionTimeout(60000).setMaxNumConnections(dop)
.setSplitsPerRegion(splitsPerRegion).addVertexProperty("name", PropertyType.STRING, "empty name")
.addVertexProperty("country", PropertyType.STRING, "empty country")
.addVertexProperty("company", PropertyType.STRING, "empty company")
.addEdgeProperty("weight", PropertyType.DOUBLE, "1000000").setMaxNumConnections(2).build();
OraclePropertyGraph opg = OraclePropertyGraph.getInstance(cfg);
PgxSession session = Pgx.createSession("session-id-1");


PgxGraph pgxGraph = session.readGraphWithProperties(opg.getConfig());


// PQL 1


PgqlResultSet pgxResultSet = pgxGraph.queryPgql("SELECT m.name,n.name WHERE (m)->(n),m!=n");
pgxResultSet.print(10);


pgxResultSet.close();
pgxGraph.close();
session.close();
opg.shutdown();


}


// PGQLdemo语句
private static void pql2() throws MasterNotRunningException, ZooKeeperConnectionException, IOException,
ExecutionException, InterruptedException {
String hbQuorum = "mypc1,mypc1";
String hbClientPort = "2181";
String hbGraphName = "people";
int splitsPerRegion = 2;
int dop = 8; // 并行度
int iClientPort = Integer.parseInt(hbClientPort);
PgHbaseGraphConfig cfg = GraphConfigBuilder.forPropertyGraphHbase().setName(hbGraphName).setZkQuorum(hbQuorum)
.setZkClientPort(iClientPort).setZkSessionTimeout(60000).setMaxNumConnections(dop)
.setSplitsPerRegion(splitsPerRegion).addVertexProperty("name", PropertyType.STRING, "empty name")
.addVertexProperty("country", PropertyType.STRING, "empty country")
.addVertexProperty("company", PropertyType.STRING, "empty company")
.addEdgeProperty("weight", PropertyType.DOUBLE, "1000000").setMaxNumConnections(2).build();
OraclePropertyGraph opg = OraclePropertyGraph.getInstance(cfg);
PgxSession session = Pgx.createSession("session-id-1");


PgxGraph pgxGraph = session.readGraphWithProperties(opg.getConfig());


// PQL 1


PgqlResultSet pgxResultSet = pgxGraph.queryPgql(
"SELECT m.name,m.country,n.name,n.country WHERE (m with country='United States')-[e1 with weight>50]->(n with country='Russia'),m!=n");
pgxResultSet.print(10);


pgxResultSet.close();
pgxGraph.close();
session.close();
opg.shutdown();


}


// PGQLdemo语句
private static void pql3() throws MasterNotRunningException, ZooKeeperConnectionException, IOException,
ExecutionException, InterruptedException {
String hbQuorum = "mypc1,mypc1";
String hbClientPort = "2181";
String hbGraphName = "people";
int splitsPerRegion = 2;
int dop = 8; // 并行度
int iClientPort = Integer.parseInt(hbClientPort);
PgHbaseGraphConfig cfg = GraphConfigBuilder.forPropertyGraphHbase().setName(hbGraphName).setZkQuorum(hbQuorum)
.setZkClientPort(iClientPort).setZkSessionTimeout(60000).setMaxNumConnections(dop)
.setSplitsPerRegion(splitsPerRegion).addVertexProperty("name", PropertyType.STRING, "empty name")
.addVertexProperty("country", PropertyType.STRING, "empty country")
.addVertexProperty("company", PropertyType.STRING, "empty company")
.addEdgeProperty("weight", PropertyType.DOUBLE, "1000000").setMaxNumConnections(2).build();
OraclePropertyGraph opg = OraclePropertyGraph.getInstance(cfg);
PgxSession session = Pgx.createSession("session-id-1");


PgxGraph pgxGraph = session.readGraphWithProperties(opg.getConfig());


// PQL 1


PgqlResultSet pgxResultSet = pgxGraph.queryPgql(
"SELECT m.country,count(*) as cnt WHERE (m)-[e1 with weight>50]->(n),m!=n group by m.country order by cnt desc");
pgxResultSet.print(10);


pgxResultSet.close();
pgxGraph.close();
session.close();
opg.shutdown();


}


// PGQLdemo语句
private static void pql4() throws MasterNotRunningException, ZooKeeperConnectionException, IOException,
ExecutionException, InterruptedException {
String hbQuorum = "mypc1,mypc1";
String hbClientPort = "2181";
String hbGraphName = "people";
int splitsPerRegion = 2;
int dop = 8; // 并行度
int iClientPort = Integer.parseInt(hbClientPort);
PgHbaseGraphConfig cfg = GraphConfigBuilder.forPropertyGraphHbase().setName(hbGraphName).setZkQuorum(hbQuorum)
.setZkClientPort(iClientPort).setZkSessionTimeout(60000).setMaxNumConnections(dop)
.setSplitsPerRegion(splitsPerRegion).addVertexProperty("name", PropertyType.STRING, "empty name")
.addVertexProperty("country", PropertyType.STRING, "empty country")
.addVertexProperty("company", PropertyType.STRING, "empty company")
.addEdgeProperty("weight", PropertyType.DOUBLE, "1000000").setMaxNumConnections(2).build();
OraclePropertyGraph opg = OraclePropertyGraph.getInstance(cfg);
PgxSession session = Pgx.createSession("session-id-1");


PgxGraph pgxGraph = session.readGraphWithProperties(opg.getConfig());


// PQL 1


PgqlResultSet pgxResultSet = pgxGraph.queryPgql(
"SELECT m.name,n.name,o.name,p.name WHERE (m with country='United States')-[e1 with weight>50]->(n with country ='Russia') -[e2 with weight=1]->(o)->(p)");
pgxResultSet.print(10);


pgxResultSet.close();
pgxGraph.close();
session.close();
opg.shutdown();


}
}

原创粉丝点击