ApacheCalciteClasses - eellpp/pubScratchpad GitHub Wiki
https://calcite.apache.org/javadocAggregate/index.html
https://calcite.apache.org/javadocAggregate/overview-tree.html
Some Important Classes
- org.apache.calcite
- org.apache.calcite.adapter.java
- org.apache.calcite.schema
- org.apache.calcite.linq4j
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.
Frameworks
Class:
Key Features of the -
Provides a Builder Pattern for Query Planning:
- The class contains methods that help configure a
FrameworkConfig
, which determines how query planning should be performed.
- The class contains methods that help configure a
-
Creates
RelOptPlanner
andRelOptCluster
:Frameworks.newConfigBuilder()
allows you to set up aFrameworkConfig
that controls how optimizations are applied.- This includes setting up rules, cost models, and metadata providers.
-
Allows Custom Schema Registration:
Frameworks.createRootSchema(true)
allows defining a custom schema for SQL parsing and validation.
-
Supports
Planner
Instantiation:- The
Frameworks.getPlanner()
method helps obtain aPlanner
instance, which is used for parsing, validating, and converting SQL queries into relational expressions (RelNode
).
- The
-
Simplifies the Use of
RelBuilder
:Frameworks.withPlanner(...)
provides a way to obtain a planner and useRelBuilder
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));
Frameworks
?
When to Use - 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: ...
- CsvStreamScannableTable : Table based on a CSV file,
- [GeodeSimpleScannableTable]JdbcTable,
- JsonScannableTable : Table based on a JSON file,
- KafkaStreamTable,
- ListTransientTable, [MazeTable] ...
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.