ApacheCalciteClasses - eellpp/pubScratchpad GitHub Wiki

https://calcite.apache.org/javadocAggregate/index.html

https://calcite.apache.org/javadocAggregate/overview-tree.html

Some Important Classes

Frameworks Class

In Apache Calcite, the Frameworks class is a utility class that provides methods for creating query planning and execution environments. It is mainly used to configure and create instances of RelOptPlanner, RelOptCluster, and RelBuilder, which are essential components for optimizing and executing relational queries.

Key Features of the Frameworks Class:

  1. Provides a Builder Pattern for Query Planning:

    • The class contains methods that help configure a FrameworkConfig, which determines how query planning should be performed.
  2. Creates RelOptPlanner and RelOptCluster:

    • Frameworks.newConfigBuilder() allows you to set up a FrameworkConfig that controls how optimizations are applied.
    • This includes setting up rules, cost models, and metadata providers.
  3. Allows Custom Schema Registration:

    • Frameworks.createRootSchema(true) allows defining a custom schema for SQL parsing and validation.
  4. Supports Planner Instantiation:

    • The Frameworks.getPlanner() method helps obtain a Planner instance, which is used for parsing, validating, and converting SQL queries into relational expressions (RelNode).
  5. Simplifies the Use of RelBuilder:

    • Frameworks.withPlanner(...) provides a way to obtain a planner and use RelBuilder within a defined configuration.

Example Usage:

Here's how you can use Frameworks to create a planner and parse a SQL query:

FrameworkConfig config = Frameworks.newConfigBuilder()
        .defaultSchema(Frameworks.createRootSchema(true)) // Create a root schema
        .build();

Planner planner = Frameworks.getPlanner(config);

// Parse and validate SQL query
SqlNode sqlNode = planner.parse("SELECT * FROM my_table");
sqlNode = planner.validate(sqlNode);

// Convert SQL query to a relational expression (RelNode)
RelNode relNode = planner.rel(sqlNode).rel;
System.out.println(RelOptUtil.toString(relNode));

When to Use Frameworks?

  • When you need custom SQL query processing with a specific schema and planner configuration.
  • When you want to use Calcite’s optimizer to transform queries.
  • When you need a custom relational algebra transformation with RelBuilder.

ScannableTable Interface

All Known Implementing Classes: ...

This has method scan

Enumerable<@Nullable Object[]> scan(DataContext root) Returns an enumerator over the rows in this Table. Each row is represented as an array of its column values.

A custom table can be created using ScannableTable Interface .
This table simulates a data source by returning hard-coded rows. In practice, this could wrap an API call, a file reader, or any other non‑JDBC data source.