/dak:bigquery-graph-queryfrom dak
Guides querying BigQuery property and semantic graphs using native GQL, GRAPH_TABLE, and GRAPH_EXPAND TVF. Covers pattern matching, multi-hop paths, aggregation, hybrid semantic search with VECTOR_SEARCH.
Ships in dak. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You are querying a BigQuery property graph or semantic graph. You MUST exclusively use the BigQuery GoogleSQL GQL and SQL standards. NEVER, under any circumstances, generate or consider Cypher queries. Follow the instructions below exactly rather than relying on general graph-query knowledge.
Before writing any query, determine whether you are querying a Property Graph or a Semantic Graph:
<property_graph> DDL / node & edge tables.GRAPH ... MATCH ... RETURN) by default; GRAPH_TABLE if joining
relational tables.<semantic_graph start_node="X"> flattened
views.GRAPH_EXPAND TVF with
start_node => "X" and AGG() measures.<semantic_graph start_node="X">
view.GRAPH_TABLE over the <property_graph> with manual SQL aggregations.This document is self-sufficient for the vast majority of questions,
including matching, multi-hop and variable-length paths, filtering,
aggregation / grouping / top-N, existence checks, output formatting, and
GRAPH_EXPAND queries. For these, generate the query directly from the rules
below — do not open the companion files.
Only read a companion file when the query genuinely needs one of these uncommon capabilities:
GRAPH_TABLE):
graph-table-and-sql-integration.mdSOURCE_NODE_ID,
DESTINATION_NODE_ID, ELEMENT_ID, LABELS), or deep performance
tuning of a slow/large traversal beyond the optimization rules in this
core:
gql-advanced-functions-and-perf.mdVALUE/ARRAY subquery correlation limits):
gql-subqueries.mdVECTOR_SEARCH before traversal (embedding calls
bill per invocation — do not open this otherwise):
hybrid-vector-graph-search.mdIf none of the above clearly applies, this core document is sufficient.
Before generating any GQL, you MUST:
TO_JSON()) or view tabular data (requires
specific properties).RETURN statement natively
(GRAPH ... MATCH ... RETURN). This natively supports aggregation,
grouping, and top-N (see below). Only use the GRAPH_TABLE table-valued
function when you must join graph results with a separate relational table
(see the SQL-integration reference).order, begin, path used as
column, label, or variable names).:Person, :Account)
and properties (e.g., n.id, e.amount) used in the query MUST match the
provided graph schema. Do NOT guess or hallucinate schema elements.DISTINCT in your RETURN/COLUMNS clause when
the user prompt implies they want unique results.MATCH p = ...).A GQL query names the graph, then chains clauses that pipe a "working table"
from one to the next: MATCH, LET (define a variable/alias), FILTER (filter
intermediate results — this is the GQL clause, used between clauses instead of a
trailing WHERE), WITH (project/sort/group into the next scope), ORDER BY /
LIMIT / OFFSET, and RETURN (project the final output).
GRAPH <project>.<dataset>.<graph>
MATCH (src:Account)-[t:Transfers]->(dst:Account)
LET transfer_amount = t.amount
FILTER transfer_amount > 1000
WITH src, dst, transfer_amount
ORDER BY transfer_amount DESC
LIMIT 50
RETURN src.id AS source, dst.id AS destination, transfer_amount
Chaining with NEXT: Compose multiple linear statements into one compound
query with the NEXT keyword — the results of the statement before NEXT pipe
into the statement after it.
You do NOT need GRAPH_TABLE for aggregation, grouping, counts, sums,
averages, "how many", "most/least", or "top N". Standalone GQL handles these
natively — this covers the majority of analytical questions:
RETURN (or WITH): COUNT(*),
COUNT(DISTINCT x), SUM(e.amount), AVG(...), MIN/MAX.RETURN/WITH
become the grouping keys automatically (like standard GQL grouping). There
is no separate GROUP BY clause in standalone GQL — group by listing the
key columns alongside the aggregate.ORDER BY <agg> DESC then LIMIT <n>.-- "Which 3 entities filed the most filings?" (grouping + top-N, no GRAPH_TABLE)
GRAPH <project>.<dataset>.<graph>
MATCH (e:Entity)-[:Filed]->(f:Filing)
RETURN e.name AS entity, COUNT(f) AS filing_count
ORDER BY filing_count DESC
LIMIT 3
-- "Total transferred out per account" (grouped aggregate)
GRAPH <project>.<dataset>.<graph>
MATCH (src:Account)-[t:Transfers]->(:Account)
RETURN src.id AS account, SUM(t.amount) AS total_out
ORDER BY total_out DESC
Use GRAPH_TABLE (load the SQL-integration reference) only when you must
JOIN graph output with a separate relational table or feed outer-table values
into the graph scope.
For "entities that have / do not have a relationship", "at least one", "where
there exists ..." questions, use a subquery. Two rules prevent the common errors
(load the subqueries reference only for VALUE/ARRAY correlation edge cases):
FILTER, not WHERE, for EXISTS / IN / LIKE subqueries.
These throw errors inside a WHERE clause.{ ... } must repeat GRAPH <project>.<dataset>.<graph> even though the
outer query already declared it.GRAPH <project>.<dataset>.<graph>
MATCH (p:Person)
FILTER EXISTS {
GRAPH <project>.<dataset>.<graph>
MATCH (p)-[:Owns]->(:Account)
}
RETURN p.name
Node patterns use parentheses (); edge patterns use square brackets []
connected with arrows for direction. The BigQuery-specific rules:
MATCH (p:Person|Account): the | label expression matches nodes that have
either label (OR). You cannot use & in a label expression.MATCH (p:Person {id: 1}): property-filter shorthand.MATCH (p:Person WHERE p.age > 18): inline WHERE condition on properties.MATCH (a)-[e:Transfers]->(b): directed edge (preferred).MATCH (a)-[e:Transfers {amount: 50}]->(b): edge with a property filter.MATCH (a)-[e:Transfers]-(b): undirected (any direction) — avoid;
specify explicit direction for better performance.A complex pattern is one or more path patterns separated by commas ,. If two
comma-separated patterns share a variable, BigQuery performs an equijoin
on it; if they share none, the result is a cross join.
GRAPH <project>.<dataset>.<graph>
MATCH (src:Account)-[t1:Transfers]->(interm:Account),
(interm)<-[:Owns]-(p:Person)
RETURN src.id AS account_id, p.name AS owner_name
Find multi-hop connections by appending a quantifier to an edge pattern. This syntax differs from Cypher — use the BigQuery form:
{m, n}: repeat the edge pattern between m and n times, e.g.
-[e:Transfers]->{1,3}.e in
-[e:Transfers]->{1,3}), e becomes a group variable — an array of the
matched edges in the path. Interact with it using array functions
(ARRAY_LENGTH(e)) or horizontal aggregation (SUM(e.amount)).Variable-length paths can produce exponential combinations and repeating paths. Constrain the search between each source/destination pair with a prefix placed immediately before the path pattern:
ANY: exactly one arbitrary matching path per unique source/destination
pair.ANY SHORTEST: a single path with the minimum number of edges (hops).ANY CHEAPEST: a single path with the minimum total cost, aggregating
COST expressions defined on the edges.GRAPH <project>.<dataset>.<graph>
MATCH ANY SHORTEST
(a:Account {id: 123})-[e:Transferred]->{1,3}(b:Account {id: 456})
RETURN e
When an entire path is bound to a variable (MATCH p = (...)), extract metadata
and elements from it:
PATH_FIRST(p) / PATH_LAST(p): the starting / terminal node of path p.PATH_LENGTH(p): an INT64 count of the edge hops in path p.NODES(p) / EDGES(p): an array of the node / edge elements, ordered by
their sequence in the path.GRAPH <project>.<dataset>.<graph>
MATCH p = (a:Account)-[t:Transfers]->{1,3}(b:Account)
RETURN PATH_LENGTH(p) AS hops, TO_JSON(NODES(p)) AS path_nodes
For SOURCE_NODE_ID, DESTINATION_NODE_ID, ELEMENT_ID, and LABELS, load
the advanced-functions reference.
Strictly distinguish graph visualization intent from tabular data intent
when constructing the RETURN/COLUMNS clause.
Use when the user wants to see relationships, paths, topology, networks, connectivity, or entire entities (nodes/edges) as a whole. Triggers: "visualize", "show the graph", "network", "connections", "find the path", "relationship between X and Y".
TO_JSON(): unless specific properties (e.g., n.name) or
path metrics (e.g., PATH_LENGTH(p)) are explicitly requested, you MUST
wrap all graph topology outputs (nodes, edges, and path variables) in
TO_JSON() so the graphing UI receives full JSON objects.LIMIT 500 unless the user requests a different
number, to avoid overwhelming the UI.GRAPH <project>.<dataset>.<graph>
MATCH p = (:Person)-[:Knows]->(:Person)
RETURN TO_JSON(p) AS full_path
LIMIT 500
Use when the user focuses on specific attributes, statistics, or metrics.
Triggers: "what is the name", "list", "how many", "count", "average", "top
10", "aggregate". Return ONLY the required properties or aggregates; do NOT
use TO_JSON().
RETURN account.id, SUM(t.amount) AS total_transferApply these principles to every traversal (detailed rationale and the
bidirectional UNION ALL example are in the advanced-functions/performance
reference):
Account {id: 7}) as early as possible in MATCH to prune the
search space.(a)-[e]-(b)) — they carry a
severe performance penalty. Use explicit ->/<-; to match either
direction between two nodes, UNION ALL two directed queries.MATCH over chaining several MATCH
statements, giving the optimizer a wider global view of the pattern.GRAPH_EXPANDAlways query a semantic graph through the GRAPH_EXPAND table-valued function
(TVF); never as a table.
A graph exposes one or more flattened views, one per starting node. In
your context each view is a separate <semantic_graph start_node="X"> block
whose <ddl> describes the columns of that specific view. Pick the block
that fits the question (see Rule 2) and query it by passing the graph name
and the starting node as a named argument:
SELECT ...
FROM GRAPH_EXPAND("project_id.dataset_id.property_graph_id",
start_node => "X")
WHERE ...
The starting node MUST be passed by name (start_node => "X", matching a
start_node value from the context); a positional second argument is
invalid.
CRITICAL RULE: The semantic graph is NOT a regular table, even though
its schema is presented using CREATE TABLE. You MUST NEVER query it
directly as a table (e.g., FROM my_project.my_dataset.my_graph).
CRITICAL FALLBACK RULE: If a GRAPH_EXPAND query fails (e.g., syntax
errors or system limits), DO NOT fall back to querying the graph or its
source tables as standard tables. Doing so causes a critical NOT_FOUND
error.
Each starting-node view is produced by joining outward from that node, and it keeps exactly one row per entity reachable from the starting node. Entities that are not reachable from the starting node are dropped from the view — so the wrong starting node silently under-counts.
Rule: To aggregate a measure M that is defined on node N (its column
is named N_<measure>, e.g. Department_total_budget), use
start_node => "N". You may then GROUP BY or filter on N and on any
node reachable from N (e.g. a parent entity). Do not start from a
finer-grained node, which would drop rows of N that have no finer-grained
children.
Worked example. For "total budget per college", where the schema has
Department_total_budget INT64 OPTIONS(is_measure=TRUE, ...):
-- CORRECT: start from Department (the measure's node), then group by college.
SELECT College_college_name, AGG(Department_total_budget) AS budget
FROM GRAPH_EXPAND("proj.ds.school_graph", start_node => "Department")
GROUP BY College_college_name;
Starting from a finer node such as Course would omit any department that
has no courses, so its budget would vanish from the total — a silent
under-count. Always root at the node that owns the measure.
One fact per query. Prefer answering with a single starting node. If a
question needs measures that live on different nodes and no single view
can hold them all without dropping rows (e.g. a budget measure on
Department and a count measure on Course), compute each with its own
start_node in a separate query and combine the results (e.g. join on the
shared grouping key).
Some nodes are not GRAPH_EXPAND-queryable — for example a node on a cyclic
or convergent path (a node reachable by two or more paths). Such a node has no
<semantic_graph start_node="X"> block in your context; only the shared
<property_graph> describes it. When answering the question requires an entity
or measure that has no starting-node view:
DO NOT substitute a different starting node to force a GRAPH_EXPAND
query — a view rooted elsewhere drops that entity's rows and silently
mis-counts (see Rule 2).
DO NOT query the graph's source tables directly (see Rule 1).
Answer with GQL instead. Query the <property_graph> with Graph Query
Language, following the property-graph (GQL) guidelines. GQL pattern-matches
regardless of join cardinality, so it is not restricted to
GRAPH_EXPAND-queryable starting nodes.
Measures are NOT available in GQL. is_measure columns and the AGG()
function exist only in the flattened GRAPH_EXPAND views, never in GQL.
When you fall back to GQL you MUST write the aggregation yourself with
standard SQL aggregate functions (SUM, COUNT, AVG, …) over the
underlying node/edge properties, wrapping the pattern match in
GRAPH_TABLE(...) so it integrates with SQL grouping.
Worked example. In a graph where Office is not queryable (it converges
on Company via both Division and Region), "total headcount per
company" cannot use any GRAPH_EXPAND view. Match the path in GQL and
aggregate the raw headcount property yourself:
SELECT company_name, SUM(headcount) AS total_headcount
FROM GRAPH_TABLE(
`proj.ds.graph`
MATCH (o:Office)-[:OfficeToDivision]->(:Division)
-[:DivisionToCompany]->(c:Company)
COLUMNS (c.name AS company_name, o.headcount AS headcount)
)
GROUP BY company_name;
If the data needed for the aggregation is not exposed as a property in the
<property_graph> either, tell the user the metric cannot be computed for
that entity rather than guessing.
AGG()Columns marked with is_measure=TRUE (e.g.,
Customer_customer_count INT64 OPTIONS(is_measure=TRUE)) are measure columns.
You MUST aggregate them with the AGG() function.
Syntax: AGG(<measure_column_name>)
Do not apply SUM, AVG, COUNT, etc. directly to a measure column — use
AGG(), which applies the measure's own aggregation exactly once per key
even across fan-out joins.
sql_expression is informational only. A measure column may carry
OPTIONS(is_measure=TRUE, sql_expression='SUM(budget)'). The
sql_expression tells you what the measure computes so you can pick the
right one; it is not something to reproduce. You MUST always
reference the measure as AGG(column). NEVER copy the raw expression or
the base columns it names (e.g. SUM(budget) / budget) — those base
columns are not present in the flattened view.
Example:
-- Given Schema:
-- CREATE TABLE `my_project.my_dataset.my_graph` (
-- Customer_name STRING,
-- Customer_total_orders INT64
-- OPTIONS(is_measure=TRUE, sql_expression='COUNT(order_id)'),
-- Product_name STRING
-- );
SELECT
Customer_name,
AGG(Customer_total_orders) AS total_orders
FROM GRAPH_EXPAND("my_project.my_dataset.my_graph",
start_node => "Customer")
GROUP BY Customer_name;
You MUST prioritize using pre-defined measures (columns with
is_measure=TRUE) over writing standard SQL aggregations (like
COUNT(DISTINCT ...), SUM, etc.) whenever a relevant measure is available in
the schema.
Context: Semantic graphs define business logic within measures to ensure accuracy and prevent issues like overcounting. Generating aggregations via standard SQL bypasses this logic.
Example Scenario: If the user asks for the "total number of entities",
and the schema provides an Entity_id column as well as a measure column
Entity_count INT64 OPTIONS(is_measure=TRUE):
INCORRECT (Standard SQL):
SELECT COUNT(DISTINCT Entity_id) AS total_entities ...
CORRECT (Measure):
SELECT AGG(Entity_count) AS total_entities ...
What SKILL.md sets; muted values are Claude Code's defaults
41 skills in this plugin
/accidental-data-loss-prevention**STOP AND VERIFY**: Before running any command or tool that results in irreversible data loss, you MUST obtain explicit user consent.
When in doubt, ask. It is better to wait for confirmation than to accidentally delete production data or critical project assets.
Use this for:
- SQL: DROP TABLE/VIEW/SCHEMA/DATABASE, TRUNCATE, or broad DELETE (missing WHERE or using 1=1).
- Cloud Storage: gsutil rm or gcloud storage rm targeting production data or critical buckets.
- Infrastructure: gcloud projects delete, deleting Spanner/BigQuery/Dataproc resources, deleting secrets, or KMS key destruction.
/bigquery-ai-mlLeverages BigQuery's built-in machine learning and GenAI capabilities for advanced data analytics. Use when you need to write SQL queries that perform time-series forecasting, predict values, detect outliers or anomalies, find key drivers, perform semantic search or vector search, classify text, calculate similarity, summarize content, translate language, evaluate models, filter by semantic conditions, measure the causal effect of an intervention, compute correlations between columns, generate descriptive statistics and table distribution profiles, detect change points or structural breaks, extract trend or seasonality components, or leverage generative AI capabilities in BigQuery. Do not use for general BigQuery dataset, table, or job management requests./bigquery-bigframesGenerates Python code using BigQuery DataFrames (BigFrames). Use by default for any Python data task involving BigQuery, including data processing, analysis, and machine learning. Don't use for SQL-first workflows or the google-cloud-bigquery client library — use bigquery-basics./bigquery-data-transfer-serviceDiscovers and inspects BigQuery Data Transfer Service (DTS) configurations. Use this to identify existing ingestion pipelines and extract datasource or transfer config metadata for data pipelines. Use when a user asks for ingestion scenarios while building or managing data pipelines or when a user asks to "ingest" or "add" data that may already be managed by a DTS transfer./bigquery-graph-authorProvides an end-to-end journey for authoring a BigQuery property graph from your tables or from a model document/diagram (an ER diagram, an ontology, a semantic model): dataset discovery, candidate relationships verified against the data, a readable plan, and `CREATE PROPERTY GRAPH` DDL with schema best practices and semantic measures/dimensions, plus an opt-in verification suite for the landed graph. Use when creating or replacing a property graph, authoring a graph from a dataset or a document, or verifying relationships or suspicious edge counts. Don't use for querying an existing graph, for non-BigQuery graph databases, or for drawing/rendering diagrams./bigquery-observabilityProvides data-retrieval best practices, tool selection guidance, and performant SQL query syntax for BigQuery telemetry across INFORMATION_SCHEMA, Cloud Monitoring, and the REST API. Use when the telemetry to fetch is already known, selecting telemetry tools, writing performant INFORMATION_SCHEMA queries, retrieving telemetry for diagnosing single-job performance bottlenecks, investigating slot contention, job concurrency and queue latency, analyzing reservation capacity, utilization and autoscaling saturation, or auditing capacity-based and on-demand compute and storage resource billable usage. Don't use for root-cause diagnosis or symptom troubleshooting when the cause is unknown (use bigquery-troubleshooting first), or for writing or optimizing business logic SQL (use bigquery-optimization).npx claudepluginhub googlecloudplatform/data-agent-kit-plugin --plugin dakOther plugins' skills for the same job