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

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


Powered by ComboStrap