You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Yanjing Wang <zh...@gmail.com> on 2022/04/12 03:36:04 UTC

[DISCUSS] Should DEFAULT be a keyword

Hi community,

In hive, DEFAULT is a default database, so one can write sql
SELECT * FROM DEFAULT.t

In trino, one can write
SELECT * FROM HIVE.DEFAULT.t

But now Calcite treat DEFAULT as a keyword which will be resolved to
DEFAULT() function.

What should I do to make the parser to support the DEFAULT in the table
identifier?

I tried to add the DEFAULT to non-keywords but it would cause DEFAULT()
function fails.

Now I must tell the user wrap the DEFAULT using quotes like this
SELECT * FROM HIVE."DEFAULT".t

Thanks in advance.

Re: [DISCUSS] Should DEFAULT be a keyword

Posted by Yanjing Wang <zh...@gmail.com>.
Thanks Gavin and Julian, If The DEFAULT can't be removed from core parser,
I think the quote is a must. Sorry, I don't know why the hive
choose DEFAULT as its default current database.

Julian Hyde <jh...@gmail.com> 于2022年4月13日周三 02:45写道:

> On reflection, I still think that DEFAULT should be a reserved keyword.
> But I don’t think that wouldn’t prevent us from supporting it as a prefix
> to a table name in the core parser.
>
> Are the deliberations of Hive or Trino (Presto/PrestoDB) public? I’d like
> to know their rationale.
>
> Julian
>
>
> > On Apr 12, 2022, at 11:40 AM, Julian Hyde <jh...@gmail.com>
> wrote:
> >
> > DEFAULT is from the SQL standard. You can use it when invoking UDFs with
> named parameters, e.g.
> >
> >  SELECT myFun(p1 => 1, p2 => DEFAULT, p3 => 3)
> >  FROM t
> >
> > and in an INSERT statement:
> >
> >  INSERT INTO t (x, y, z) VALUES (1, DEFAULT, 2)
> >
> > as long as parameter p2 and column y have default values.
> >
> > So yes, DEFAULT should be a reserved keyword. And Hive screwed up by not
> reading the standard.
> >
> > If there is a database or schema called DEFAULT then you can quote it,
> e.g.
> >
> >  SELECT *
> >  FROM “DEFAULT”.t
> >
> > We could consider making DEFAULT non-reserved in the Babel parser.
> >
> > Julian
> >
> >
> >
> >
> >> On Apr 12, 2022, at 9:06 AM, Gavin Ray <ra...@gmail.com> wrote:
> >>
> >> The hacky way would be to add a grammar clause like this I think:
> >>
> >> | "DEFAULT"
> >>
> >> To the "TableRef2" node in the parser grammar:
> >>
> https://github.com/apache/calcite/blob/82dd78a14f6aef2eeec2f9c94978d04b4acc5359/core/src/main/codegen/templates/Parser.jj#L2087-L2276
> >>
> >> Not sure all the implications this would have elsewhere though.
> >>
> >> Also for personal opinion -- the notion of a "DEFAULT" database I'm not
> >> sure is a universal thing.
> >> I've never worked with analytical DB's, only Postgres/MySQL -- and in
> these
> >> DB's the default database is implicit in your queries.
> >>
> >> IE if I connect to a database called "mydb", all queries are
> automatically
> >> prefixed implicitly with "mydb."
> >>
> >> MySQL I don't think has a default database. A brand-new MySQL DB has 0
> >> databases.
> >> There is one called "mysql" but that's a system DB, like "pg_catalog" or
> >> "information_schema".
> >>
> >> Confusingly this is different in Postgres, where the "postgres" DB is
> one
> >> that exists by default
> >> and IS intended to be a user-facing DB.
> >>
> >>
> >> On Mon, Apr 11, 2022 at 11:36 PM Yanjing Wang <
> zhuangzixiaoyou@gmail.com>
> >> wrote:
> >>
> >>> Hi community,
> >>>
> >>> In hive, DEFAULT is a default database, so one can write sql
> >>> SELECT * FROM DEFAULT.t
> >>>
> >>> In trino, one can write
> >>> SELECT * FROM HIVE.DEFAULT.t
> >>>
> >>> But now Calcite treat DEFAULT as a keyword which will be resolved to
> >>> DEFAULT() function.
> >>>
> >>> What should I do to make the parser to support the DEFAULT in the table
> >>> identifier?
> >>>
> >>> I tried to add the DEFAULT to non-keywords but it would cause DEFAULT()
> >>> function fails.
> >>>
> >>> Now I must tell the user wrap the DEFAULT using quotes like this
> >>> SELECT * FROM HIVE."DEFAULT".t
> >>>
> >>> Thanks in advance.
> >>>
> >
>
>

Re: [DISCUSS] Should DEFAULT be a keyword

Posted by Julian Hyde <jh...@gmail.com>.
On reflection, I still think that DEFAULT should be a reserved keyword. But I don’t think that wouldn’t prevent us from supporting it as a prefix to a table name in the core parser.

Are the deliberations of Hive or Trino (Presto/PrestoDB) public? I’d like to know their rationale.

Julian
 

> On Apr 12, 2022, at 11:40 AM, Julian Hyde <jh...@gmail.com> wrote:
> 
> DEFAULT is from the SQL standard. You can use it when invoking UDFs with named parameters, e.g.
> 
>  SELECT myFun(p1 => 1, p2 => DEFAULT, p3 => 3)
>  FROM t
> 
> and in an INSERT statement:
> 
>  INSERT INTO t (x, y, z) VALUES (1, DEFAULT, 2)
> 
> as long as parameter p2 and column y have default values.
> 
> So yes, DEFAULT should be a reserved keyword. And Hive screwed up by not reading the standard.
> 
> If there is a database or schema called DEFAULT then you can quote it, e.g.
> 
>  SELECT *
>  FROM “DEFAULT”.t
> 
> We could consider making DEFAULT non-reserved in the Babel parser.
> 
> Julian
> 
> 
> 
> 
>> On Apr 12, 2022, at 9:06 AM, Gavin Ray <ra...@gmail.com> wrote:
>> 
>> The hacky way would be to add a grammar clause like this I think:
>> 
>> | "DEFAULT"
>> 
>> To the "TableRef2" node in the parser grammar:
>> https://github.com/apache/calcite/blob/82dd78a14f6aef2eeec2f9c94978d04b4acc5359/core/src/main/codegen/templates/Parser.jj#L2087-L2276
>> 
>> Not sure all the implications this would have elsewhere though.
>> 
>> Also for personal opinion -- the notion of a "DEFAULT" database I'm not
>> sure is a universal thing.
>> I've never worked with analytical DB's, only Postgres/MySQL -- and in these
>> DB's the default database is implicit in your queries.
>> 
>> IE if I connect to a database called "mydb", all queries are automatically
>> prefixed implicitly with "mydb."
>> 
>> MySQL I don't think has a default database. A brand-new MySQL DB has 0
>> databases.
>> There is one called "mysql" but that's a system DB, like "pg_catalog" or
>> "information_schema".
>> 
>> Confusingly this is different in Postgres, where the "postgres" DB is one
>> that exists by default
>> and IS intended to be a user-facing DB.
>> 
>> 
>> On Mon, Apr 11, 2022 at 11:36 PM Yanjing Wang <zh...@gmail.com>
>> wrote:
>> 
>>> Hi community,
>>> 
>>> In hive, DEFAULT is a default database, so one can write sql
>>> SELECT * FROM DEFAULT.t
>>> 
>>> In trino, one can write
>>> SELECT * FROM HIVE.DEFAULT.t
>>> 
>>> But now Calcite treat DEFAULT as a keyword which will be resolved to
>>> DEFAULT() function.
>>> 
>>> What should I do to make the parser to support the DEFAULT in the table
>>> identifier?
>>> 
>>> I tried to add the DEFAULT to non-keywords but it would cause DEFAULT()
>>> function fails.
>>> 
>>> Now I must tell the user wrap the DEFAULT using quotes like this
>>> SELECT * FROM HIVE."DEFAULT".t
>>> 
>>> Thanks in advance.
>>> 
> 


Re: [DISCUSS] Should DEFAULT be a keyword

Posted by Julian Hyde <jh...@gmail.com>.
DEFAULT is from the SQL standard. You can use it when invoking UDFs with named parameters, e.g.

  SELECT myFun(p1 => 1, p2 => DEFAULT, p3 => 3)
  FROM t

and in an INSERT statement:

  INSERT INTO t (x, y, z) VALUES (1, DEFAULT, 2)

as long as parameter p2 and column y have default values.

So yes, DEFAULT should be a reserved keyword. And Hive screwed up by not reading the standard.

If there is a database or schema called DEFAULT then you can quote it, e.g.

  SELECT *
  FROM “DEFAULT”.t

We could consider making DEFAULT non-reserved in the Babel parser.

Julian




> On Apr 12, 2022, at 9:06 AM, Gavin Ray <ra...@gmail.com> wrote:
> 
> The hacky way would be to add a grammar clause like this I think:
> 
> | "DEFAULT"
> 
> To the "TableRef2" node in the parser grammar:
> https://github.com/apache/calcite/blob/82dd78a14f6aef2eeec2f9c94978d04b4acc5359/core/src/main/codegen/templates/Parser.jj#L2087-L2276
> 
> Not sure all the implications this would have elsewhere though.
> 
> Also for personal opinion -- the notion of a "DEFAULT" database I'm not
> sure is a universal thing.
> I've never worked with analytical DB's, only Postgres/MySQL -- and in these
> DB's the default database is implicit in your queries.
> 
> IE if I connect to a database called "mydb", all queries are automatically
> prefixed implicitly with "mydb."
> 
> MySQL I don't think has a default database. A brand-new MySQL DB has 0
> databases.
> There is one called "mysql" but that's a system DB, like "pg_catalog" or
> "information_schema".
> 
> Confusingly this is different in Postgres, where the "postgres" DB is one
> that exists by default
> and IS intended to be a user-facing DB.
> 
> 
> On Mon, Apr 11, 2022 at 11:36 PM Yanjing Wang <zh...@gmail.com>
> wrote:
> 
>> Hi community,
>> 
>> In hive, DEFAULT is a default database, so one can write sql
>> SELECT * FROM DEFAULT.t
>> 
>> In trino, one can write
>> SELECT * FROM HIVE.DEFAULT.t
>> 
>> But now Calcite treat DEFAULT as a keyword which will be resolved to
>> DEFAULT() function.
>> 
>> What should I do to make the parser to support the DEFAULT in the table
>> identifier?
>> 
>> I tried to add the DEFAULT to non-keywords but it would cause DEFAULT()
>> function fails.
>> 
>> Now I must tell the user wrap the DEFAULT using quotes like this
>> SELECT * FROM HIVE."DEFAULT".t
>> 
>> Thanks in advance.
>> 


Re: [DISCUSS] Should DEFAULT be a keyword

Posted by Gavin Ray <ra...@gmail.com>.
The hacky way would be to add a grammar clause like this I think:

| "DEFAULT"

To the "TableRef2" node in the parser grammar:
https://github.com/apache/calcite/blob/82dd78a14f6aef2eeec2f9c94978d04b4acc5359/core/src/main/codegen/templates/Parser.jj#L2087-L2276

Not sure all the implications this would have elsewhere though.

Also for personal opinion -- the notion of a "DEFAULT" database I'm not
sure is a universal thing.
I've never worked with analytical DB's, only Postgres/MySQL -- and in these
DB's the default database is implicit in your queries.

IE if I connect to a database called "mydb", all queries are automatically
prefixed implicitly with "mydb."

MySQL I don't think has a default database. A brand-new MySQL DB has 0
databases.
There is one called "mysql" but that's a system DB, like "pg_catalog" or
"information_schema".

Confusingly this is different in Postgres, where the "postgres" DB is one
that exists by default
and IS intended to be a user-facing DB.


On Mon, Apr 11, 2022 at 11:36 PM Yanjing Wang <zh...@gmail.com>
wrote:

> Hi community,
>
> In hive, DEFAULT is a default database, so one can write sql
> SELECT * FROM DEFAULT.t
>
> In trino, one can write
> SELECT * FROM HIVE.DEFAULT.t
>
> But now Calcite treat DEFAULT as a keyword which will be resolved to
> DEFAULT() function.
>
> What should I do to make the parser to support the DEFAULT in the table
> identifier?
>
> I tried to add the DEFAULT to non-keywords but it would cause DEFAULT()
> function fails.
>
> Now I must tell the user wrap the DEFAULT using quotes like this
> SELECT * FROM HIVE."DEFAULT".t
>
> Thanks in advance.
>