Calcite - Relational Operator (RelNode)

Card Puncher Data Processing

Calcite - Relational Operator (RelNode)

About

Relational Algebra - Expression and Operators in Calcite.

They are used to build a relational expression.

Because of the chaining nature of a relational expression, a relational operator is also a relational expression and share the same interface called RelNode.

Every relational operator (expression) must derive from AbstractRelNode.

List

Scan

final FrameworkConfig config;
final RelBuilder builder = RelBuilder.create(config);
final RelNode node = builder
  .scan("EMP")
  .build();
System.out.println(RelOptUtil.toString(node));
LogicalTableScan(table=[[scott, EMP]])

  • Equivalent to
SELECT *
FROM scott.EMP;

Projection

Calcite - Projection relational operator

Filter and aggregate

final RelNode node = builder
  .scan("EMP")
  .aggregate(builder.groupKey("DEPTNO"),
      builder.count(false, "C"),
      builder.sum(false, "S", builder.field("SAL")))
  .filter(
      builder.call(SqlStdOperatorTable.GREATER_THAN,
          builder.field("C"),
          builder.literal(10)))
  .build();
System.out.println(RelOptUtil.toString(node));
LogicalFilter(condition=[>($1, 10)])
  LogicalAggregate(group=[{7}], C=[COUNT()], S=[SUM($5)])
    LogicalTableScan(table=[[scott, EMP]])

equivalent to

SELECT deptno, count(*) AS c, sum(sal) AS s
FROM emp
GROUP BY deptno
HAVING count(*) > 10

Multi-join

  • The graphical expression tree
join
             /      \
        join          join
      /      \      /      \
CUSTOMERS ORDERS LINE_ITEMS PRODUCTS

  • The tree in calcite
final RelNode left = builder
  .scan("CUSTOMERS")
  .scan("ORDERS")
  .join(JoinRelType.INNER, "ORDER_ID")
  .build();

final RelNode right = builder
  .scan("LINE_ITEMS")
  .scan("PRODUCTS")
  .join(JoinRelType.INNER, "PRODUCT_ID")
  .build();

final RelNode result = builder
  .push(left)
  .push(right)
  .join(JoinRelType.INNER, "ORDER_ID")
  .build();

Values

values(String[] fieldNames, Object... values) 

where: fieldName is the name of the columns

Documentation / Reference





Discover More
Card Puncher Data Processing
Calcite - Field

in calcite. You can reference a field (cell) by name or ordinal. Ordinals are zero-based. Each operator guarantees the order in which its output fields occur. For example, Project returns the fields...
Card Puncher Data Processing
Calcite - Join

in Calcite. Join is a calcite relational operator (RelNode) Example field addressing in a join between the input EMP and DEPT The ordinal referencing is: 0=EMP 0=EMPNO, 1=ENAME, 2=JOB,...
Card Puncher Data Processing
Calcite - Projection relational operator

Projection relational operator in Calcite is a relational operator. name expressions using alias(expr, fieldName) equivalent to: builder.field create simple expressions that return the fields...



Share this page:
Follow us:
Task Runner