Repository navigation
Prevent Arrow offset overflow in DiskGraph temporal output #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nittin-murthi
wants to merge
3
commits into
main
Choose a base branch
from
codex/diskgraph-arrow-offset-overflow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
170 changes: 170 additions & 0 deletions
170
packages/diskgraph/diskgraph-pybind/python/examples/arrow_offset_query_bench.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. | ||
| # All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # Usage: python arrow_offset_query_bench.py FRESH_INDEX_ROOT LABEL [model|inspectable] | ||
| # Reuse the generated index across baseline/candidate runs. Use a separate | ||
| # installed wheel for each label; the label only identifies the JSON result. | ||
|
|
||
| from pathlib import Path | ||
| import json, time, sys, hashlib, statistics | ||
| import diskgraph, pyarrow as pa, pyarrow.parquet as pq | ||
|
|
||
| root = Path(sys.argv[1]) | ||
| variant = sys.argv[2] | ||
| output_format = sys.argv[3] if len(sys.argv) > 3 else "model" | ||
| root.mkdir(exist_ok=True) | ||
| if not (root / "index").exists(): | ||
| pq.write_table(pa.table({"id": list(range(100))}), root / "users.parquet") | ||
| n = 10000 | ||
| pq.write_table( | ||
| pa.table( | ||
| { | ||
| "id": list(range(n)), | ||
| "owner": [i % 100 for i in range(n)], | ||
| "time": pa.array( | ||
| [1700000000 + i // 100 for i in range(n)], type=pa.timestamp("s") | ||
| ), | ||
| "text": ["x" * 64 if i % 17 else None for i in range(n)], | ||
| "value": [float(i) for i in range(n)], | ||
| "blob": [b"abcdefgh" if i % 17 else None for i in range(n)], | ||
| "tags": [ | ||
| ["a", "bb", "ccc", "dddd"] if i % 17 else None for i in range(n) | ||
| ], | ||
| } | ||
| ), | ||
| root / "orders.parquet", | ||
| ) | ||
| cfg = { | ||
| "dataset_name": "offset_perf", | ||
| "num_shards": 1, | ||
| "tables": [ | ||
| { | ||
| "name": "users", | ||
| "primary_key": "id", | ||
| "columns": [{"name": "id", "ingested_dtype": "int64"}], | ||
| "source": {"type": "parquet", "paths": [str(root / "users.parquet")]}, | ||
| }, | ||
| { | ||
| "name": "orders", | ||
| "primary_key": "id", | ||
| "create_time": "time", | ||
| "columns": [ | ||
| {"name": k, "ingested_dtype": v} | ||
| for k, v in [ | ||
| ("id", "int64"), | ||
| ("owner", "int64"), | ||
| ("time", "timestamp"), | ||
| ("text", "string"), | ||
| ("value", "float64"), | ||
| ("blob", "bytes"), | ||
| ("tags", "string_array"), | ||
| ] | ||
| ], | ||
| "fkeys": [ | ||
| { | ||
| "src_column": "owner", | ||
| "dst_table": "users", | ||
| "reverse": { | ||
| "time": {"table": "orders", "column": "time", "unit": "s"} | ||
| }, | ||
| } | ||
| ], | ||
| "source": {"type": "parquet", "paths": [str(root / "orders.parquet")]}, | ||
| }, | ||
| ], | ||
| } | ||
| diskgraph.ingest( | ||
| json.dumps(cfg), | ||
| str(root / "index"), | ||
| col_stats=False, | ||
| context_threads=1, | ||
| encode_threads=1, | ||
| pk_map_threads=1, | ||
| edges_map_threads=1, | ||
| index_threads=1, | ||
| ) | ||
| e = diskgraph.SamplerEngine(str(root / "index")) | ||
| relation = next( | ||
| x["name"] | ||
| for x in json.loads(e.get_type_mapping())["edge_relations"] | ||
| if x["src_type"] == "users" | ||
| ) | ||
| plan = { | ||
| "frames": [ | ||
| { | ||
| "name": "f", | ||
| "root_type": "users", | ||
| "path": [{"relation": relation, "destination_type": "orders"}], | ||
| "time_column": "time", | ||
| "start_seconds": -102, | ||
| "stop_seconds": 0, | ||
| "distinct": True, | ||
| "columns": ["id", "text", "value", "blob", "tags"], | ||
| } | ||
| ], | ||
| "sequences": [ | ||
| { | ||
| "name": "s", | ||
| "frame": "f", | ||
| "columns": ["id", "text", "value", "blob", "tags"], | ||
| "order": "descending", | ||
| "limit": 32, | ||
| } | ||
| ], | ||
| "aggregates": [], | ||
| } | ||
| ids = e.lookup_node_ids("users", pa.array([i % 100 for i in range(256)])) | ||
| times = [1700000101] * 256 | ||
| p = json.dumps(plan) | ||
|
|
||
|
|
||
| def run(): | ||
| return e.query_temporal( | ||
| {"users": ids}, {"users": times}, p, output_format=output_format | ||
| ) | ||
|
|
||
|
|
||
| first = run() | ||
|
|
||
|
|
||
| # Preserve a value-based output digest separately from timing. | ||
| def normalize(x): | ||
| if isinstance(x, (pa.RecordBatch, pa.Table, pa.Array, pa.ChunkedArray)): | ||
| return x.to_pylist() | ||
| if isinstance(x, dict): | ||
| return { | ||
| k: normalize(v) for k, v in x.items() if k not in ("timings", "timings_ns") | ||
| } | ||
| if isinstance(x, (tuple, list)): | ||
| return [normalize(v) for v in x] | ||
| if hasattr(x, "tolist"): | ||
| return x.tolist() | ||
| return x | ||
|
|
||
|
|
||
| digest = hashlib.sha256( | ||
| json.dumps(normalize(first), sort_keys=True, default=str).encode() | ||
| ).hexdigest() | ||
| del first | ||
| for _ in range(5): | ||
| run() | ||
| start = time.perf_counter() | ||
| latencies = [] | ||
| for _ in range(100): | ||
| t0 = time.perf_counter() | ||
| run() | ||
| latencies.append(time.perf_counter() - t0) | ||
| print( | ||
| json.dumps( | ||
| { | ||
| "variant": variant, | ||
| "format": output_format, | ||
| "seconds": time.perf_counter() - start, | ||
| "queries": 100, | ||
| "median_query_seconds": statistics.median(latencies), | ||
| "p95_query_seconds": sorted(latencies)[94], | ||
| "digest": digest, | ||
| } | ||
| ) | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
packages/diskgraph/diskgraph-rowpack/examples/arrow_offset_bench.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. | ||
| // All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| use anyhow::Result; | ||
| use diskgraph_rowpack::*; | ||
| use std::{hint::black_box, time::Instant}; | ||
| fn main() -> Result<()> { | ||
| let args: Vec<_> = std::env::args().collect(); | ||
| let kind = &args[1]; | ||
| let n: usize = args[2].parse()?; | ||
| let repeats: usize = args[3].parse()?; | ||
| let text = "abcdefgh".repeat(if kind == "long" { 128 } else { 1 }); | ||
| let tokens = vec!["a", "bb", "ccc", "dddd"]; | ||
| let (dtype, value) = match kind.as_str() { | ||
| "numeric" => (IngestedType::Int64, ValueRef::Int64(42)), | ||
| "list" => (IngestedType::StringArray, ValueRef::StringArray(&tokens)), | ||
| "binary" => (IngestedType::Bytes, ValueRef::Bytes(text.as_bytes())), | ||
| _ => (IngestedType::String, ValueRef::String(&text)), | ||
| }; | ||
| let columns = vec![RowPackColumn { | ||
| name: "value".into(), | ||
| logical_type: dtype, | ||
| fixed_len: None, | ||
| precision: None, | ||
| scale: None, | ||
| }]; | ||
| let mut cb = RowPackContextBuilder::new(columns, RowPackConfig::default()); | ||
| cb.observe_row(&[value.clone()])?; | ||
| cb.observe_row(&[ValueRef::Null])?; | ||
| let ctx = cb.finish()?; | ||
| let encoder = RowPackEncoder::new(ctx.clone())?; | ||
| let mut scratch = RowPackScratch::new(&ctx); | ||
| let mut encoded = Vec::new(); | ||
| encoder.encode_row_into(&[value], &mut encoded, &mut scratch)?; | ||
| let mut null = Vec::new(); | ||
| encoder.encode_row_into(&[ValueRef::Null], &mut null, &mut scratch)?; | ||
| let rows: Vec<&[u8]> = (0..n) | ||
| .map(|i| { | ||
| if i % 17 == 0 { | ||
| null.as_slice() | ||
| } else { | ||
| encoded.as_slice() | ||
| } | ||
| }) | ||
| .collect(); | ||
| let decoder = RowPackDecoder::new(ctx)?; | ||
| for _ in 0..3 { | ||
| black_box(decoder.decode_batch_to_arrow_large(&rows, &[0])?); | ||
| } | ||
| let start = Instant::now(); | ||
| let mut bytes = 0; | ||
| for _ in 0..repeats { | ||
| let batch = decoder.decode_batch_to_arrow_large(black_box(&rows), &[0])?; | ||
| assert_eq!(batch.num_rows(), n); | ||
| bytes = batch.column(0).get_buffer_memory_size(); | ||
| black_box(batch); | ||
| } | ||
| println!( | ||
| "{{\"case\":\"{}\",\"rows\":{},\"repeats\":{},\"seconds\":{},\"output_buffer_bytes\":{}}}", | ||
| kind, | ||
| n, | ||
| repeats, | ||
| start.elapsed().as_secs_f64(), | ||
| bytes | ||
| ); | ||
| Ok(()) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the Clippy failure in the benchmark.
The supplied pipeline log shows that
cargo clippy --locked --workspace --all-targets -- -D warningsfails on&[value.clone()]. Passstd::slice::from_ref(&value)instead. This keepsvalueavailable for the later encode call. (raw.githubusercontent.com)Proposed fix
Committable suggestion
GitHub Actions: Testing and Coverage / 49_diskgraph-clippy.txt
[error] 29-29: cargo clippy --locked --workspace --all-targets -- -D warnings failed: Clippy's
cloned_ref_to_slice_refslint flags&[value.clone()]as an unnecessary clone. Usestd::slice::from_ref(&value).Source: Pipeline failures