You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Juan Pan <pa...@apache.org> on 2019/09/29 03:36:48 UTC

How to get columnName as `COUNT(*)` , not `EXPR$0`


Hi everyone,


I executed SQL `select count(*) from tb1` through Calcite and resultSet.getMetaData().getColumnName(i) in my project. But the result is `EXPR$0` not `COUNT(*)`. 


Is there any way to get real columnName?


Thanks for your attention.


Regard,
Trista




 Juan Pan


panjuan@apache.org
Juan Pan(Trista), Apache ShardingSphere


Re: How to get columnName as `COUNT(*)` , not `EXPR$0`

Posted by Juan Pan <pa...@apache.org>.
Sorry, 
It is CALCITE-3261.


 Juan Pan


panjuan@apache.org
Juan Pan(Trista), Apache ShardingSphere


On 09/29/2019 16:29,Juan Pan<pa...@apache.org> wrote:
Thanks Danny,
Got it. I will watch CALCITE-326.


Regards,
Trista


Juan Pan


panjuan@apache.org
Juan Pan(Trista), Apache ShardingSphere


On 09/29/2019 16:15,Danny Chan<yu...@gmail.com> wrote:
No worries, Juan Pan, welcome to contribute to Apache Calcite.

Calcite always put the JIRA issues in the first place instead of GitHub page because it is really food for bug/problem tracing.

If you have any questions or want to discuss something, welcome to send mail into the DEV mailing list.

If it is a known bug or promotion, feel free to fire a JIRA issue and we move the discussion there. The committers would help you and what you need to do is describe your problems/cases clearly in the JIRA issue.

Best,
Danny Chan
在 2019年9月29日 +0800 PM3:23,Juan Pan <pa...@apache.org>,写道:
Actually, i think this problem should be already raised by others, for it is obvious enough. But i visited Calcite gitHub, and can not find issue list, so i sent this email. Yes, Calcite is using Jira for issues, i got.


Given Calcite implements the interfaces of ResultSetMetadata, ResultSet and so on, it should return the real columnName or columnLabel from SQL, not the parsing expr(?) which is somewhat... strange to users. When i first got the result `EXPR$0`, i doubted whether my program went wrong?


Recently, i am exploring Calcite, and i’d like to do some contributions to Calcite community if i can. But.. for a new one, it seems difficult.


Regard,
Trista


Juan Pan


panjuan@apache.org
Juan Pan(Trista), Apache ShardingSphere


On 09/29/2019 14:48,Danny Chan<yu...@gmail.com> wrote:
There is already a JIRA issue to trace this problem[1], maybe we can move the discussion to there.

[1] https://issues.apache.org/jira/browse/CALCITE-3261

Best,
Danny Chan
在 2019年9月29日 +0800 AM11:39,Juan Pan <pa...@apache.org>,写道:


Hi everyone,


I executed SQL `select count(*) from tb1` through Calcite and resultSet.getMetaData().getColumnName(i) in my project. But the result is `EXPR$0` not `COUNT(*)`.


Is there any way to get real columnName?


Thanks for your attention.


Regard,
Trista




Juan Pan


panjuan@apache.org
Juan Pan(Trista), Apache ShardingSphere


Re: How to get columnName as `COUNT(*)` , not `EXPR$0`

Posted by Juan Pan <pa...@apache.org>.
Thanks Danny,
Got it. I will watch CALCITE-326.


Regards,
Trista


 Juan Pan


panjuan@apache.org
Juan Pan(Trista), Apache ShardingSphere


On 09/29/2019 16:15,Danny Chan<yu...@gmail.com> wrote:
No worries, Juan Pan, welcome to contribute to Apache Calcite.

Calcite always put the JIRA issues in the first place instead of GitHub page because it is really food for bug/problem tracing.

If you have any questions or want to discuss something, welcome to send mail into the DEV mailing list.

If it is a known bug or promotion, feel free to fire a JIRA issue and we move the discussion there. The committers would help you and what you need to do is describe your problems/cases clearly in the JIRA issue.

Best,
Danny Chan
在 2019年9月29日 +0800 PM3:23,Juan Pan <pa...@apache.org>,写道:
Actually, i think this problem should be already raised by others, for it is obvious enough. But i visited Calcite gitHub, and can not find issue list, so i sent this email. Yes, Calcite is using Jira for issues, i got.


Given Calcite implements the interfaces of ResultSetMetadata, ResultSet and so on, it should return the real columnName or columnLabel from SQL, not the parsing expr(?) which is somewhat... strange to users. When i first got the result `EXPR$0`, i doubted whether my program went wrong?


Recently, i am exploring Calcite, and i’d like to do some contributions to Calcite community if i can. But.. for a new one, it seems difficult.


Regard,
Trista


Juan Pan


panjuan@apache.org
Juan Pan(Trista), Apache ShardingSphere


On 09/29/2019 14:48,Danny Chan<yu...@gmail.com> wrote:
There is already a JIRA issue to trace this problem[1], maybe we can move the discussion to there.

[1] https://issues.apache.org/jira/browse/CALCITE-3261

Best,
Danny Chan
在 2019年9月29日 +0800 AM11:39,Juan Pan <pa...@apache.org>,写道:


Hi everyone,


I executed SQL `select count(*) from tb1` through Calcite and resultSet.getMetaData().getColumnName(i) in my project. But the result is `EXPR$0` not `COUNT(*)`.


Is there any way to get real columnName?


Thanks for your attention.


Regard,
Trista




Juan Pan


panjuan@apache.org
Juan Pan(Trista), Apache ShardingSphere


Re: How to get columnName as `COUNT(*)` , not `EXPR$0`

Posted by Danny Chan <yu...@gmail.com>.
No worries, Juan Pan, welcome to contribute to Apache Calcite.

Calcite always put the JIRA issues in the first place instead of GitHub page because it is really food for bug/problem tracing.

If you have any questions or want to discuss something, welcome to send mail into the DEV mailing list.

If it is a known bug or promotion, feel free to fire a JIRA issue and we move the discussion there. The committers would help you and what you need to do is describe your problems/cases clearly in the JIRA issue.

Best,
Danny Chan
在 2019年9月29日 +0800 PM3:23,Juan Pan <pa...@apache.org>,写道:
> Actually, i think this problem should be already raised by others, for it is obvious enough. But i visited Calcite gitHub, and can not find issue list, so i sent this email. Yes, Calcite is using Jira for issues, i got.
>
>
> Given Calcite implements the interfaces of ResultSetMetadata, ResultSet and so on, it should return the real columnName or columnLabel from SQL, not the parsing expr(?) which is somewhat... strange to users. When i first got the result `EXPR$0`, i doubted whether my program went wrong?
>
>
> Recently, i am exploring Calcite, and i’d like to do some contributions to Calcite community if i can. But.. for a new one, it seems difficult.
>
>
> Regard,
> Trista
>
>
> Juan Pan
>
>
> panjuan@apache.org
> Juan Pan(Trista), Apache ShardingSphere
>
>
> On 09/29/2019 14:48,Danny Chan<yu...@gmail.com> wrote:
> There is already a JIRA issue to trace this problem[1], maybe we can move the discussion to there.
>
> [1] https://issues.apache.org/jira/browse/CALCITE-3261
>
> Best,
> Danny Chan
> 在 2019年9月29日 +0800 AM11:39,Juan Pan <pa...@apache.org>,写道:
>
>
> Hi everyone,
>
>
> I executed SQL `select count(*) from tb1` through Calcite and resultSet.getMetaData().getColumnName(i) in my project. But the result is `EXPR$0` not `COUNT(*)`.
>
>
> Is there any way to get real columnName?
>
>
> Thanks for your attention.
>
>
> Regard,
> Trista
>
>
>
>
> Juan Pan
>
>
> panjuan@apache.org
> Juan Pan(Trista), Apache ShardingSphere
>

Re: How to get columnName as `COUNT(*)` , not `EXPR$0`

Posted by Juan Pan <pa...@apache.org>.
Actually, i think this problem should be already raised by others, for it is obvious enough. But i visited Calcite gitHub, and can not find issue list, so i sent this email. Yes, Calcite is using Jira for issues, i got.


Given Calcite implements the interfaces of ResultSetMetadata, ResultSet and so on, it should return the real columnName or columnLabel from SQL, not the parsing expr(?) which is somewhat... strange to users. When i first got the result `EXPR$0`, i doubted whether my program went wrong?


Recently, i am exploring Calcite, and i’d like to do some contributions to Calcite community if i can. But.. for a new one, it seems difficult.


Regard,
Trista


 Juan Pan


panjuan@apache.org
Juan Pan(Trista), Apache ShardingSphere


On 09/29/2019 14:48,Danny Chan<yu...@gmail.com> wrote:
There is already a JIRA issue to trace this problem[1], maybe we can move the discussion to there.

[1] https://issues.apache.org/jira/browse/CALCITE-3261

Best,
Danny Chan
在 2019年9月29日 +0800 AM11:39,Juan Pan <pa...@apache.org>,写道:


Hi everyone,


I executed SQL `select count(*) from tb1` through Calcite and resultSet.getMetaData().getColumnName(i) in my project. But the result is `EXPR$0` not `COUNT(*)`.


Is there any way to get real columnName?


Thanks for your attention.


Regard,
Trista




Juan Pan


panjuan@apache.org
Juan Pan(Trista), Apache ShardingSphere


Re: How to get columnName as `COUNT(*)` , not `EXPR$0`

Posted by Danny Chan <yu...@gmail.com>.
There is already a JIRA issue to trace this problem[1], maybe we can move the discussion to there.

[1] https://issues.apache.org/jira/browse/CALCITE-3261

Best,
Danny Chan
在 2019年9月29日 +0800 AM11:39,Juan Pan <pa...@apache.org>,写道:
>
>
> Hi everyone,
>
>
> I executed SQL `select count(*) from tb1` through Calcite and resultSet.getMetaData().getColumnName(i) in my project. But the result is `EXPR$0` not `COUNT(*)`.
>
>
> Is there any way to get real columnName?
>
>
> Thanks for your attention.
>
>
> Regard,
> Trista
>
>
>
>
> Juan Pan
>
>
> panjuan@apache.org
> Juan Pan(Trista), Apache ShardingSphere
>

Re: How to get columnName as `COUNT(*)` , not `EXPR$0`

Posted by XING JIN <ji...@gmail.com>.
It's my pleasure, you are welcome ~

Juan Pan <pa...@apache.org> 于2019年9月29日周日 下午2:24写道:

> Hi XING,
> I appreciate your kindness. :-D Your detailed and prompt replies really
> helped me a lot.
> I will review the java doc you mentioned.
>
>
> Best wishes,
> Trista
>
>
>  Juan Pan
>
>
> panjuan@apache.org
> Juan Pan(Trista), Apache ShardingSphere
>
>
> On 09/29/2019 13:58,XING JIN<ji...@gmail.com> wrote:
> You can check the below doc of SqlValidatorUtil#getAlias for explanation:
>
> /**
> * Derives an alias for a node, and invents a mangled identifier if it
> * cannot.
> *
> * <p>Examples:
> *
> * <ul>
> * <li>Alias: "1 + 2 as foo" yields "foo"
> * <li>Identifier: "foo.bar.baz" yields "baz"
> * <li>Anything else yields "expr$<i>ordinal</i>"
> * </ul>
> *
> * @return An alias, if one can be derived; or a synthetic alias
> * "expr$<i>ordinal</i>" if ordinal &lt; 0; otherwise null
> */
> public static String getAlias(SqlNode node, int ordinal)
>
> But from my experience, you'd better not rely on above logic heavily. If
> you really care about the output name, just give it an alias explicitly.
>
> Juan Pan <pa...@apache.org> 于2019年9月29日周日 下午1:27写道:
>
> That means Calcite can only return real columnName or columnLabel from
> simple column or alias. And any aggregate function, or calculate expression
> without alias, parsing expression, i.e, `EXPR$0` will be returned?
>
>
> Juan Pan
>
>
> panjuan@apache.org
> Juan Pan(Trista), Apache ShardingSphere
>
>
> On 09/29/2019 13:16,XING JIN<ji...@gmail.com> wrote:
> If no column name given explicitly, e.g. by alias or simple identifier,
> Calcite will derive one but not from the aggregate function.
>
> Juan Pan <pa...@apache.org> 于2019年9月29日周日 下午1:12写道:
>
> Thank for your reply. It is a indirect way to get columnName.
>
>
> Calcite can not return the real columnName from SQL, is it right?
>
>
> Juan Pan
>
>
> panjuan@apache.org
> Juan Pan(Trista), Apache ShardingSphere
>
>
> On 09/29/2019 12:21,XING JIN<ji...@gmail.com> wrote:
> You can try to give an alias for the selected column.
>
> Juan Pan <pa...@apache.org> 于2019年9月29日周日 上午11:39写道:
>
>
>
> Hi everyone,
>
>
> I executed SQL `select count(*) from tb1` through Calcite and
> resultSet.getMetaData().getColumnName(i) in my project. But the result is
> `EXPR$0` not `COUNT(*)`.
>
>
> Is there any way to get real columnName?
>
>
> Thanks for your attention.
>
>
> Regard,
> Trista
>
>
>
>
> Juan Pan
>
>
> panjuan@apache.org
> Juan Pan(Trista), Apache ShardingSphere
>
>
>
>
>

Re: How to get columnName as `COUNT(*)` , not `EXPR$0`

Posted by Juan Pan <pa...@apache.org>.
Hi XING,
I appreciate your kindness. :-D Your detailed and prompt replies really helped me a lot.
I will review the java doc you mentioned.


Best wishes,
Trista


 Juan Pan


panjuan@apache.org
Juan Pan(Trista), Apache ShardingSphere


On 09/29/2019 13:58,XING JIN<ji...@gmail.com> wrote:
You can check the below doc of SqlValidatorUtil#getAlias for explanation:

/**
* Derives an alias for a node, and invents a mangled identifier if it
* cannot.
*
* <p>Examples:
*
* <ul>
* <li>Alias: "1 + 2 as foo" yields "foo"
* <li>Identifier: "foo.bar.baz" yields "baz"
* <li>Anything else yields "expr$<i>ordinal</i>"
* </ul>
*
* @return An alias, if one can be derived; or a synthetic alias
* "expr$<i>ordinal</i>" if ordinal &lt; 0; otherwise null
*/
public static String getAlias(SqlNode node, int ordinal)

But from my experience, you'd better not rely on above logic heavily. If
you really care about the output name, just give it an alias explicitly.

Juan Pan <pa...@apache.org> 于2019年9月29日周日 下午1:27写道:

That means Calcite can only return real columnName or columnLabel from
simple column or alias. And any aggregate function, or calculate expression
without alias, parsing expression, i.e, `EXPR$0` will be returned?


Juan Pan


panjuan@apache.org
Juan Pan(Trista), Apache ShardingSphere


On 09/29/2019 13:16,XING JIN<ji...@gmail.com> wrote:
If no column name given explicitly, e.g. by alias or simple identifier,
Calcite will derive one but not from the aggregate function.

Juan Pan <pa...@apache.org> 于2019年9月29日周日 下午1:12写道:

Thank for your reply. It is a indirect way to get columnName.


Calcite can not return the real columnName from SQL, is it right?


Juan Pan


panjuan@apache.org
Juan Pan(Trista), Apache ShardingSphere


On 09/29/2019 12:21,XING JIN<ji...@gmail.com> wrote:
You can try to give an alias for the selected column.

Juan Pan <pa...@apache.org> 于2019年9月29日周日 上午11:39写道:



Hi everyone,


I executed SQL `select count(*) from tb1` through Calcite and
resultSet.getMetaData().getColumnName(i) in my project. But the result is
`EXPR$0` not `COUNT(*)`.


Is there any way to get real columnName?


Thanks for your attention.


Regard,
Trista




Juan Pan


panjuan@apache.org
Juan Pan(Trista), Apache ShardingSphere





Re: How to get columnName as `COUNT(*)` , not `EXPR$0`

Posted by XING JIN <ji...@gmail.com>.
You can check the below doc of SqlValidatorUtil#getAlias for explanation:

  /**
   * Derives an alias for a node, and invents a mangled identifier if it
   * cannot.
   *
   * <p>Examples:
   *
   * <ul>
   * <li>Alias: "1 + 2 as foo" yields "foo"
   * <li>Identifier: "foo.bar.baz" yields "baz"
   * <li>Anything else yields "expr$<i>ordinal</i>"
   * </ul>
   *
   * @return An alias, if one can be derived; or a synthetic alias
   * "expr$<i>ordinal</i>" if ordinal &lt; 0; otherwise null
   */
  public static String getAlias(SqlNode node, int ordinal)

But from my experience, you'd better not rely on above logic heavily. If
you really care about the output name, just give it an alias explicitly.

Juan Pan <pa...@apache.org> 于2019年9月29日周日 下午1:27写道:

> That means Calcite can only return real columnName or columnLabel from
> simple column or alias. And any aggregate function, or calculate expression
> without alias, parsing expression, i.e, `EXPR$0` will be returned?
>
>
>  Juan Pan
>
>
> panjuan@apache.org
> Juan Pan(Trista), Apache ShardingSphere
>
>
> On 09/29/2019 13:16,XING JIN<ji...@gmail.com> wrote:
> If no column name given explicitly, e.g. by alias or simple identifier,
> Calcite will derive one but not from the aggregate function.
>
> Juan Pan <pa...@apache.org> 于2019年9月29日周日 下午1:12写道:
>
> Thank for your reply. It is a indirect way to get columnName.
>
>
> Calcite can not return the real columnName from SQL, is it right?
>
>
> Juan Pan
>
>
> panjuan@apache.org
> Juan Pan(Trista), Apache ShardingSphere
>
>
> On 09/29/2019 12:21,XING JIN<ji...@gmail.com> wrote:
> You can try to give an alias for the selected column.
>
> Juan Pan <pa...@apache.org> 于2019年9月29日周日 上午11:39写道:
>
>
>
> Hi everyone,
>
>
> I executed SQL `select count(*) from tb1` through Calcite and
> resultSet.getMetaData().getColumnName(i) in my project. But the result is
> `EXPR$0` not `COUNT(*)`.
>
>
> Is there any way to get real columnName?
>
>
> Thanks for your attention.
>
>
> Regard,
> Trista
>
>
>
>
> Juan Pan
>
>
> panjuan@apache.org
> Juan Pan(Trista), Apache ShardingSphere
>
>
>
>

Re: How to get columnName as `COUNT(*)` , not `EXPR$0`

Posted by Juan Pan <pa...@apache.org>.
That means Calcite can only return real columnName or columnLabel from simple column or alias. And any aggregate function, or calculate expression without alias, parsing expression, i.e, `EXPR$0` will be returned?


 Juan Pan


panjuan@apache.org
Juan Pan(Trista), Apache ShardingSphere


On 09/29/2019 13:16,XING JIN<ji...@gmail.com> wrote:
If no column name given explicitly, e.g. by alias or simple identifier,
Calcite will derive one but not from the aggregate function.

Juan Pan <pa...@apache.org> 于2019年9月29日周日 下午1:12写道:

Thank for your reply. It is a indirect way to get columnName.


Calcite can not return the real columnName from SQL, is it right?


Juan Pan


panjuan@apache.org
Juan Pan(Trista), Apache ShardingSphere


On 09/29/2019 12:21,XING JIN<ji...@gmail.com> wrote:
You can try to give an alias for the selected column.

Juan Pan <pa...@apache.org> 于2019年9月29日周日 上午11:39写道:



Hi everyone,


I executed SQL `select count(*) from tb1` through Calcite and
resultSet.getMetaData().getColumnName(i) in my project. But the result is
`EXPR$0` not `COUNT(*)`.


Is there any way to get real columnName?


Thanks for your attention.


Regard,
Trista




Juan Pan


panjuan@apache.org
Juan Pan(Trista), Apache ShardingSphere




Re: How to get columnName as `COUNT(*)` , not `EXPR$0`

Posted by XING JIN <ji...@gmail.com>.
If no column name given explicitly, e.g. by alias or simple identifier,
Calcite will derive one but not from the aggregate function.

Juan Pan <pa...@apache.org> 于2019年9月29日周日 下午1:12写道:

> Thank for your reply. It is a indirect way to get columnName.
>
>
> Calcite can not return the real columnName from SQL, is it right?
>
>
>  Juan Pan
>
>
> panjuan@apache.org
> Juan Pan(Trista), Apache ShardingSphere
>
>
> On 09/29/2019 12:21,XING JIN<ji...@gmail.com> wrote:
> You can try to give an alias for the selected column.
>
> Juan Pan <pa...@apache.org> 于2019年9月29日周日 上午11:39写道:
>
>
>
> Hi everyone,
>
>
> I executed SQL `select count(*) from tb1` through Calcite and
> resultSet.getMetaData().getColumnName(i) in my project. But the result is
> `EXPR$0` not `COUNT(*)`.
>
>
> Is there any way to get real columnName?
>
>
> Thanks for your attention.
>
>
> Regard,
> Trista
>
>
>
>
> Juan Pan
>
>
> panjuan@apache.org
> Juan Pan(Trista), Apache ShardingSphere
>
>
>

Re: How to get columnName as `COUNT(*)` , not `EXPR$0`

Posted by Juan Pan <pa...@apache.org>.
Thank for your reply. It is a indirect way to get columnName. 


Calcite can not return the real columnName from SQL, is it right?


 Juan Pan


panjuan@apache.org
Juan Pan(Trista), Apache ShardingSphere


On 09/29/2019 12:21,XING JIN<ji...@gmail.com> wrote:
You can try to give an alias for the selected column.

Juan Pan <pa...@apache.org> 于2019年9月29日周日 上午11:39写道:



Hi everyone,


I executed SQL `select count(*) from tb1` through Calcite and
resultSet.getMetaData().getColumnName(i) in my project. But the result is
`EXPR$0` not `COUNT(*)`.


Is there any way to get real columnName?


Thanks for your attention.


Regard,
Trista




Juan Pan


panjuan@apache.org
Juan Pan(Trista), Apache ShardingSphere



Re: How to get columnName as `COUNT(*)` , not `EXPR$0`

Posted by XING JIN <ji...@gmail.com>.
You can try to give an alias for the selected column.

Juan Pan <pa...@apache.org> 于2019年9月29日周日 上午11:39写道:

>
>
> Hi everyone,
>
>
> I executed SQL `select count(*) from tb1` through Calcite and
> resultSet.getMetaData().getColumnName(i) in my project. But the result is
> `EXPR$0` not `COUNT(*)`.
>
>
> Is there any way to get real columnName?
>
>
> Thanks for your attention.
>
>
> Regard,
> Trista
>
>
>
>
>  Juan Pan
>
>
> panjuan@apache.org
> Juan Pan(Trista), Apache ShardingSphere
>
>