Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ env_logger = "0.11"
fastlanes = { version = "0.8.1", features = ["runtime"] }
fearless_simd = "1.0.0"
fearless_simd_macros = "0.1.0"
flate2 = "1.1"
flatbuffers = "25.2.10"
fsst-rs = "0.7.0"
futures = { version = "0.3.31", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion bench-orchestrator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ vx-bench run <benchmark> [options]

**Arguments:**

- `benchmark`: Benchmark suite to run (`appian`, `tpch`, `tpcds`, `clickbench`, `fineweb`, `gh-archive`, `job`, `polarsignals`, `public-bi`, `statpopgen`, `tpch-nested`)
- `benchmark`: Benchmark suite to run (`appian`, `tpch`, `tpcds`, `clickbench`, `fineweb`, `gh-archive`, `job`, `jsonbench`, `polarsignals`, `public-bi`, `statpopgen`, `tpch-nested`)

**Options:**

Expand Down
28 changes: 28 additions & 0 deletions bench-orchestrator/bench_orchestrator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class Benchmark(Enum):
FINEWEB = "fineweb"
GHARCHIVE = "gh-archive"
JOB = "job"
JSONBENCH = "jsonbench"
POLARSIGNALS = "polarsignals"
PUBLIC_BI = "public-bi"
STATPOPGEN = "statpopgen"
Expand Down Expand Up @@ -126,6 +127,18 @@ class Benchmark(Enum):
}


# Engine/format targets a benchmark cannot run, beyond what `ENGINE_FORMATS` rules out. JSONBench
# stores a Variant column, which the Vortex DuckDB extension cannot export to DuckDB yet.
BENCHMARK_UNSUPPORTED_TARGETS: dict[Benchmark, frozenset[tuple[Engine, Format]]] = {
Benchmark.JSONBENCH: frozenset(
{
(Engine.DUCKDB, Format.VORTEX),
(Engine.DUCKDB, Format.VORTEX_COMPACT),
}
),
}


# Formats whose targets name an integration and a scan engine. Other formats (Parquet, DuckDB's own
# format, Lance) are controls and comparisons, with neither axis.
VORTEX_FORMATS: frozenset[Format] = frozenset({Format.VORTEX, Format.VORTEX_COMPACT, Format.VORTEX_SPATIAL_NATIVE})
Expand Down Expand Up @@ -195,6 +208,11 @@ def engines_for_benchmark(benchmark: Benchmark) -> frozenset[Engine]:
return BENCHMARK_ENGINES.get(benchmark, frozenset(Engine))


def benchmark_supports_target(benchmark: Benchmark, engine: Engine, fmt: Format) -> bool:
"""Return whether `benchmark` can run on `engine` over `fmt`, given the engine supports both."""
return (engine, fmt) not in BENCHMARK_UNSUPPORTED_TARGETS.get(benchmark, frozenset())


T = TypeVar("T")


Expand Down Expand Up @@ -400,6 +418,11 @@ def resolve_axis_targets(
if not target.is_supported():
warnings.append(f"Format {fmt.value} is not supported by engine {engine.value}")
continue
if benchmark is not None and not benchmark_supports_target(benchmark, target.engine, target.format):
warnings.append(
f"Benchmark {benchmark.value} does not support format {fmt.value} on engine {engine.value}"
)
continue
targets.append(target)

return _unique_preserve_order(targets), warnings
Expand All @@ -424,6 +447,11 @@ def validate_targets(
errors.extend(target.support_errors(benchmark))
if benchmark is not None and target.engine not in engines_for_benchmark(benchmark):
errors.append(f"Benchmark {benchmark.value} does not support engine {target.engine.value}")
elif benchmark is not None and not benchmark_supports_target(benchmark, target.engine, target.format):
errors.append(
f"Benchmark {benchmark.value} does not support format {target.format.value} "
f"on engine {target.engine.value}"
)

if options.get("remote-data-dir") and any(target.format == Format.LANCE for target in normalized_targets):
errors.append("Lance format is not supported for remote storage benchmarks.")
Expand Down
31 changes: 31 additions & 0 deletions bench-orchestrator/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,34 @@ def test_validate_targets_rejects_v2_on_list_layouts() -> None:
)

assert errors == ["Benchmark tpch-nested cannot run the v2 scan yet (list layout): duckdb:vortex [file, v2]"]


def test_resolve_axis_targets_skips_jsonbench_vortex_on_duckdb() -> None:
# The Vortex DuckDB extension cannot export JSONBench's Variant column yet.
targets, warnings = resolve_axis_targets(
[Engine.DATAFUSION, Engine.DUCKDB],
[Format.PARQUET, Format.VORTEX],
Benchmark.JSONBENCH,
)

assert targets == [
BenchmarkTarget(engine=Engine.DATAFUSION, format=Format.PARQUET),
BenchmarkTarget(Engine.DATAFUSION, Format.VORTEX, Integration.FILE, ScanEngine.V2),
BenchmarkTarget(engine=Engine.DUCKDB, format=Format.PARQUET),
]
assert warnings == ["Benchmark jsonbench does not support format vortex on engine duckdb"]


def test_validate_targets_rejects_jsonbench_vortex_on_duckdb() -> None:
errors = validate_targets(
[BenchmarkTarget(engine=Engine.DUCKDB, format=Format.VORTEX)],
{},
Benchmark.JSONBENCH,
)

assert errors == ["Benchmark jsonbench does not support format vortex on engine duckdb"]


def test_jsonbench_runs_on_the_v2_scan() -> None:
# The split-wide sharing of decoded Variant storage is part of the V2 scan.
assert default_scan_engine(Benchmark.JSONBENCH) is ScanEngine.V2
2 changes: 2 additions & 0 deletions benchmarks/datafusion-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ opentelemetry.workspace = true
opentelemetry-otlp.workspace = true
opentelemetry_sdk.workspace = true
parking_lot = { workspace = true }
parquet-variant = { workspace = true }
parquet-variant-compute = { workspace = true }
tokio = { workspace = true, features = ["full"] }
url = { workspace = true }
vortex = { workspace = true, features = ["object_store", "files", "tokio"] }
Expand Down
5 changes: 4 additions & 1 deletion benchmarks/datafusion-bench/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

pub mod metrics;
pub mod tracer;
pub mod variant;

use std::sync::Arc;

Expand Down Expand Up @@ -66,7 +67,9 @@ pub fn get_session_context() -> SessionContext {
file_formats.push(Arc::new(factory));
}

SessionContext::new_with_state(session_state_builder.build())
let session = SessionContext::new_with_state(session_state_builder.build());
variant::register_variant_functions(&session);
session
}

pub fn make_object_store(
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/datafusion-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async fn main() -> anyhow::Result<()> {
let benchmark = create_benchmark(args.benchmark, &opts)?;

let filtered_queries = filter_queries(
benchmark.queries()?,
benchmark.queries_for_engine(Engine::DataFusion)?,
args.queries.as_ref(),
args.exclude_queries.as_ref(),
);
Expand Down
134 changes: 134 additions & 0 deletions benchmarks/datafusion-bench/src/variant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors

//! A `try_variant_get(variant, path, type)` function for DataFusion.
//!
//! This is a stand-in for the function of the same name and signature in
//! [`datafusion-variant`](https://github.com/datafusion-contrib/datafusion-variant), which has no
//! release for the DataFusion and Arrow versions that Vortex builds against. Both evaluate with the
//! `variant_get` kernel of `parquet-variant-compute`. Replace this module with
//! `datafusion_variant::register_all` once the versions line up.

use std::sync::Arc;

use datafusion::arrow::array::ArrayRef;
use datafusion::arrow::datatypes::DataType;
use datafusion::arrow::datatypes::Field;
use datafusion::arrow::datatypes::FieldRef;
use datafusion::logical_expr::ColumnarValue;
use datafusion::logical_expr::ExpressionPlacement;
use datafusion::logical_expr::ReturnFieldArgs;
use datafusion::logical_expr::ScalarFunctionArgs;
use datafusion::logical_expr::ScalarUDF;
use datafusion::logical_expr::ScalarUDFImpl;
use datafusion::logical_expr::Signature;
use datafusion::logical_expr::Volatility;
use datafusion::prelude::SessionContext;
use datafusion_common::Result as DFResult;
use datafusion_common::ScalarValue;
use datafusion_common::exec_err;
use datafusion_common::plan_err;
use parquet_variant::VariantPath;
use parquet_variant_compute::GetOptions;
use parquet_variant_compute::variant_get;

/// Registers the Variant functions with `ctx`.
pub fn register_variant_functions(ctx: &SessionContext) {
ctx.register_udf(ScalarUDF::new_from_impl(VariantGetUdf::new()));
}

/// `try_variant_get(variant, path, type)`: the value at `path` of each Variant, cast to the SQL
/// type named `type`.
///
/// `path` is `$.` and a dot-separated list of object fields, such as `'$.commit.collection'`. A
/// missing path or a value that cannot be cast yields null. Both `path` and `type` must be string
/// literals.
#[derive(Debug, PartialEq, Eq, Hash)]
struct VariantGetUdf {
signature: Signature,
}

impl VariantGetUdf {
fn new() -> Self {
Self {
signature: Signature::any(3, Volatility::Immutable),
}
}
}

impl ScalarUDFImpl for VariantGetUdf {
fn name(&self) -> &str {
"try_variant_get"
}

fn signature(&self) -> &Signature {
&self.signature
}

fn return_type(&self, _arg_types: &[DataType]) -> DFResult<DataType> {
plan_err!("try_variant_get derives its return type from its type argument")
}

fn return_field_from_args(&self, args: ReturnFieldArgs) -> DFResult<FieldRef> {
let Some(Some(type_name)) = args.scalar_arguments.get(2) else {
return plan_err!("the type argument of try_variant_get must be a literal");
};
let data_type = sql_type(string_literal("type", type_name)?)?;
Ok(Arc::new(Field::new(self.name(), data_type, true)))
}

/// Extraction is cheap next to reading a whole Variant, so DataFusion moves it into a
/// projection above the scan, which a source that understands `try_variant_get` can absorb.
fn placement(&self, args: &[ExpressionPlacement]) -> ExpressionPlacement {
match args {
[
ExpressionPlacement::Column,
ExpressionPlacement::Literal,
ExpressionPlacement::Literal,
] => ExpressionPlacement::MoveTowardsLeafNodes,
_ => ExpressionPlacement::KeepInPlace,
}
}

fn invoke_with_args(&self, args: ScalarFunctionArgs) -> DFResult<ColumnarValue> {
let [variant, path, _type] = args.args.as_slice() else {
return exec_err!("try_variant_get expects 3 arguments, got {}", args.args.len());
};
let ColumnarValue::Scalar(path) = path else {
return exec_err!("the path argument of try_variant_get must be a literal");
};
let Some(path) = string_literal("path", path)?.strip_prefix("$.") else {
return exec_err!("the path argument of try_variant_get must start with `$.`");
};
let path = VariantPath::try_from(path)?;
let options = GetOptions::new_with_path(path).with_as_type(Some(args.return_field));

let input: ArrayRef = variant.to_array(args.number_rows)?;
Ok(ColumnarValue::Array(variant_get(&input, options)?))
}
}

/// The value of the string literal `scalar`, which is the `argument` of `try_variant_get`.
fn string_literal<'a>(argument: &str, scalar: &'a ScalarValue) -> DFResult<&'a str> {
match scalar {
ScalarValue::Utf8(Some(value))
| ScalarValue::Utf8View(Some(value))
| ScalarValue::LargeUtf8(Some(value)) => Ok(value),
other => exec_err!(
"the {argument} argument of try_variant_get must be a non-null string literal, got {}",
other.data_type()
),
}
}

/// The Arrow type that the SQL type `name` maps to.
fn sql_type(name: &str) -> DFResult<DataType> {
Ok(match name.to_ascii_uppercase().as_str() {
"VARCHAR" | "TEXT" | "STRING" => DataType::Utf8View,
"BIGINT" => DataType::Int64,
"INT" | "INTEGER" => DataType::Int32,
"DOUBLE" => DataType::Float64,
"BOOLEAN" => DataType::Boolean,
_ => return plan_err!("try_variant_get does not support the type {name}"),
})
}
2 changes: 1 addition & 1 deletion benchmarks/duckdb-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn main() -> anyhow::Result<()> {
let benchmark = create_benchmark(args.benchmark, &opts)?;

let filtered_queries = filter_queries(
benchmark.queries()?,
benchmark.queries_for_engine(Engine::DuckDB)?,
args.queries.as_ref(),
args.exclude_queries.as_ref(),
);
Expand Down
9 changes: 8 additions & 1 deletion vortex-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ async-trait = { workspace = true }
bytes = { workspace = true }
bzip2 = { workspace = true }
clap = { workspace = true, features = ["derive"] }
flate2 = { workspace = true }
futures = { workspace = true }
geo = { workspace = true }
geo-traits = { workspace = true }
Expand All @@ -57,7 +58,12 @@ noodles-bgzf = { workspace = true, features = ["async"] }
noodles-vcf = { workspace = true, features = ["async"] }
object_store = { workspace = true, features = ["aws"] }
parking_lot = { workspace = true }
parquet = { workspace = true, features = ["async", "object_store"] }
parquet = { workspace = true, features = [
"async",
"object_store",
"variant_experimental",
] }
parquet-variant-compute = { workspace = true }
rand = { workspace = true }
regex = { workspace = true }
reqwest = { workspace = true, features = ["stream"] }
Expand Down Expand Up @@ -88,5 +94,6 @@ wkb = { workspace = true }

[dev-dependencies]
insta = { workspace = true }
parquet-variant = { workspace = true }
rstest = { workspace = true }
vortex-array = { workspace = true, features = ["_test-harness"] }
Loading