PuppyGraph
Search
K

Connecting to Apache Hudi

It is also possible to query existing data on Hudi directly without loading it to PuppyGraph. Here is an demo of the feature.
In the demo, the Hudi data source stores people and referral information. To query the data as a graph, we model people as vertices and the referral relationship between people as edges.

Prerequisites

The demo assumes that PuppyGraph has been deployed at localhost according to the instruction in AMI Version or Docker Deployment.
In this demo, we use the username puppygraph and password 888888.

Data Preparation (Optional)

Person Table
Referral Table
ID
Age
Name
v1
29
marko
v2
27
vadas
RefID
Source
Referred
Weight
e1
v1
v2
0.5
The demo uses people and referral information as shown above.
Here is the shell command to start a SparkSQL instance for data preparation assuming that the hudi data are stored on HDFS at 172.31.19.123:9000 and the Hive metastore is at 172.31.31.125:9083.
spark-sql --packages org.apache.hudi:hudi-spark3.3-bundle_2.12:0.13.0 \
--conf spark.hadoop.fs.defaultFS=hdfs://172.31.19.123:9000 \
--conf spark.sql.warehouse.dir=hdfs://172.31.19.123:9000/spark-warehouse \
--conf spark.sql.extensions=org.apache.spark.sql.hudi.HoodieSparkSessionExtension \
--conf spark.serializer=org.apache.spark.serializer.KryoSerializer \
--conf spark.sql.catalog.spark_catalog=org.apache.spark.sql.hudi.catalog.HoodieCatalog \
--conf spark.sql.catalog.spark_catalog.type=hive \
--conf spark.sql.catalog.puppy_hudi=org.apache.spark.sql.hudi.catalog.HoodieCatalog \
--conf spark.sql.catalog.puppy_hudi.type=hive \
--conf spark.sql.catalog.puppy_hudi.uri=thrift://172.31.31.125:9083
Now we can use the following SparkSQL query to create data in the database hudi_onhdfs. The catalog name is puppy_hudi as specified in the command above.
CREATE DATABASE hudi_onhdfs;
USE hudi_onhdfs;
CREATE EXTERNAL TABLE person (
ID string,
age int,
name string
) using hudi
tblproperties (
primaryKey = 'ID'
);
INSERT INTO person VALUES ('v1', 29, 'marko'), ('v2', 27, 'vadas');
CREATE EXTERNAL TABLE referral (
refId string,
source string,
referred string,
weight double
) using hudi
tblproperties (
primaryKey = 'refId'
);
INSERT INTO referral VALUES ('e1', 'v1', 'v2', 0.5);

Upload the schema

Now the data are ready in Hudi. We need a PuppyGraph schema before querying it. Let's create a schema file hudi.json:
hudi.json
{
"catalogs": [
{
"name": "catalog_test",
"type": "hudi",
"metastore": {
"type": "HMS",
"hiveMetastoreUrl": "thrift://172.31.31.125:9083"
}
],
"vertices": [
{
"label": "person",
"mappedTableSource": {
"catalog": "catalog_test",
"schema": "hudi_onhdfs",
"table": "person",
"metaFields": {
"id": "id"
}
},
"attributes": [
{
"type": "Int",
"name": "age"
},
{
"type": "String",
"name": "name"
}
]
}
],
"edges": [
{
"label": "knows",
"mappedTableSource": {
"catalog": "catalog_test",
"schema": "hudi_onhdfs",
"table": "referral",
"metaFields": {
"id": "refId",
"from": "source",
"to": "referred"
}
},
"from": "person",
"to": "person",
"attributes": [
{
"type": "Double",
"name": "weight"
}
]
}
]
}
Here are some notes on this schema:
  1. 1.
    A catalog catalog_test is added to specify the remote data source in Hudi. Note the hiveMetastoreUrl field has the same value as the one we used to create data.
  2. 2.
    The label of the vertices and edges do not have to be the same as the names of corresponding tables in Hudi. There is a mappedTableSource field in each of the vertex and edge types specifying the actual schema (onhdfs) and table (referral).
  3. 3.
    Additionally, the mappedTableSource marks meta columns in the tables. For example, the fieldsfrom and to describe which columns in the table form the endpoints of edges.
PuppyGraph supports query Iceberg / Hudi / Delta Lake with metastore: Hive metastore/ AWS Glue and with storage: HDFS/ AWS S3/ MinIO.
You can refer to catalog configuration examples we provide: Examples.
For more catalog parameters details, please refer to Data Lake Catalog.
Now we can upload the schema file hudi.json to PuppyGraph with the following shell command, assuming that the PuppyGraph is running on localhost:
curl -XPOST -H "content-type: application/json" --data-binary @./hudi.json --user "puppygraph:888888" localhost:8081/schema

Query the data

Connecting to PuppyGraph at http://localhost:8081 and start gremlin console from the "Query" section:
[PuppyGraph]> console
\,,,/
(o o)
-----oOOo-(3)-oOOo-----
plugin activated: tinkerpop.server
plugin activated: tinkerpop.utilities
plugin activated: tinkerpop.tinkergraph
Now we have connected to the Gremlin Console. We can query the graph:
gremlin> g.V().hasLabel("person").out("knows").values("name")
==>vadas