Connection Driver Reference
Ocient Python Module: pyocient
OCGraph Python Library
the ocient graph module brings a programming model (similar to {{spark}} graphx) to the {{ocient}} system directly from {{python}} using the pyocient driver the module treats a graph as two relational tables, one for vertices (nodes) and one for edges (directed links) this module provides a composable api for graph transformations, neighborhood analytics, and iterative algorithms (e g , pregel, pagerank) the api validates inputs, avoids destructive changes by materializing results into new tables, supports optional indexing for performance, and follows ocient sql conventions the package installs separately from pyocient and exposes a python native interface that mirrors the {{java}} library for details, see docid\ hoxig9l4m5f2kisrve3ge installation use pyocient for connectivity and ocient graph for graph apis the graph library is a separate package that depends on pyocient for a tutorial about installing and using pyocient , see docid\ jb9ujd1myi pollu9azdu install and import install the ocient graph module pip install ocient graph import the module from pyocient import connect from ocient graph import ( subgraph, collect neighbors, edgedirection, ) data model requirements database tables that use the ocgraph python library must adhere to this structure in addition to the listed requirements, tables can include other columns true 200,200,201 unhandled content type unhandled content type unhandled content type unhandled content type unhandled content type unhandled content type unhandled content type unhandled content type unhandled content type subgraph and filtering use a subgraph or various filters to restrict a graph to relevant vertices and edges these functions create filtered copies or masked intersections, preserving schema and optional indexes for performance subgraph creates filtered vertex and edge tables using vertex and triplet predicates, retaining only edges with endpoints that remain after vertex filtering the function creates the requested indexes and performs best effort cleanup in the event of failure syntax subgraph( connection, input schema, input vertices table, input edges table, result schema, result vertices table, result edges table, vertex filter, edge filter, \[ result vertices indexes \[ , ] ], \[ result edges indexes \[ , ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example create an active customer subgraph that includes only purchases exceeding $50 where the source and destination share a region subgraph( connection, "sales", "customers", "purchases", "sales", "customers active", "purchases active", "status = 'active' and score > 0", "b amount > 50 and a region = c region", \["id","region"], \["srcid","destid"], ) filter vertices creates a filtered subgraph by selecting vertices that match a predicate while retaining only edges with endpoints that are in the filtered vertex set syntax filter vertices( connection, input schema, input vertices table, input edges table, result schema, result vertices table, result edges table, vertex filter, \[ result vertices indexes \[ , ] ], \[ result edges indexes \[ , ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example filter us customers and retain edges with endpoints that remain in the filtered vertex set filter vertices( connection, "sales", "customers", "purchases", "sales", "customers us", "purchases us", "country = 'us'", \["id"], \["srcid","destid"], ) filter edges creates a filtered edges table by selecting edges that match a predicate syntax filter edges( connection, input schema, input edges table, result schema, result edges table, edge filter, \[ result edges indexes \[, ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example this example demonstrates how to create a filtered edges table from an existing purchases edge set by keeping only edges that meet a business rule ( weight > 0 5 and active ) then, the filteredges method indexes the result on the srcid and destid columns for faster lookups filter edges( connection, "sales", "purchases", "sales", "purchases filtered", "weight > 0 5 and type = 'active'", \["srcid", "destid"], ) mask creates a masked subgraph by intersecting two graphs vertices intersect if the vertex identifier is present in both graphs edges intersect when the srcid and destid values are present in both graphs the function creates a masked subgraph from rows that intersect with each other the function copies rows that intersect from the graph defined by the arguments input vertices table and input edges table , including any attributes you can optionally create indexes on the result subgraph tables syntax mask( connection, input schema, input vertices table, input edges table, other schema, other vertices table, other edges table, result schema, result vertices table, result edges table, \[ result vertices indexes \[ , ] ], \[ result edges indexes \[ , ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left 1 1 unhandled content type left 1 1 unhandled content type left 1 1 unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example create a masked subgraph by intersecting two graphs the example copies vertices and edges that are present in both graphs, along with the remaining endpoints mask( connection, "sales", "customers", "purchases", "ref", "customers ref", "purchases ref", "sales", "customers masked", "purchases masked", \["id"], \["srcid", "destid"], ) transformations construct new vertex or edge tables by computing derived columns, reversing direction, or aggregating duplicates these functions do not change the original inputs instead, the functions materialize new results map vertices creates a new vertices table with the identifier id and computed columns use the result column expressions argument to calculate additional columns this function can also add indexes before inserting data syntax map vertices( connection, input schema, input vertices table, result schema, result vertices table, result column expressions, \[ result vertices indexes \[, ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example create a new vertices table with two new columns, name upper and is vip , and generate indexes for the id and name upper columns map vertices( connection, "sales", "customers", "sales", "customers enriched", \[ "upper(name) as name upper", "case when score > 1000 then true else false end as is vip", ], \["id","name upper"], ) map edges creates a new edges table with srcid , destid , and any additional computed columns expressions should refer to input edge columns by their original names, and each computed expression should include an as alias keyword syntax map edges( connection, input schema, input edges table, result schema, result edges table, \[ result column expressions \[, ] ], \[ result edges indexes \[, ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example create a new edges table with two columns, discounted amount and big txn , and generate indexes for the srcid and destid columns map edges( connection, "sales", "purchases", "sales", "purchases enriched", \[ "amount 0 9 as discounted amount", "case when amount > 100 then 1 else 0 end as big txn", ], \["srcid","destid"], ) map triplets creates a new edges table with computed columns that reference a (source vertex), b (edge), and c (destination vertex) the output automatically includes b srcid and b destid columns syntax map triplets( connection, input schema, input vertices table, input edges table, result schema, result edges table, \[ result column expressions \[, ] ], \[ result edges indexes \[, ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example create a new triplet table from the vertices and edges tables with the amount and same country columns, and generate indexes for the src and destid columns map triplets( connection, "sales", "customers", "purchases", "sales", "purchases triplets", \[ "b amount as amount", "case when a country = c country then 1 else 0 end as same country", ], \["srcid","destid"], ) reverse edges creates a new edges table with the srcid and destid columns reversed, preserving other columns use this function to traverse a graph in the opposite direction syntax reverse edges( connection, input schema, input edges table, result schema, result edges table \[ result edges indexes \[, ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example transform edge direction by reversing the srcid and destid columns the example also creates indexes for these columns reverse edges( connection, "sales", "purchases", "sales", "purchases reversed", \["srcid","destid"], ) group edges groups duplicate rows of the srcid and destid columns, producing one row for each unique pair of values in a new edges table this function performs aggregations based on one or more sql expressions syntax group edges( connection, input schema, input edges table, result schema, result edges table, \[ result column expressions \[, ] ], \[ result edges indexes \[, ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example create a new edge table that includes sql aggregations for counting unique transactions txn count and total sums total amount also, this function generates indexes for the src and destid columns group edges( connection, "sales", "purchases", "sales", "purchases grouped", \[ "count( ) as txn count", "sum(amount) as total amount", ], \["srcid","destid"], ) triplets produce triplet representations that are made of a (source vertex), b (edge), and c (destination vertex), either as a logical view or a materialized table for downstream queries create triplets view creates a view that combines the edge table with the source and destination vertex attributes this view is useful for analyzing relationships without having to repeatedly join tables the view includes these columns all original edge columns (including the srcid and destid columns) all source vertex columns except id source vertex column names have the src prefix all destination vertex columns except id destination vertex column names have the dest prefix use the docid\ hnemo4f1y3sslallr03vp function instead if you want to create a materialized table with indexes instead of a view syntax create triplets view( connection, input schema, input vertices table, input edges table, result schema, result triplets view ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example create a triplets view to inspect edges with joined source and destination vertex attributes create triplets view( connection, "sales", "customers", "purchases", "sales", "triplets v", ) create triplets table creates a materialized table that combines the edge table with the source and destination vertex attributes this table is useful for analyzing relationships without having to repeatedly join tables the created table includes these columns all original edge columns (including the srcid and destid columns) all source vertex columns except id source vertex column names have the src prefix all destination vertex columns except id destination vertex column names have the dest prefix use the docid\ hnemo4f1y3sslallr03vp function if you want to create a view instead of a new table syntax create triplets table( connection, input schema, input vertices table, input edges table, result schema, result triplets table, \[ result triplets indexes \[, ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example create a new table for triplets generate indexes for the src id and dest id columns create triplets table( connection, "sales", "customers", "purchases", "sales", "triplets t", \["srcid","destid"], ) degrees compute degree metrics for each vertex from the edges table these functions produce small vertex tables suitable for joins and analytics in degrees computes how many edges point to each vertex in an edge table by counting how many times each unique destid value appears the result table has two columns id (the destination vertex) and in degree (the count) syntax in degrees( connection, input schema, input edges table, result schema, result vertices table, \[ result vertices indexes \[, ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example compute in degrees per vertex and generate an index on the id column in degrees( connection, "sales", "purchases", "sales", "customers in degree", \["id"], ) out degrees computes how many edges originate from each vertex in an edge table by counting how many times each unique srcid value appears the result table has two columns id (the source vertex) and out degree (the count) syntax out degrees( connection, input schema, input edges table, result schema, result vertices table, \[ result vertices indexes \[, ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example compute the out degrees count for each vertex and generate an index on the id column out degrees( connection, "sales", "purchases", "sales", "customers out degree", \["id"], ) degrees computes the total degrees (in degrees and out degrees) for each vertex in an edge table by counting how many times each unique srcid and destid value appears the result table has two columns id (the destination or source vertex) and degree (the count) syntax degrees( connection, input schema, input edges table, result schema, result vertices table, \[ result vertices indexes \[, ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example compute total degrees for each vertex and generate an index on the id column degrees( connection, "sales", "purchases", "sales", "customers degree", \["id"], ) vertex extraction and joins build vertex sets from edges and combine vertex attributes across tables these functions are useful for shaping vertex properties and consolidating features from edges builds a vertices table from an edges table by extracting the unique source and destination identifiers this function can optionally compute additional columns using sql expressions by referencing the unique identifier as ids id the created table always contains the id column with one additional column per expression syntax from edges( connection, input schema, input edges table, result schema, result vertices table, \[ result column expressions \[ , ] ], \[ result vertices indexes \[ , ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example create a vertices table from edge endpoints and add a bucket column that assigns each vertex to one of 10 buckets generate an index for the id and bucket columns from edges( connection, "sales", "purchases", "sales", "customers from edges", \["ids id % 10 as bucket"], \["id","bucket"], ) join vertices merges two vertices tables by retaining every row from a primary table ( input vertices table ) and selectively updating rows that also appear in the modification table ( modification vertices table ) the merged table includes all vertices from the primary table that do not appear in the modification table for vertices that appear in both tables, the function must include a list of expressions ( resultattributeexpressions ) in the same column order for every non identifier column in the merged result table these sql expressions can add computations to columns, or simply add aliases if no changes are needed each expression can reference columns from the primary table (using alias a ) or from the modification table (using alias b ) syntax join vertices( connection, input schema, input vertices table, modification schema, modification vertices table, result schema, result vertices table, result attribute expressions \[ , ], \[ result vertices indexes \[ , ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example merge vertex attributes and generate indexes for the id and status columns this example includes two sql expressions to update the status and score columns based on the modification vertex table using the coalesce sql reference function join vertices( connection, "sales", "customers", "sales", "customers updates", "sales", "customers merged", \[ "coalesce(b new status, a status) as status", "coalesce(b score delta + a score, a score) as score", ], \["id","status"], ) inner join vertices performs an inner join on two vertex tables using an equality comparison a id = b id the result table automatically includes the id column from the first table the function must include a list of sql expressions ( result attribute expressions ) in the same column order for every non identifier column in the merged result table these sql expressions can add computations to columns, or simply add aliases if no changes are needed each expression can reference columns from the primary table using the alias a or from the modification table using the alias b syntax inner join vertices( connection, input schema, input vertices table, other schema, other vertices table, result schema, result vertices table, result attribute expressions \[ , ], \[ result vertices indexes \[ , ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example create an inner join between two vertex tables and generate an index on the id column inner join vertices( connection, "sales", "customers", "sales", "profiles", "sales", "customers joined", \[ "a id as id", "a status as status", "b tier as tier", ], \["id"], ) outer join vertices performs a left outer join between two vertices tables using an equality comparison a id = b id the result table includes all rows from the left table for left table rows that have no match in the right table, any expression that reads columns from the right table with the alias b evaluates to null (while expressions that only read the table with the alias a remain non null as usual) the method must include a list of sql expressions ( result attribute expressions ) in the same column order for every non identifier column in the merged result table these sql expressions can add computations to columns, or simply add aliases if no changes are needed each expression can reference columns from the primary table using the alias a or from the modification table using the alias b syntax outer join vertices( connection, input schema, input vertices table, other schema, other vertices table, result schema, result vertices table, result attribute expressions \[ , ], \[ result vertices indexes \[ , ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example perform a left outer join on two vertices tables and generate an index on the id column outer join vertices( connection, "sales", "customers", "sales", "profiles", "sales", "customers joined", \[ "a id as id", "a status as status", "b tier as tier", ], \["id"], ) collect neighbors for each vertex in a table, this function collects information on neighbors (identifier and any attributes) as an array of tuples for a specified direction ( in , out , or both ), the function aggregates tuples representing each neighboring vertex into an array the direction types are in — neighbors with edges pointing to the vertex (edges where destid = id ) out — neighbors that the vertex points to (edges where srcid = id ) both — union of in and out with neighbors from incoming ( destid = id ) and outgoing ( srcid = id ) edges the result table has the columns id (the vertex identifier) and neighbors (an array of tuples representing each neighbor) if an error occurs after table creation, the function drops the result table syntax collect neighbors( connection, input schema, input vertices table, input edges table, result schema, result table, direction, \[ result indexes \[ , ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example collect incoming neighbors for each vertex and generate an index on the id column the direction argument set to in collects neighbors pointing to id collect neighbors( connection, "sales", "customers", "purchases", "sales", "neighbors in", edgedirection in, \["id"], ) collect edges for each vertex in a table, this function collects an array of adjacent edge rows based on the specified direction the result table has two columns id (the vertex identifier) and edges (an array of tuples, each tuple containing all columns from the edges table for a connected edge) the direction types are in — edges pointing to the vertex (edges where destid = id ) out — edges originating from the vertex (edges where srcid = id ) both — union of in and out that includes edges from incoming ( destid = id ) and outgoing ( srcid = id ) directions this direction retains duplicates if an error occurs after table creation, the function drops the result table syntax collect edges( connection, input schema, input vertices table, input edges table, result schema, result table, direction, \[ result indexes \[ , ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example collect outgoing edges per vertex the example sets the direction to out to collect edges from id collect edges( connection, "sales", "customers", "purchases", "sales", "outgoing edges", edgedirection out, \["id"], ) algorithms high level graph algorithms that iterate over the graph structure to produce labels, components, or counts label propagation executes the https //en wikipedia org/wiki/label propagation algorithm (lpa) to assign community labels to vertices each vertex starts with its own identifier as its label for a number set by the maxiterations argument, each vertex updates its label to the most frequent label among its neighbors the algorithm determines ties by choosing the smallest label the algorithm uses temporary tables for intermediate results and drops these tables when the process completes or if it fails isolated vertices retain their initial label the final table stores id and label columns and can include indexes syntax label propagation( connection, input schema, input vertices table, input edges table, result schema, result vertices table, max iterations, result vertices indexes, \[ result vertices indexes \[ , ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example run label propagation for 10 iterations and assign labels to vertices generate an index on the id column label propagation( connection, "sales", "customers", "purchases", "sales", "lpa labels", 10, \["id"], ) connected components identifies the connected components of an undirected graph this algorithm configures a pregel computation in which each vertex initially sets its component label equal to its own identifier id in each iteration, vertices send their component label to neighbors each vertex updates based on the aggregated minimum value of its current component label and any received values the process repeats until no more updates occur or when it reaches the maximum specified number of iterations ( max iterations ) the result table maps each vertex id to its final component label syntax connected components( connection, input schema, input vertices table, input edges table, result schema, result vertices table, max iterations, \[ result vertices indexes \[ , ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example compute connected components for a maximum of 20 iterations and generate an index on the id column connected components( connection, "sales", "customers", "purchases", "sales", "components", 20, \["id"], ) strongly connected components computes strongly connected components (scc) in a directed graph this function runs a recursive algorithm that partitions vertices into subsets where every vertex is reachable from other vertices in the same subset this function uses recursive partitioning the algorithm selects a pivot (typically the minimum identifier id ), computes its predecessor set (vertices that can reach the pivot), and its descendant sets (vertices reachable from the pivot) then, the function identifies the scc as their intersection, removes that scc from the graph, and recurses on the remainder until all vertices have been assigned to an scc the output contains columns for the id and component identifiers (the minimum id in the scc) the function creates temporary tables in the result schema to store intermediate results this function drops these tables when the computation completes or fails the final result table contains two columns id (vertex identifier) and component (the minimum vertex identifier in its scc subset) syntax strongly connected components( connection, input schema, input vertices table, input edges table, result schema, result vertices table, \[ result vertices indexes \[ , ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example compute the scc and generate an index on the id column strongly connected components( connection, "sales", "customers", "purchases", "sales", "scc", \["id"], ) trianglecount trianglecount identifies all 3 cycles (triangles) in the graph and counts how many distinct triangles each vertex participates in the algorithm first builds a canonical, undirected edge set by ensuring srcid < destid and removing duplicates to prevent double counting if your input edges are already canonicalized and deduplicated, use trianglecount run pre canonicalized to skip preprocessing for faster performance the function then counts triangles ( a , b , c ) where a < b < c by intersecting neighbor lists and aggregates per vertex participation to produce a result table with the id and triangle count columns run syntax trianglecount run( input schema, input vertices table, input edges table, result schema, result vertices table, \[ result vertices indexes \[ , ] ], ) run pre canonicalized syntax trianglecount run pre canonicalized( connection, input schema, input vertices table, canonical edges schema, canonical edges table, result schema, result vertices table, \[ result vertices indexes \[ , ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left 1 1 unhandled content type left 1 1 unhandled content type left 1 1 unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type examples count triangles using run canonicalize the raw edges internally, count unique triangles, and write per vertex triangle counts with an index on the id column trianglecount run( connection, "sales", "customers", "purchases", "sales", "triangle counts", \["id"], ) count triangles using run pre canonicalized use a pre canonicalized, deduplicated edge table to count triangles and write per vertex triangle counts with an index on the id column trianglecount run pre canonicalized( connection, "sales", "customers", "sales", "purchases canonical", "sales", "triangle counts", \["id"], ) pregel provides a generic vertex‑centered iteration framework for custom graph algorithms, similar to the https //research google/pubs/pregel a system for large scale graph processing/ each iteration updates vertex states by sending messages along edges and then aggregating these messages to compute new states the algorithm continues iterating until it reaches convergence (no state changes or no messages produced) or a specified iteration cap the algorithm uses multiple specified sql expressions syntax pregel( connection, input schema, input vertices table, input edges table, result schema, result vertices table, initializer expr, send to source expr, send to dest expr, aggregate expr, updater expr, max iterations, \[ result vertices indexes \[ , ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example run a simple pregel computation summing incoming edge amounts into the vertex state for 10 iterations at most, and generate an index on the id column pregel( connection, "sales", "customers", "purchases", "sales", "pregel result", "0 as state", "b amount", none, "sum(msg) as aggregated message", "state + coalesce(aggregated message, 0) as state", 10, \["id"], ) paths & ranking these functions include the shortest path and pagerank algorithms shortest paths computes the shortest distance from every vertex to each set of landmark vertices using an iterative relaxation algorithm the algorithm resembles https //en wikipedia org/wiki/bellman%e2%80%93ford algorithm but simultaneously handles multiple destinations each landmark starts at distance 0 and all others at positive infinity on each iteration, the algorithm examines every edge and checks whether traveling through the connected neighbor would yield a shorter route to a landmark if a shorter route exists, the algorithm updates the distance of the source vertex the process stops when no distances improve or the algorithm reaches the maximum number of iterations after the process finishes, the algorithm writes a result table with the srcid , destid , and distance columns syntax shortest paths( connection, input schema, input vertices table, input edges table, result schema, result table, landmarks\[ , ], edge weight column, max iterations, \[ result vertices indexes \[ , ] ] ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example compute distances from landmarks and generate indexes on the src and dest columns shortest paths( connection, "sales", "customers", "purchases", "sales", "distances", \[1, 42], none, 10, \["srcid","destid"], ) static page rank computes https //en wikipedia org/wiki/pagerank scores for each vertex over a fixed number of iterations the algorithm follows the standard pagerank formula with a reset probability ( reset prob ) and uses common table expressions to calculate contributions from incoming edges and redistribute ranks from dangling nodes the algorithm supports two variants standard pagerank — all vertices start with rank 1 0/n , where n is the number of vertices specify this variant if personalizationsrcid is null personalized pagerank — the specified vertex starts with a rank of 1 0 , while others start with a rank of 0 0 specify this variant if personalizationsrcid is a vertex identifier after running pagerank for a fixed number of iterations, the function writes a result vertices table containing all original vertex columns with a new pagerank scoring column syntax static page rank( connection, input schema, input vertices table, input edges table, result schema, result vertices table, num iterations, reset prob, \[ result vertices indexes \[ , ] ], personalization src id, ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example run fixed iteration pagerank and generate an index on the id column this example uses a high reset probability reset prob of 0 85 to ensure the ranking concentrates on highly linked regions static page rank( connection, "sales", "customers", "purchases", "sales", "pagerank static", 10, 0 85, \["id"], none, ) dynamic page rank computes pagerank scores until convergence based on a specified threshold value ( tolerance ) unlike the docid\ hnemo4f1y3sslallr03vp function, this algorithm runs iterations until the sum of absolute differences between ranks in successive iterations is less than or equal to the tolerance value the algorithm handles personalization similarly to static page rank at each iteration, the function uses the pagerank formula, collects rank values, and redistributes them the algorithm supports two variants standard pagerank — all vertices start with rank 1 0/n , where n is the number of vertices specify this variant if personalizationsrcid is null personalized pagerank — the specified vertex starts with a rank of 1 0 , while others start with a rank of 0 0 specify this variant if personalizationsrcid is a vertex identifier after running pagerank until the system reaches the tolerance threshold, the function writes a vertices table containing all the original vertex columns with a new pagerank scoring column syntax dynamic page rank( connection, input schema, input vertices table, input edges table, result schema, result vertices table, tolerance, reset prob, \[ result vertices indexes \[ , ] ], personalization src id, ) true 200,200,201left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type example run dynamic pagerank to convergence and generate an index on the id column this example uses a low tolerance value of 1 0e 6 , which generates high precision rankings but requires more computing resources dynamic page rank( connection, "sales", "customers", "purchases", "sales", "pagerank dynamic", 1 0e 6, 0 85, \["id"], none, ) bibliography pregel a system for large scale graph processing ” accessed november 18, 2025 https //research google/pubs/pregel a system for large scale graph processing/ related links docid\ hoxig9l4m5f2kisrve3ge docid\ jb9ujd1myi pollu9azdu