Prerequisites
The prerequisites for running the page rank solve graph example are listed below:- Graph server enabled
- Python API
- Solve graph script
- NYC Taxi dataset ingested (see Demo for more information)
- NYC Neighborhood CSV file
Python API Installation
Depending on the target operating system, a Python virtual environment may need to be installed first: The native Kinetica Python API is accessible through the following means:Python Virtual Environment
A Python virtual environment is necessary to install in an operating environment where Python is externally managed.-
Install a Python virtual environment:
-
Activate the Python virtual environment:
PyPI
-
Install the API:
-
Test the installation:
If Import Successful is displayed, the API has been installed as is ready for use.
Git
-
In the desired directory, run the following, but be sure to replace
<kinetica-version>with the name of the installed Kinetica version, e.g.,v7.2: -
Change directory into the newly downloaded repository:
-
In the root directory of the unzipped repository, install the Kinetica API:
-
Test the installation (Python3 is necessary for running the API example):
Data File
The example script references the nyc_neighborhood.csv data file, mentioned in the Prerequisites, in the current local directory, by default. This directory can specified as a parameter when running the example script.Script Detail
This example is going to demonstrate solving for the most popular pickup or dropoff point in New York City by ranking pickup and dropoff locations in terms of how frequently passengers are getting picked up/dropped off there. The more connected a point is in relation to other points, the greater its importance.Constants
Several constants are defined at the beginning of the script:-
SCHEMA— the name of the schema in which the tables supporting the graph creation and match operations will be createdThe schema is created during the table setup portion of the script because the schema must exist prior to creating the tables that will later support the graph creation and match operations. -
TABLE_NYC_N— the name of the table into which the NYC Neighborhood dataset is loaded. This dataset is joined to theTABLE_TAXItable to create theJOIN_TAXIdataset. -
TABLE_TAXI— the name of the table into which the NYC taxi dataset is loaded. This dataset is joined to theTABLE_NYC_Ntable to create theJOIN_TAXIdataset. -
TABLE_TAXI_E— the name of the projection derived from theJOIN_TAXIdataset that serves as the edges for theGRAPH_Tgraph. -
TABLE_TAXI_N— the name of the union derived from theJOIN_TAXIdataset that serves as the nodes for theGRAPH_Tgraph. -
TABLE_TAXI_N_S— the same asTABLE_TAXI_Nbut later sharded so it can be joined to thenyctaxi_graph_idgraph. -
JOIN_TAXI— the name of the join view that represents the dataset of all the trips found in theTABLE_TAXIdataset that overlap with the neighborhood boundaries found in theTABLE_NYC_Ndataset -
JOIN_PR_RESULTS— the name of the join view that represents the dataset of all the nodes found in theTABLE_TAXI_Nwhere the ID matches theSOLVERS_NODE_IDfound inTABLE_GRAPH_T_PRSOLVED_S -
GRAPH_T— the NYC taxi graph -
TABLE_GRAPH_T_PRSOLVED— the solved NYC taxi graph using thePAGE_RANKsolver type -
TABLE_GRAPH_T_PRSOLVED_S— the same asTABLE_GRAPH_T_PRSOLVEDbut later sharded so it can be joined to thenyctaxi_nodes_shardedtable.
Constant Definitions
Graph Creation
One graph is used for this example:nyctaxi_graph_id, a graph utilizing
IDs based on a modified version of the standard NYC Taxi dataset (mentioned in
Prerequisites).
To filter out data that could skew graph nyctaxi_graph_id, the
NYC Neighborhood dataset must be inserted into Kinetica and joined to the
NYC Taxi dataset using STXY_CONTAINS to remove any trip points in the NYC
Taxi dataset that are not contained within the geospatial boundaries of the
NYC Neighborhood dataset:
Perform Geospatial Filter of Taxi Data by NYC Neighborhoods
nyctaxi_graph_id can be created, the edges must be derived from
the taxi_tables_joined dataset’s XY pickup and dropoff pairs to create the
nyctaxi_edges_id dataset:
Create Node & Edge Tables from Taxi Trips
nyctaxi_graph_id is created with the following characteristics:
- It is not directed because direction is irrelevant to this example
- The
nodesin this graph are represented using the IDs created from the union of pickup and dropoff points IDs of thenyctaxi_nodestable (ID). - The
edgesin this graph are using the individual pickup and dropoff point IDs of thenyctaxi_edges_idtable as the edge endpoints (NODE1_ID/NODE2_ID). - It has no
weightsbecause one does not need to influence the ranking in any way - It has no inherent
restrictionsfor any of the nodes or edges in the graph - It will be replaced with this instance of the graph if a graph of the same
name exists (
recreate).
Create NYC Taxi Routes Graph
Page Rank
The graph is solved:Solve Graph
A source node ID was selected at random from the
nyctaxi_nodes. Since page rank is ranking each node’s
connectedness in relation to other nodes, any node can be the
sourcenyctaxi_nodes union (created earlier) is created
so it can be joined:
Shard Node Table for Geospatial Join with Graph Solution
nyctaxi_graph_id_page_rank_solved table is also
created so it can be joined to the nyctaxi_nodes union:
Shard Graph Solution for Geospatial Join with Node Table
Join Node Table with Graph Solution
Page Rank Results
Download & Run
Included below is a complete example containing all the above requests, the data files, and output. To run the complete sample, ensure that:- the NYC Taxi dataset has been loaded into the database
- the solve_graph_nyctaxi_page_rank.py script is in the current directory
- the nyc_neighborhood.csv file is in the current directory or
use the
data_dirparameter to specify the local directory containing it
Run Example