Skip to content

Commit f199b00

Browse files
authored
refactor: remove core crate from datafusion-proto (#18123)
## Which issue does this PR close? - Closes #17713. ## Rationale for this change Now that we have all the required supporting code moved out of the `core` crate, we can remove this as a dependency to reduce build times for downstream projects. ## What changes are included in this PR? Remove dependency. Update paths. ## Are these changes tested? Existing unit tests since this is just a code shuffle. ## Are there any user-facing changes? - Methods within the proto crate now take `TaskContext` instead of `SessionContext`
1 parent b98cad6 commit f199b00

File tree

16 files changed

+274
-239
lines changed

16 files changed

+274
-239
lines changed

Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benchmarks/src/imdb/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ mod tests {
534534
let plan = ctx.sql(&query).await?;
535535
let plan = plan.into_optimized_plan()?;
536536
let bytes = logical_plan_to_bytes(&plan)?;
537-
let plan2 = logical_plan_from_bytes(&bytes, &ctx)?;
537+
let plan2 = logical_plan_from_bytes(&bytes, &ctx.task_ctx())?;
538538
let plan_formatted = format!("{}", plan.display_indent());
539539
let plan2_formatted = format!("{}", plan2.display_indent());
540540
assert_eq!(plan_formatted, plan2_formatted);

benchmarks/src/tpch/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ mod tests {
387387
let plan = ctx.sql(&query).await?;
388388
let plan = plan.into_optimized_plan()?;
389389
let bytes = logical_plan_to_bytes(&plan)?;
390-
let plan2 = logical_plan_from_bytes(&bytes, &ctx)?;
390+
let plan2 = logical_plan_from_bytes(&bytes, &ctx.task_ctx())?;
391391
let plan_formatted = format!("{}", plan.display_indent());
392392
let plan2_formatted = format!("{}", plan2.display_indent());
393393
assert_eq!(plan_formatted, plan2_formatted);

datafusion/proto/Cargo.toml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,31 @@ name = "datafusion_proto"
4040
[features]
4141
default = ["parquet"]
4242
json = ["pbjson", "serde", "serde_json", "datafusion-proto-common/json"]
43-
parquet = ["datafusion/parquet", "datafusion-common/parquet"]
44-
avro = ["datafusion/avro", "datafusion-common/avro"]
43+
parquet = ["datafusion-datasource-parquet", "datafusion-common/parquet", "datafusion/parquet"]
44+
avro = ["datafusion-datasource-avro", "datafusion-common/avro"]
45+
46+
# Note to developers: do *not* add `datafusion` as a dependency in
47+
# this crate. See https://github.com/apache/datafusion/issues/17713
48+
# for additional information.
4549

4650
[dependencies]
4751
arrow = { workspace = true }
4852
chrono = { workspace = true }
49-
datafusion = { workspace = true, default-features = false }
53+
datafusion-catalog = { workspace = true }
54+
datafusion-catalog-listing = { workspace = true }
5055
datafusion-common = { workspace = true }
56+
datafusion-datasource = { workspace = true }
57+
datafusion-datasource-arrow = { workspace = true }
58+
datafusion-datasource-avro = { workspace = true, optional = true }
59+
datafusion-datasource-csv = { workspace = true }
60+
datafusion-datasource-json = { workspace = true }
61+
datafusion-datasource-parquet = { workspace = true, optional = true }
62+
datafusion-execution = { workspace = true }
5163
datafusion-expr = { workspace = true }
64+
datafusion-functions-table = { workspace = true }
65+
datafusion-physical-expr = { workspace = true }
66+
datafusion-physical-expr-common = { workspace = true }
67+
datafusion-physical-plan = { workspace = true }
5268
datafusion-proto-common = { workspace = true }
5369
object_store = { workspace = true }
5470
pbjson = { workspace = true, optional = true }

datafusion/proto/src/bytes/mod.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use crate::physical_plan::{
2424
AsExecutionPlan, DefaultPhysicalExtensionCodec, PhysicalExtensionCodec,
2525
};
2626
use crate::protobuf;
27-
use datafusion::execution::TaskContext;
2827
use datafusion_common::{plan_datafusion_err, Result};
28+
use datafusion_execution::TaskContext;
2929
use datafusion_expr::{
3030
create_udaf, create_udf, create_udwf, AggregateUDF, Expr, LogicalPlan, Volatility,
3131
WindowUDF,
@@ -37,10 +37,9 @@ use prost::{
3737
use std::sync::Arc;
3838

3939
// Reexport Bytes which appears in the API
40-
use datafusion::execution::registry::FunctionRegistry;
41-
use datafusion::physical_plan::ExecutionPlan;
42-
use datafusion::prelude::SessionContext;
40+
use datafusion_execution::registry::FunctionRegistry;
4341
use datafusion_expr::planner::ExprPlanner;
42+
use datafusion_physical_plan::ExecutionPlan;
4443

4544
mod registry;
4645

@@ -240,24 +239,21 @@ pub fn logical_plan_to_json_with_extension_codec(
240239

241240
/// Deserialize a LogicalPlan from JSON
242241
#[cfg(feature = "json")]
243-
pub fn logical_plan_from_json(json: &str, ctx: &SessionContext) -> Result<LogicalPlan> {
242+
pub fn logical_plan_from_json(json: &str, ctx: &TaskContext) -> Result<LogicalPlan> {
244243
let extension_codec = DefaultLogicalExtensionCodec {};
245244
logical_plan_from_json_with_extension_codec(json, ctx, &extension_codec)
246245
}
247246

248247
/// Deserialize a LogicalPlan from bytes
249-
pub fn logical_plan_from_bytes(
250-
bytes: &[u8],
251-
ctx: &SessionContext,
252-
) -> Result<LogicalPlan> {
248+
pub fn logical_plan_from_bytes(bytes: &[u8], ctx: &TaskContext) -> Result<LogicalPlan> {
253249
let extension_codec = DefaultLogicalExtensionCodec {};
254250
logical_plan_from_bytes_with_extension_codec(bytes, ctx, &extension_codec)
255251
}
256252

257253
/// Deserialize a LogicalPlan from bytes
258254
pub fn logical_plan_from_bytes_with_extension_codec(
259255
bytes: &[u8],
260-
ctx: &SessionContext,
256+
ctx: &TaskContext,
261257
extension_codec: &dyn LogicalExtensionCodec,
262258
) -> Result<LogicalPlan> {
263259
let protobuf = protobuf::LogicalPlanNode::decode(bytes)
@@ -269,7 +265,7 @@ pub fn logical_plan_from_bytes_with_extension_codec(
269265
#[cfg(feature = "json")]
270266
pub fn logical_plan_from_json_with_extension_codec(
271267
json: &str,
272-
ctx: &SessionContext,
268+
ctx: &TaskContext,
273269
extension_codec: &dyn LogicalExtensionCodec,
274270
) -> Result<LogicalPlan> {
275271
let back: protobuf::LogicalPlanNode = serde_json::from_str(json)
@@ -312,12 +308,12 @@ pub fn physical_plan_to_bytes_with_extension_codec(
312308
#[cfg(feature = "json")]
313309
pub fn physical_plan_from_json(
314310
json: &str,
315-
ctx: &SessionContext,
311+
ctx: &TaskContext,
316312
) -> Result<Arc<dyn ExecutionPlan>> {
317313
let back: protobuf::PhysicalPlanNode = serde_json::from_str(json)
318314
.map_err(|e| plan_datafusion_err!("Error serializing plan: {e}"))?;
319315
let extension_codec = DefaultPhysicalExtensionCodec {};
320-
back.try_into_physical_plan(&ctx.task_ctx(), &extension_codec)
316+
back.try_into_physical_plan(&ctx, &extension_codec)
321317
}
322318

323319
/// Deserialize a PhysicalPlan from bytes

datafusion/proto/src/bytes/registry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
use std::{collections::HashSet, sync::Arc};
1919

20-
use datafusion::execution::registry::FunctionRegistry;
2120
use datafusion_common::plan_err;
2221
use datafusion_common::Result;
22+
use datafusion_execution::registry::FunctionRegistry;
2323
use datafusion_expr::planner::ExprPlanner;
2424
use datafusion_expr::{AggregateUDF, ScalarUDF, WindowUDF};
2525

datafusion/proto/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
//!
3535
//! [`LogicalPlan`]: datafusion_expr::LogicalPlan
3636
//! [`Expr`]: datafusion_expr::Expr
37-
//! [`ExecutionPlan`]: datafusion::physical_plan::ExecutionPlan
38-
//! [`PhysicalExpr`]: datafusion::physical_expr::PhysicalExpr
37+
//! [`ExecutionPlan`]: datafusion_physical_plan::ExecutionPlan
38+
//! [`PhysicalExpr`]: datafusion_physical_expr::PhysicalExpr
3939
//!
4040
//! Internally, this crate is implemented by converting the plans to [protocol
4141
//! buffers] using [prost].
@@ -93,7 +93,7 @@
9393
//! let bytes = logical_plan_to_bytes(&plan)?;
9494
//!
9595
//! // Decode bytes from somewhere (over network, etc.) back to LogicalPlan
96-
//! let logical_round_trip = logical_plan_from_bytes(&bytes, &ctx)?;
96+
//! let logical_round_trip = logical_plan_from_bytes(&bytes, &ctx.task_ctx())?;
9797
//! assert_eq!(format!("{:?}", plan), format!("{:?}", logical_round_trip));
9898
//! # Ok(())
9999
//! # }

0 commit comments

Comments
 (0)