calcite-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Julian Hyde <jul...@hydromatic.net>
Subject Re: RexNode corresponding to complex types
Date Fri, 05 Sep 2014 20:04:33 GMT
A RexNode represents an expression. The expression can have complex
values - scalars (e.g. BOOLEAN, DECIMAL, NULL), multisets, arrays,
maps, structs, records, and combinations of these.

(Relational expressions, which are streams of records and are
represented as RelNodes, are not expressions in this scheme --
although there are ways to convert a relation to a multiset or an
array, and vice versa. Relational expression values are just too "big"
to be treated in this way, and besides, they need to be subjected to a
different kind of optimization.)

The sub-types of RexNode represent the kinds of operations on
expressions - a literal, a field access, a call to a function or
prefix or infix operator with arguments. So, you would need to create
a new sub-type of RexNode only if you have a new kind of operation.
You probably don't.

The common types are RexLiteral, RexInputRef, RexCall.

RexFieldAccess is relatively rarely used. You'd only use it if your
input value is a record (e.g. your input row type has a field whose
value is a record type). To just access the output fields of the
incoming record, use RexInputRef.

RexLocalRef is similar to RexInputRef but is only used within a RexProgram.

RexRangeRef is a "clever" way of referring to the columns coming from
one side of a join as a virtual record; it simplifies the sql-to-rel
process. When you apply a RexFieldAccess to a RexRangeRef you get back
a RexInputRef. The record never existed.

The complex types introduce a new set of operations. For example,
array has a constructor, to convert N values into an array, and an
accessor, to get the Nth element of an array, and a function to get
the count. Each of these operations is represented by an operator: in
SqlStdOperatorTable, see ARRAY_VALUE_CONSTRUCTOR, ITEM and
CARDINALITY. You would construct a RexCall to these operators.

There are similar sets of operators for multiset, record, map, array.

Does that help?

Julian


On Fri, Sep 5, 2014 at 12:08 PM, Ashutosh Chauhan <hashutosh@apache.org> wrote:
> Which RexNode implementation shall I use if my RelDataType corresponds to
> one of complex types like  ArraySqlType, MapSqlType etc.
>
> I looked at inbuilt one like RexFieldAccess, RexInputRef etc., none of them
> seem to fit. But may be I am missing some thing. Which one is recommended?
> Or do I need to implement one myself?
>
> Thanks,
> Ashutosh

Mime
View raw message