[SQL] Purpose of RuntimeReplaceable unevaluable unary expressions?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[SQL] Purpose of RuntimeReplaceable unevaluable unary expressions?

Jacek Laskowski
Hi,

I've been exploring RuntimeReplaceable expressions [1] and have been wondering what their purpose is.

Quoting the scaladoc [2]:

> An expression that gets replaced at runtime (currently by the optimizer) into a different expression for evaluation. This is mainly used to provide compatibility with other databases.

For example, ParseToTimestamp expression is a RuntimeReplaceable expression and it is replaced by Cast(left, TimestampType) or Cast(UnixTimestamp(left, format), TimestampType) per to_timestamp function (there are two variants).

My question is why is this RuntimeReplaceable better than simply using the Casts as the implementation of to_timestamp functions?

def to_timestamp(s: Column, fmt: String): Column = withExpr {
  // pseudocode
  Cast(UnixTimestamp(left, format), TimestampType)
}

What's wrong with the above implementation compared to the current one?


Reply | Threaded
Open this post in threaded view
|

Re: [SQL] Purpose of RuntimeReplaceable unevaluable unary expressions?

rxin
SQL expressions?

On Wed, May 30, 2018 at 11:09 AM Jacek Laskowski <[hidden email]> wrote:
Hi,

I've been exploring RuntimeReplaceable expressions [1] and have been wondering what their purpose is.

Quoting the scaladoc [2]:

> An expression that gets replaced at runtime (currently by the optimizer) into a different expression for evaluation. This is mainly used to provide compatibility with other databases.

For example, ParseToTimestamp expression is a RuntimeReplaceable expression and it is replaced by Cast(left, TimestampType) or Cast(UnixTimestamp(left, format), TimestampType) per to_timestamp function (there are two variants).

My question is why is this RuntimeReplaceable better than simply using the Casts as the implementation of to_timestamp functions?

def to_timestamp(s: Column, fmt: String): Column = withExpr {
  // pseudocode
  Cast(UnixTimestamp(left, format), TimestampType)
}

What's wrong with the above implementation compared to the current one?


Reply | Threaded
Open this post in threaded view
|

Re: [SQL] Purpose of RuntimeReplaceable unevaluable unary expressions?

Jacek Laskowski
Yay! That's right!!! Thanks Reynold. Such a short answer with so much information. Thanks.


On Wed, May 30, 2018 at 8:10 PM, Reynold Xin <[hidden email]> wrote:
SQL expressions?

On Wed, May 30, 2018 at 11:09 AM Jacek Laskowski <[hidden email]> wrote:
Hi,

I've been exploring RuntimeReplaceable expressions [1] and have been wondering what their purpose is.

Quoting the scaladoc [2]:

> An expression that gets replaced at runtime (currently by the optimizer) into a different expression for evaluation. This is mainly used to provide compatibility with other databases.

For example, ParseToTimestamp expression is a RuntimeReplaceable expression and it is replaced by Cast(left, TimestampType) or Cast(UnixTimestamp(left, format), TimestampType) per to_timestamp function (there are two variants).

My question is why is this RuntimeReplaceable better than simply using the Casts as the implementation of to_timestamp functions?

def to_timestamp(s: Column, fmt: String): Column = withExpr {
  // pseudocode
  Cast(UnixTimestamp(left, format), TimestampType)
}

What's wrong with the above implementation compared to the current one?