You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Shuyi Chen <su...@gmail.com> on 2017/11/07 19:00:21 UTC

Support for ROW value constructor with custom CAST type

Hi,

I want to use the row value constructor and CAST to create a named row, or
even nested named row, e.g.

CREATE TYPE myrowtype AS (f1 INTEGER, f2 VARCHAR(10))
SELECT CAST(ROW(intField, "test") AS myrowtype) AS myRow FROM myTable;

So if converted to JSON, the output will be {"myRow":{"f0": ${intField},
"f1":"test"}}.

I tried it out, the RVC and CAST are working, but seems Calcite doesn't
support CREATE TYPE in the grammar. Please correct me if I am wrong. Thanks
a lot.

Shuyi

-- 
"So you have to trust that the dots will somehow connect in your future."

Re: Support for ROW value constructor with custom CAST type

Posted by Shuyi Chen <su...@gmail.com>.
Thanks a lot for the response.

I'll create a JIRA for adding support for "CREATE TYPE". We need it in the
DDL. I can help with it once you commit the new module, or please let me
know if I can help with the module if needed.

Also, I think we will need CREATE FUNCTION as well for UDFs, will create a
JIRA as well.

On Wed, Nov 8, 2017 at 2:44 PM, Julian Hyde <jh...@apache.org> wrote:

> You are correct. Calcite does not support CREATE TYPE.
>
> In fact it doesn't support any DDL. (I'm working on
> https://issues.apache.org/jira/browse/CALCITE-707, but it's not
> finished, it will be in an optional module, and it won't support
> CREATE TYPE at first.)
>
> You can, however, create types programmatically; search for "address"
> in MockCatalogReader and you will see some examples.
>
> Julian
>
>
> On Wed, Nov 8, 2017 at 2:22 PM, Shuyi Chen <su...@gmail.com> wrote:
> > Ping, any idea? Thanks a lot.
> >
> > Shuyi
> >
> > On Tue, Nov 7, 2017 at 11:00 AM, Shuyi Chen <su...@gmail.com> wrote:
> >
> >> Hi,
> >>
> >> I want to use the row value constructor and CAST to create a named row,
> or
> >> even nested named row, e.g.
> >>
> >> CREATE TYPE myrowtype AS (f1 INTEGER, f2 VARCHAR(10))
> >> SELECT CAST(ROW(intField, "test") AS myrowtype) AS myRow FROM myTable;
> >>
> >> So if converted to JSON, the output will be {"myRow":{"f0": ${intField},
> >> "f1":"test"}}.
> >>
> >> I tried it out, the RVC and CAST are working, but seems Calcite doesn't
> >> support CREATE TYPE in the grammar. Please correct me if I am wrong.
> >> Thanks a lot.
> >>
> >> Shuyi
> >>
> >> --
> >> "So you have to trust that the dots will somehow connect in your
> future."
> >>
> >
> >
> >
> > --
> > "So you have to trust that the dots will somehow connect in your future."
>



-- 
"So you have to trust that the dots will somehow connect in your future."

Re: Support for ROW value constructor with custom CAST type

Posted by Julian Hyde <jh...@apache.org>.
You are correct. Calcite does not support CREATE TYPE.

In fact it doesn't support any DDL. (I'm working on
https://issues.apache.org/jira/browse/CALCITE-707, but it's not
finished, it will be in an optional module, and it won't support
CREATE TYPE at first.)

You can, however, create types programmatically; search for "address"
in MockCatalogReader and you will see some examples.

Julian


On Wed, Nov 8, 2017 at 2:22 PM, Shuyi Chen <su...@gmail.com> wrote:
> Ping, any idea? Thanks a lot.
>
> Shuyi
>
> On Tue, Nov 7, 2017 at 11:00 AM, Shuyi Chen <su...@gmail.com> wrote:
>
>> Hi,
>>
>> I want to use the row value constructor and CAST to create a named row, or
>> even nested named row, e.g.
>>
>> CREATE TYPE myrowtype AS (f1 INTEGER, f2 VARCHAR(10))
>> SELECT CAST(ROW(intField, "test") AS myrowtype) AS myRow FROM myTable;
>>
>> So if converted to JSON, the output will be {"myRow":{"f0": ${intField},
>> "f1":"test"}}.
>>
>> I tried it out, the RVC and CAST are working, but seems Calcite doesn't
>> support CREATE TYPE in the grammar. Please correct me if I am wrong.
>> Thanks a lot.
>>
>> Shuyi
>>
>> --
>> "So you have to trust that the dots will somehow connect in your future."
>>
>
>
>
> --
> "So you have to trust that the dots will somehow connect in your future."

Re: Support for ROW value constructor with custom CAST type

Posted by Shuyi Chen <su...@gmail.com>.
Ping, any idea? Thanks a lot.

Shuyi

On Tue, Nov 7, 2017 at 11:00 AM, Shuyi Chen <su...@gmail.com> wrote:

> Hi,
>
> I want to use the row value constructor and CAST to create a named row, or
> even nested named row, e.g.
>
> CREATE TYPE myrowtype AS (f1 INTEGER, f2 VARCHAR(10))
> SELECT CAST(ROW(intField, "test") AS myrowtype) AS myRow FROM myTable;
>
> So if converted to JSON, the output will be {"myRow":{"f0": ${intField},
> "f1":"test"}}.
>
> I tried it out, the RVC and CAST are working, but seems Calcite doesn't
> support CREATE TYPE in the grammar. Please correct me if I am wrong.
> Thanks a lot.
>
> Shuyi
>
> --
> "So you have to trust that the dots will somehow connect in your future."
>



-- 
"So you have to trust that the dots will somehow connect in your future."