PGQL Property Graph 查询语言

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();


}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值