Revolutionizing Presto C++: Unleashing Native Power with the Sidecar 

    At PrestoCon Day 2025, we unveiled the Presto Sidecar, a powerful enhancement for Presto C++ (Velox) clusters that transforms how coordinators interact with native workers. This innovation removes long-standing blind spots in query planning by giving the coordinator real-time visibility into native worker capabilities – such as supported functions, data types, session properties, and plan compatibility. By aligning the planner with the Velox execution engine from the start, the Presto Sidecar enables faster query optimization, reduces runtime failures, and streamlines the migration from Java to C++ clusters.

    The Problem: A Disconnect Between Coordinator and C++ Worker 

    In a standard Presto setup, Presto C++ workers use the same REST API communication layer as Java workers. While this ensures compatibility at a basic level, it hides critical information from the coordinator: 

    • Unknown Capabilities: The coordinator doesn’t know which functions, types, or connectors are supported by the underlying C++ worker, as they are hardcoded. 
    • No “Fail Fast”: Queries incompatible with the native execution engine (Velox) aren’t flagged early, leading to runtime failures after resources have already been allocated
    • Irrelevant Information: SHOW FUNCTIONS or SHOW SESSION commands return Java-specific information that may not apply to the C++ worker, confusing users. 

    To overcome these issues, a new coordinator plugin interface was introduced in Presto SPI, leading to the development of the Native Sidecar Plugin specifically for Presto C++ clusters. 

    The Sidecar Solution: Bridging the Native Gap

    At its heart, the sidecar is essentially a Presto C++ worker configured with additional REST endpoints. The Native Sidecar Plugin on the coordinator makes REST calls to these endpoints to infer the capabilities of the C++ worker (e.g., supported functions, session properties) and perform other tasks like validating plans and optimizing expressions.

    Deployment is flexible: you can either set up a dedicated sidecar process or configure one of your existing C++ workers to act as a sidecar by simply adding native.sidecar=true to its config.properties file. You can even enable all workers in a cluster as sidecars.

    Key Enhancements Powered by the Sidecar

    The sidecar unlocks a suite of powerful enhancements for Presto C++ clusters:

    1. Function Validation: Failing Fast, Not Failing Late

    Previously, queries with unsupported functions would fail only during execution on the workers. With the sidecar, function validation happens on the coordinator, allowing for “fail fast” behavior.

    • How it Works: The sidecar exposes metadata for all Presto C++ functions registered in Velox via the v1/functions endpoint. The Native Sidecar Plugin retrieves this metadata and integrates it into the coordinator using the Native Function Namespace Manager.
    • Namespaces: To differentiate Java and C++ built-in functions, Presto Java uses presto.default namespace whereas Presto C++ uses native.default namespace by default. The function namespace used by Presto is configurable.
    • Benefits:
      • Accurate SHOW FUNCTIONS: Users now only see functions relevant to the C++ worker, excluding those not supported in Velox (e.g., tdigest_agg, apply).
      • Correct Function Signatures: The sidecar ensures the correct function signature is chosen based on the cluster type. For instance, the function array_sort in Presto can sort an array using a custom function for comparison, and the semantics of this custom function vary in Presto Java and Velox. 

    2. User-Defined Functions (UDFs): Extending Functionality Dynamically

    The sidecar paves the way for robust UDF support in Presto C++:

    • In-Process UDFs: Support for dynamic function loading in Velox is being built using the dlopen function, allowing C++ UDFs to be used for function analysis just like built-in functions.
    • Out-of-Process UDFs: A new standard REST API for remote functions is being defined. This API will support dynamic function definition, metadata retrieval, and function execution.
      • These UDFs will be integrated into the coordinator via a new rest-based function namespace manager.
      • Currently, Presto Page format is supported for data serialization, with Arrow format planned for the future.

    3. Constant Folding and Expression Optimization: Smarter Query Planning

    Constant folding evaluates constant expressions at compile time to reduce runtime work.

    • Problem Addressed: Previously, constant folding on the coordinator used Presto Java function implementations, resulting in limitations such as not being able to constant fold expressions containing C++ UDFs.
    • Solution: The Native Expression Optimizer (an implementation of Presto SPI’s ExpressionOptimizer interface) delegates expression optimization, including constant folding, to the sidecar via the v1/expressions HTTP endpoint.
    • Goal: Constant fold expressions in Presto C++ with Velox’s expression evaluation framework and implement Presto’s special form expression optimizations in Velox.

    4. Session Property Validation: Relevant Configuration Control

    • Problem Addressed: Setting Java-specific session properties on a Presto C++ cluster would have no effect, as they wouldn’t propagate to the worker.
    • Solution: The sidecar exposes Presto C++ worker session properties via the v1/properties/session endpoint. The Native Worker Session Property Provider integrates these into the coordinator.
    • Benefits: Users can now only set session properties relevant to the C++ cluster type. The config exclude-invalid-worker-session-properties config allows explicit control over this behavior in order to support heterogeneous environments.

    5. Type Validation: Ensuring Data Compatibility

    • Problem Addressed: Presto and Velox have different supported type lists (e.g., Presto supports parameterized varchar, Velox does not by default).
    • Solution: A new Native Type Manager provides the coordinator with a list of types supported in Velox. The goal is to move from a static list to a more dynamic one, pulling custom types registered in Velox at startup time.

    6. Plan Checker Functionality: Seamless C++ Migration

    One of the most impactful features, the sidecar’s plan checker functionality, validates if a Presto plan can be successfully converted to a Velox plan.

    • Problem Addressed: Incompatible plans failing during runtime, after resources have been allocated, is costly. The plan checker enables early detection of incompatibilities.
    • How it Works: A serialized plan fragment is sent to the sidecar’s v1/lock/plan endpoint. A 200 HTTP response indicates successful conversion to a Velox plan fragment, while a 400 HTTP response indicates a failure with details.
    • Major Use Case: Gradual Migration from Java to C++ Clusters:
      • A new Presto Plan Checker Router Plugin acts as an intermediary layer between two routers: one pointing to native C++ clusters and the other to Java clusters.
      • Incoming queries are sent to a sidecar-enabled plan checker cluster. Based on the sidecar’s response (native compatible or incompatible), the query is routed to the appropriate Java or native cluster.
      • This enables low-risk, gradual migration without the user needing to know the underlying cluster type.
      • It also provides full control over scheduling logic in both Java and C++ router groups. 

    Deployment and Future Work

    To enable the Native Sidecar Plugin, ensure coordinator.sidecar.enabled=true is configured. Each sidecar functionality (e.g., function namespace, session properties, plan checker) is controlled via individual configuration files (e.g., etc/function-namespace/native.properties). Detailed setup instructions are forthcoming.

    Future plans include:

    • Connector Support: Making the connectors supported by the native execution engine (Velox) the source of truth for the coordinator.
    • Helm Chart Deployment: Streamlining sidecar deployment in Kubernetes environments.

    The Presto Sidecar is a powerful addition that significantly enhances the functionality and performance of Presto C++ clusters. By providing the coordinator with deep insights into native worker capabilities, it enables smarter query planning, “fail fast” error detection, and facilitates a smooth, low-risk transition to a fully native Presto experience.

    Follow Presto at LinkedinYoutube, and Join Slack channel to interact with the community.