[jira] [Updated] (CALCITE-4130) Aggregation function in order by clause will throw exception in elasticsearch adapter

2020-07-21 Thread yuqi (Jira)


 [ 
https://issues.apache.org/jira/browse/CALCITE-4130?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-4130:
--
Description: 
For sql like 


{code:java}
select id, count(id) from test group by id order by count(id)
{code}

When execute query, `ElasticsearchTable#aggregate` will throw exception like 

{code:java}
 Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for 
aggs
{code}

Reproduce:

{code:java}
Add test as below in AggregationTest
CalciteAssert.that()
.with(newConnectionFactory())
.query("select cat2, count(cat2) from view group by cat2 order by 
count(cat2)")
.returnsUnordered("cat2=g; EXPR$1=2",
"cat2=h; EXPR$1=1");
{code}

result:

{code:java}
Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for aggs
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchMapping.missingValueFor(ElasticsearchMapping.java:84)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.aggregate(ElasticsearchTable.java:235)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.find(ElasticsearchTable.java:130)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.access$000(ElasticsearchTable.java:70)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable$ElasticsearchQueryable.find(ElasticsearchTable.java:411)
at Baz.bind(Unknown Source)
at 
org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:355)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:315)
at 
org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:507)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.createIterable(CalciteMetaImpl.java:498)
at 
org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:182)
at 
org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64)
at 
org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43)
at 
org.apache.calcite.avatica.AvaticaConnection$1.execute(AvaticaConnection.java:667)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:567)
at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
... 68 more
{code}

till now, this problem can only be found in elasticsearch adapter

  was:
For sql like 


{code:java}
select id, count(id) from test group by id order by count(id)
{code}

When execute query, `ElasticsearchTable#aggregate` will throw exception like 

{code:java}
 Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for 
aggs
{code}

Reproduce:

{code:java}
Add test as below in AggregationTest
CalciteAssert.that()
.with(newConnectionFactory())
.query("select cat2, count(cat2) from view group by cat2 order by 
count(cat2)")
.returnsUnordered("cat2=g; EXPR$1=2",
"cat2=h; EXPR$1=1");
{code}

result:

{code:java}
Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for aggs
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchMapping.missingValueFor(ElasticsearchMapping.java:84)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.aggregate(ElasticsearchTable.java:235)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.find(ElasticsearchTable.java:130)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.access$000(ElasticsearchTable.java:70)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable$ElasticsearchQueryable.find(ElasticsearchTable.java:411)
at Baz.bind(Unknown Source)
at 
org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:355)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:315)
at 
org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:507)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.createIterable(CalciteMetaImpl.java:498)
at 
org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:182)
at 
org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64)
at 
org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43)
at 
org.apache.calcite.avatica.AvaticaConnection$1.execute(AvaticaConnection.java:667)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:567)
at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
at 

[jira] [Updated] (CALCITE-4130) Aggregation function in order by clause will throw exception in elasticsearch adapter

2020-07-21 Thread yuqi (Jira)


 [ 
https://issues.apache.org/jira/browse/CALCITE-4130?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-4130:
--
Summary: Aggregation function in order by clause will throw exception in 
elasticsearch adapter  (was: Aggregation function in order by clause will throw 
exception )

> Aggregation function in order by clause will throw exception in elasticsearch 
> adapter
> -
>
> Key: CALCITE-4130
> URL: https://issues.apache.org/jira/browse/CALCITE-4130
> Project: Calcite
>  Issue Type: Bug
>  Components: elasticsearch-adapter
>Affects Versions: 1.25.0
>Reporter: yuqi
>Priority: Major
>  Labels: pull-request-available
> Fix For: 1.25.0
>
>  Time Spent: 10m
>  Remaining Estimate: 0h
>
> For sql like 
> {code:java}
> select id, count(id) from test group by id order by count(id)
> {code}
> When execute query, `ElasticsearchTable#aggregate` will throw exception like 
> {code:java}
>  Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for 
> aggs
> {code}
> Reproduce:
> {code:java}
> Add test as below in AggregationTest
> CalciteAssert.that()
> .with(newConnectionFactory())
> .query("select cat2, count(cat2) from view group by cat2 order by 
> count(cat2)")
> .returnsUnordered("cat2=g; EXPR$1=2",
> "cat2=h; EXPR$1=1");
> {code}
> result:
> {code:java}
> Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for 
> aggs
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchMapping.missingValueFor(ElasticsearchMapping.java:84)
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.aggregate(ElasticsearchTable.java:235)
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.find(ElasticsearchTable.java:130)
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.access$000(ElasticsearchTable.java:70)
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchTable$ElasticsearchQueryable.find(ElasticsearchTable.java:411)
>   at Baz.bind(Unknown Source)
>   at 
> org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:355)
>   at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:315)
>   at 
> org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:507)
>   at 
> org.apache.calcite.jdbc.CalciteMetaImpl.createIterable(CalciteMetaImpl.java:498)
>   at 
> org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:182)
>   at 
> org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64)
>   at 
> org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43)
>   at 
> org.apache.calcite.avatica.AvaticaConnection$1.execute(AvaticaConnection.java:667)
>   at 
> org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:567)
>   at 
> org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
>   at 
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
>   ... 68 more
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Updated] (CALCITE-4130) Aggregation function in order by clause will throw exception

2020-07-21 Thread yuqi (Jira)


 [ 
https://issues.apache.org/jira/browse/CALCITE-4130?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-4130:
--
Summary: Aggregation function in order by clause will throw exception   
(was: Aggregation function in order by clause will throw exception)

> Aggregation function in order by clause will throw exception 
> -
>
> Key: CALCITE-4130
> URL: https://issues.apache.org/jira/browse/CALCITE-4130
> Project: Calcite
>  Issue Type: Bug
>  Components: elasticsearch-adapter
>Affects Versions: 1.25.0
>Reporter: yuqi
>Priority: Major
>  Labels: pull-request-available
> Fix For: 1.25.0
>
>  Time Spent: 10m
>  Remaining Estimate: 0h
>
> For sql like 
> {code:java}
> select id, count(id) from test group by id order by count(id)
> {code}
> When execute query, `ElasticsearchTable#aggregate` will throw exception like 
> {code:java}
>  Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for 
> aggs
> {code}
> Reproduce:
> {code:java}
> Add test as below in AggregationTest
> CalciteAssert.that()
> .with(newConnectionFactory())
> .query("select cat2, count(cat2) from view group by cat2 order by 
> count(cat2)")
> .returnsUnordered("cat2=g; EXPR$1=2",
> "cat2=h; EXPR$1=1");
> {code}
> result:
> {code:java}
> Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for 
> aggs
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchMapping.missingValueFor(ElasticsearchMapping.java:84)
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.aggregate(ElasticsearchTable.java:235)
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.find(ElasticsearchTable.java:130)
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.access$000(ElasticsearchTable.java:70)
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchTable$ElasticsearchQueryable.find(ElasticsearchTable.java:411)
>   at Baz.bind(Unknown Source)
>   at 
> org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:355)
>   at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:315)
>   at 
> org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:507)
>   at 
> org.apache.calcite.jdbc.CalciteMetaImpl.createIterable(CalciteMetaImpl.java:498)
>   at 
> org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:182)
>   at 
> org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64)
>   at 
> org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43)
>   at 
> org.apache.calcite.avatica.AvaticaConnection$1.execute(AvaticaConnection.java:667)
>   at 
> org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:567)
>   at 
> org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
>   at 
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
>   ... 68 more
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (CALCITE-4130) Aggregation function in order by clause will throw exception

2020-07-20 Thread yuqi (Jira)


[ 
https://issues.apache.org/jira/browse/CALCITE-4130?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17160925#comment-17160925
 ] 

yuqi commented on CALCITE-4130:
---

Name of count(*), sqlline cant' resolve the column name correctly if there is 
not a alias name for function call.

However, even though put an alias name for `count(*)`, problem still exists

> Aggregation function in order by clause will throw exception
> 
>
> Key: CALCITE-4130
> URL: https://issues.apache.org/jira/browse/CALCITE-4130
> Project: Calcite
>  Issue Type: Bug
>  Components: elasticsearch-adapter
>Affects Versions: 1.25.0
>Reporter: yuqi
>Priority: Major
>  Labels: pull-request-available
> Fix For: 1.25.0
>
>  Time Spent: 10m
>  Remaining Estimate: 0h
>
> For sql like 
> {code:java}
> select id, count(id) from test group by id order by count(id)
> {code}
> When execute query, `ElasticsearchTable#aggregate` will throw exception like 
> {code:java}
>  Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for 
> aggs
> {code}
> Reproduce:
> {code:java}
> Add test as below in AggregationTest
> CalciteAssert.that()
> .with(newConnectionFactory())
> .query("select cat2, count(cat2) from view group by cat2 order by 
> count(cat2)")
> .returnsUnordered("cat2=g; EXPR$1=2",
> "cat2=h; EXPR$1=1");
> {code}
> result:
> {code:java}
> Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for 
> aggs
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchMapping.missingValueFor(ElasticsearchMapping.java:84)
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.aggregate(ElasticsearchTable.java:235)
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.find(ElasticsearchTable.java:130)
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.access$000(ElasticsearchTable.java:70)
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchTable$ElasticsearchQueryable.find(ElasticsearchTable.java:411)
>   at Baz.bind(Unknown Source)
>   at 
> org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:355)
>   at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:315)
>   at 
> org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:507)
>   at 
> org.apache.calcite.jdbc.CalciteMetaImpl.createIterable(CalciteMetaImpl.java:498)
>   at 
> org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:182)
>   at 
> org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64)
>   at 
> org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43)
>   at 
> org.apache.calcite.avatica.AvaticaConnection$1.execute(AvaticaConnection.java:667)
>   at 
> org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:567)
>   at 
> org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
>   at 
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
>   ... 68 more
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Comment Edited] (CALCITE-4130) Aggregation function in order by clause will throw exception

2020-07-19 Thread yuqi (Jira)


[ 
https://issues.apache.org/jira/browse/CALCITE-4130?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17160867#comment-17160867
 ] 

yuqi edited comment on CALCITE-4130 at 7/20/20, 3:37 AM:
-

Seems unlikely the problem of rel to sql conversion. After debug, all works 
well exception the implementation of aggregation in es adapter.

for your question, i use the sql line as below:

Connection info:

{code:json}
// Some comments here
{
  "version": "1.0",
  "defaultSchema": "t1",
  "schemas": [
{
  "type": "custom",
  "name": "db1",
  "factory": 
"org.apache.calcite.adapter.elasticsearch.ElasticsearchSchemaFactory",
  "operand": {
"hosts": "[\"http://10.224.120.143:9200\"];,
"database": "test",
"index": "db1"
  }
},
{
  "name": "es",
  "tables": [
{
  "name": "view1",
  "type": "view",
  "sql": "select cast(_MAP['id'] AS bigint) AS id,\n cast(_MAP['name'] 
AS varchar) AS name, cast(_MAP['addr'] AS varchar) AS addr from \"db1\".\"db1\""
},
{
  "name": "view2",
  "type": "view",
  "sql": "select cast(_MAP['id'] AS bigint) AS id,\n cast(_MAP['name'] 
AS varchar) AS name from \"db1\".\"db1\""
}
  ]
}
  ]
}
{code}

and sql line command as below:
{code:json}
➜  calcite git:(master) ✗ ./sqlline
Listening for transport dt_socket at address: 5005
sqlline version 1.9.0
sqlline> !connect jdbc:calcite:model=elasticsearch/src/test/resources/es.json 
admin admin
log4j:WARN No appenders could be found for logger 
(org.apache.http.impl.nio.client.MainClientExec).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more 
info.
Transaction isolation level TRANSACTION_REPEATABLE_READ is not supported. 
Default (TRANSACTION_NONE) will be used instead.
0: jdbc:calcite:model=elasticsearch/src/test/> !tables
+---+-++--+-+--++---+---++
| TABLE_CAT | TABLE_SCHEM | TABLE_NAME |  TABLE_TYPE  | REMARKS | TYPE_CAT | 
TYPE_SCHEM | TYPE_NAME | SELF_REFERENCING_COL_NAME | REF_GENERATION |
+---+-++--+-+--++---+---++
|   | db1 | db1| TABLE| |  |
|   |   ||
|   | es  | view1  | VIEW | |  |
|   |   ||
|   | es  | view2  | VIEW | |  |
|   |   ||
|   | metadata| COLUMNS| SYSTEM TABLE | |  |
|   |   ||
|   | metadata| TABLES | SYSTEM TABLE | |  |
|   |   ||
+---+-++--+-+--++---+---++
0: jdbc:calcite:model=elasticsearch/src/test/> select ID, count(ID) from 
es.view1 group by ID order by count(ID);
Error: Error while executing SQL "select ID, count(ID) from es.view1 group by 
ID order by count(ID)": Field EXPR$1 not defined for db1 (state=,code=0)
0: jdbc:calcite:model=elasticsearch/src/test/>

{code:shell}



was (Author: yuqi):
Seems unlikely the problem of rel to sql conversion. After debug, all works 
well exception the implementation of aggregation in es adapter.

for your question, i use the sql line as below:

Connection info:

{code:json}
// Some comments here
{
  "version": "1.0",
  "defaultSchema": "t1",
  "schemas": [
{
  "type": "custom",
  "name": "db1",
  "factory": 
"org.apache.calcite.adapter.elasticsearch.ElasticsearchSchemaFactory",
  "operand": {
"hosts": "[\"http://10.224.120.143:9200\"];,
"database": "test",
"index": "db1"
  }
},
{
  "name": "es",
  "tables": [
{
  "name": "view1",
  "type": "view",
  "sql": "select cast(_MAP['id'] AS bigint) AS id,\n cast(_MAP['name'] 
AS varchar) AS name, cast(_MAP['addr'] AS varchar) AS addr from \"db1\".\"db1\""
},
{
  "name": "view2",
  "type": "view",
  "sql": "select cast(_MAP['id'] AS bigint) AS id,\n cast(_MAP['name'] 
AS varchar) AS name from \"db1\".\"db1\""
}
  ]
}
  ]
}
{code}

and sql line command as below:
{code:shell}
➜  calcite git:(master) ✗ ./sqlline
Listening for transport dt_socket at address: 5005
sqlline version 1.9.0
sqlline> !connect 

[jira] [Commented] (CALCITE-4130) Aggregation function in order by clause will throw exception

2020-07-19 Thread yuqi (Jira)


[ 
https://issues.apache.org/jira/browse/CALCITE-4130?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17160867#comment-17160867
 ] 

yuqi commented on CALCITE-4130:
---

Seems unlikely the problem of rel to sql conversion. After debug, all works 
well exception the implementation of aggregation in es adapter.

for your question, i use the sql line as below:

Connection info:

{code:json}
// Some comments here
{
  "version": "1.0",
  "defaultSchema": "t1",
  "schemas": [
{
  "type": "custom",
  "name": "db1",
  "factory": 
"org.apache.calcite.adapter.elasticsearch.ElasticsearchSchemaFactory",
  "operand": {
"hosts": "[\"http://10.224.120.143:9200\"];,
"database": "test",
"index": "db1"
  }
},
{
  "name": "es",
  "tables": [
{
  "name": "view1",
  "type": "view",
  "sql": "select cast(_MAP['id'] AS bigint) AS id,\n cast(_MAP['name'] 
AS varchar) AS name, cast(_MAP['addr'] AS varchar) AS addr from \"db1\".\"db1\""
},
{
  "name": "view2",
  "type": "view",
  "sql": "select cast(_MAP['id'] AS bigint) AS id,\n cast(_MAP['name'] 
AS varchar) AS name from \"db1\".\"db1\""
}
  ]
}
  ]
}
{code}

and sql line command as below:
{code:shell}
➜  calcite git:(master) ✗ ./sqlline
Listening for transport dt_socket at address: 5005
sqlline version 1.9.0
sqlline> !connect jdbc:calcite:model=elasticsearch/src/test/resources/es.json 
admin admin
log4j:WARN No appenders could be found for logger 
(org.apache.http.impl.nio.client.MainClientExec).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more 
info.
Transaction isolation level TRANSACTION_REPEATABLE_READ is not supported. 
Default (TRANSACTION_NONE) will be used instead.
0: jdbc:calcite:model=elasticsearch/src/test/> !tables
+---+-++--+-+--++---+---++
| TABLE_CAT | TABLE_SCHEM | TABLE_NAME |  TABLE_TYPE  | REMARKS | TYPE_CAT | 
TYPE_SCHEM | TYPE_NAME | SELF_REFERENCING_COL_NAME | REF_GENERATION |
+---+-++--+-+--++---+---++
|   | db1 | db1| TABLE| |  |
|   |   ||
|   | es  | view1  | VIEW | |  |
|   |   ||
|   | es  | view2  | VIEW | |  |
|   |   ||
|   | metadata| COLUMNS| SYSTEM TABLE | |  |
|   |   ||
|   | metadata| TABLES | SYSTEM TABLE | |  |
|   |   ||
+---+-++--+-+--++---+---++
0: jdbc:calcite:model=elasticsearch/src/test/> select id, count(id) from 
es.view1 group by id order by count(id);
Error: Error while executing SQL "select id, count(id) from es.view1 group by 
id order by count(id)": From line 1, column 45 to line 1, column 46: Column 
'id' not found in any table; did you mean 'ID'? (state=,code=0)
0: jdbc:calcite:model=elasticsearch/src/test/> select ID, count(ID) from 
es.view1 group by ID order by count(ID);
Error: Error while executing SQL "select ID, count(ID) from es.view1 group by 
ID order by count(ID)": Field EXPR$1 not defined for db1 (state=,code=0)
0: jdbc:calcite:model=elasticsearch/src/test/>

{code:shell}


> Aggregation function in order by clause will throw exception
> 
>
> Key: CALCITE-4130
> URL: https://issues.apache.org/jira/browse/CALCITE-4130
> Project: Calcite
>  Issue Type: Bug
>  Components: elasticsearch-adapter
>Affects Versions: 1.25.0
>Reporter: yuqi
>Priority: Major
>  Labels: pull-request-available
> Fix For: 1.25.0
>
>  Time Spent: 10m
>  Remaining Estimate: 0h
>
> For sql like 
> {code:java}
> select id, count(id) from test group by id order by count(id)
> {code}
> When execute query, `ElasticsearchTable#aggregate` will throw exception like 
> {code:java}
>  Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for 
> aggs
> {code}
> Reproduce:
> {code:java}
> Add test as below in AggregationTest
> CalciteAssert.that()
> .with(newConnectionFactory())
> .query("select cat2, count(cat2) 

[jira] [Updated] (CALCITE-4130) Aggregation function in order by clause will throw exception

2020-07-19 Thread yuqi (Jira)


 [ 
https://issues.apache.org/jira/browse/CALCITE-4130?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-4130:
--
Description: 
For sql like 


{code:java}
select id, count(id) from test group by id order by count(id)
{code}

When execute query, `ElasticsearchTable#aggregate` will throw exception like 

{code:java}
 Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for 
aggs
{code}

Reproduce:

{code:java}
Add test as below in AggregationTest
CalciteAssert.that()
.with(newConnectionFactory())
.query("select cat2, count(cat2) from view group by cat2 order by 
count(cat2)")
.returnsUnordered("cat2=g; EXPR$1=2",
"cat2=h; EXPR$1=1");
{code}

result:

{code:java}
Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for aggs
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchMapping.missingValueFor(ElasticsearchMapping.java:84)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.aggregate(ElasticsearchTable.java:235)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.find(ElasticsearchTable.java:130)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.access$000(ElasticsearchTable.java:70)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable$ElasticsearchQueryable.find(ElasticsearchTable.java:411)
at Baz.bind(Unknown Source)
at 
org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:355)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:315)
at 
org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:507)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.createIterable(CalciteMetaImpl.java:498)
at 
org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:182)
at 
org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64)
at 
org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43)
at 
org.apache.calcite.avatica.AvaticaConnection$1.execute(AvaticaConnection.java:667)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:567)
at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
... 68 more
{code}


  was:
For sql like 

`select id, count(id) from test group by id order by count(id)`

When execute query, `ElasticsearchTable#aggregate` will throw exception like 
```
 Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for 
aggs
```

Reproduce:

Add test as below in AggregationTest
CalciteAssert.that()
.with(newConnectionFactory())
.query("select cat2, count(cat2) from view group by cat2 order by 
count(cat2)")
.returnsUnordered("cat2=g; EXPR$1=2",
"cat2=h; EXPR$1=1");

result:

```
Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for aggs
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchMapping.missingValueFor(ElasticsearchMapping.java:84)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.aggregate(ElasticsearchTable.java:235)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.find(ElasticsearchTable.java:130)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.access$000(ElasticsearchTable.java:70)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable$ElasticsearchQueryable.find(ElasticsearchTable.java:411)
at Baz.bind(Unknown Source)
at 
org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:355)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:315)
at 
org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:507)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.createIterable(CalciteMetaImpl.java:498)
at 
org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:182)
at 
org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64)
at 
org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43)
at 
org.apache.calcite.avatica.AvaticaConnection$1.execute(AvaticaConnection.java:667)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:567)
at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
... 68 more


```


> Aggregation function in order by clause will throw exception
> 

[jira] [Updated] (CALCITE-4130) Aggregation function in order by clause will throw E

2020-07-18 Thread yuqi (Jira)


 [ 
https://issues.apache.org/jira/browse/CALCITE-4130?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-4130:
--
Description: 
For sql like 

`select id, count(id) from test group by id order by count(id)`

When execute query, `ElasticsearchTable#aggregate` will throw exception like 
```
 Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for 
aggs
```

Reproduce:

Add test as below in AggregationTest
CalciteAssert.that()
.with(newConnectionFactory())
.query("select cat2, count(cat2) from view group by cat2 order by 
count(cat2)")
.returnsUnordered("cat2=g; EXPR$1=2",
"cat2=h; EXPR$1=1");

result:

```
Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for aggs
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchMapping.missingValueFor(ElasticsearchMapping.java:84)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.aggregate(ElasticsearchTable.java:235)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.find(ElasticsearchTable.java:130)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.access$000(ElasticsearchTable.java:70)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable$ElasticsearchQueryable.find(ElasticsearchTable.java:411)
at Baz.bind(Unknown Source)
at 
org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:355)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:315)
at 
org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:507)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.createIterable(CalciteMetaImpl.java:498)
at 
org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:182)
at 
org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64)
at 
org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43)
at 
org.apache.calcite.avatica.AvaticaConnection$1.execute(AvaticaConnection.java:667)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:567)
at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
... 68 more


```

  was:
For sql like 

`select id, count(id) from test group by id order by count(id)`

When execute query, `ElasticsearchTable#aggregate` will throw exception like 
```
 Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for 
aggs
```


> Aggregation function in order by clause will throw E
> 
>
> Key: CALCITE-4130
> URL: https://issues.apache.org/jira/browse/CALCITE-4130
> Project: Calcite
>  Issue Type: Bug
>  Components: elasticsearch-adapter
>Affects Versions: 1.25.0
> Environment: Add test as below in AggregationTest
> CalciteAssert.that()
> .with(newConnectionFactory())
> .query("select cat2, count(cat2) from view group by cat2 order by 
> count(cat2)")
> .returnsUnordered("cat2=g; EXPR$1=2",
> "cat2=h; EXPR$1=1");
> result:
> ```
> Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for 
> aggs
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchMapping.missingValueFor(ElasticsearchMapping.java:84)
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.aggregate(ElasticsearchTable.java:235)
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.find(ElasticsearchTable.java:130)
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.access$000(ElasticsearchTable.java:70)
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchTable$ElasticsearchQueryable.find(ElasticsearchTable.java:411)
>   at Baz.bind(Unknown Source)
>   at 
> org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:355)
>   at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:315)
>   at 
> org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:507)
>   at 
> org.apache.calcite.jdbc.CalciteMetaImpl.createIterable(CalciteMetaImpl.java:498)
>   at 
> org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:182)
>   at 
> org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64)
>   at 
> org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43)
>   at 
> org.apache.calcite.avatica.AvaticaConnection$1.execute(AvaticaConnection.java:667)
>   at 
> 

[jira] [Updated] (CALCITE-4130) Aggregation function in order by clause will throw E

2020-07-18 Thread yuqi (Jira)


 [ 
https://issues.apache.org/jira/browse/CALCITE-4130?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-4130:
--
Environment: (was: Add test as below in AggregationTest
CalciteAssert.that()
.with(newConnectionFactory())
.query("select cat2, count(cat2) from view group by cat2 order by 
count(cat2)")
.returnsUnordered("cat2=g; EXPR$1=2",
"cat2=h; EXPR$1=1");

result:

```
Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for aggs
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchMapping.missingValueFor(ElasticsearchMapping.java:84)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.aggregate(ElasticsearchTable.java:235)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.find(ElasticsearchTable.java:130)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.access$000(ElasticsearchTable.java:70)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable$ElasticsearchQueryable.find(ElasticsearchTable.java:411)
at Baz.bind(Unknown Source)
at 
org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:355)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:315)
at 
org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:507)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.createIterable(CalciteMetaImpl.java:498)
at 
org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:182)
at 
org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64)
at 
org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43)
at 
org.apache.calcite.avatica.AvaticaConnection$1.execute(AvaticaConnection.java:667)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:567)
at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
... 68 more


```)

> Aggregation function in order by clause will throw E
> 
>
> Key: CALCITE-4130
> URL: https://issues.apache.org/jira/browse/CALCITE-4130
> Project: Calcite
>  Issue Type: Bug
>  Components: elasticsearch-adapter
>Affects Versions: 1.25.0
>Reporter: yuqi
>Priority: Major
> Fix For: 1.25.0
>
>
> For sql like 
> `select id, count(id) from test group by id order by count(id)`
> When execute query, `ElasticsearchTable#aggregate` will throw exception like 
> ```
>  Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for 
> aggs
> ```
> Reproduce:
> Add test as below in AggregationTest
> CalciteAssert.that()
> .with(newConnectionFactory())
> .query("select cat2, count(cat2) from view group by cat2 order by 
> count(cat2)")
> .returnsUnordered("cat2=g; EXPR$1=2",
> "cat2=h; EXPR$1=1");
> result:
> ```
> Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for 
> aggs
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchMapping.missingValueFor(ElasticsearchMapping.java:84)
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.aggregate(ElasticsearchTable.java:235)
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.find(ElasticsearchTable.java:130)
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.access$000(ElasticsearchTable.java:70)
>   at 
> org.apache.calcite.adapter.elasticsearch.ElasticsearchTable$ElasticsearchQueryable.find(ElasticsearchTable.java:411)
>   at Baz.bind(Unknown Source)
>   at 
> org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:355)
>   at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:315)
>   at 
> org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:507)
>   at 
> org.apache.calcite.jdbc.CalciteMetaImpl.createIterable(CalciteMetaImpl.java:498)
>   at 
> org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:182)
>   at 
> org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64)
>   at 
> org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43)
>   at 
> org.apache.calcite.avatica.AvaticaConnection$1.execute(AvaticaConnection.java:667)
>   at 
> org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:567)
>   at 
> org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
>   at 
> 

[jira] [Created] (CALCITE-4130) Aggregation function in order by clause will throw E

2020-07-18 Thread yuqi (Jira)
yuqi created CALCITE-4130:
-

 Summary: Aggregation function in order by clause will throw E
 Key: CALCITE-4130
 URL: https://issues.apache.org/jira/browse/CALCITE-4130
 Project: Calcite
  Issue Type: Bug
  Components: elasticsearch-adapter
Affects Versions: 1.25.0
 Environment: Add test as below in AggregationTest
CalciteAssert.that()
.with(newConnectionFactory())
.query("select cat2, count(cat2) from view group by cat2 order by 
count(cat2)")
.returnsUnordered("cat2=g; EXPR$1=2",
"cat2=h; EXPR$1=1");

result:

```
Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for aggs
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchMapping.missingValueFor(ElasticsearchMapping.java:84)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.aggregate(ElasticsearchTable.java:235)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.find(ElasticsearchTable.java:130)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.access$000(ElasticsearchTable.java:70)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchTable$ElasticsearchQueryable.find(ElasticsearchTable.java:411)
at Baz.bind(Unknown Source)
at 
org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:355)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:315)
at 
org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:507)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.createIterable(CalciteMetaImpl.java:498)
at 
org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:182)
at 
org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64)
at 
org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43)
at 
org.apache.calcite.avatica.AvaticaConnection$1.execute(AvaticaConnection.java:667)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:567)
at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
... 68 more


```
Reporter: yuqi
 Fix For: 1.25.0


For sql like 

`select id, count(id) from test group by id order by count(id)`

When execute query, `ElasticsearchTable#aggregate` will throw exception like 
```
 Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for 
aggs
```



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Issue Comment Deleted] (CALCITE-3186) IN expressions in UPDATE statements throwing Exceptions

2019-07-10 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-3186?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-3186:
--
Comment: was deleted

(was: [~danny0405] Confirm, see below
```
 @Test
  public void test() throws Exception {
try (Connection c = connect();
 Statement s = c.createStatement()) {
  final String sql1 = "create table t1 (\n"
  + " id1 int, \n"
  + " val1 VARCHAR )";

  final String sql2 = "create table t2 (\n"
  + " id2 int, \n"
  + " val2 VARCHAR )";

  boolean b1 = s.execute(sql1);
  boolean b2 = s.execute(sql2);

  assertThat(b1, is(false));
  assertThat(b2, is(false));

  int x = s.executeUpdate("UPDATE t1 SET val1 = 't2' WHERE id1 IN (1, 2, 
3)");
  assertThat(x, is(1));
}
  }
```

Exception stack: 
```
java.lang.AssertionError: UPDATE

at 
org.apache.calcite.adapter.enumerable.EnumerableTableModify.implement(EnumerableTableModify.java:137)
at 
org.apache.calcite.adapter.enumerable.EnumerableRelImplementor.implementRoot(EnumerableRelImplementor.java:100)
at 
org.apache.calcite.adapter.enumerable.EnumerableInterpretable.toBindable(EnumerableInterpretable.java:112)
at 
org.apache.calcite.prepare.CalcitePrepareImpl$CalcitePreparingStmt.implement(CalcitePrepareImpl.java:1233)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:332)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:231)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:767)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:631)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:601)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:229)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:550)
at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
at 
org.apache.calcite.avatica.AvaticaStatement.executeLargeUpdate(AvaticaStatement.java:246)
at 
org.apache.calcite.avatica.AvaticaStatement.executeUpdate(AvaticaStatement.java:240)
at org.apache.calcite.test.ServerTest.test(ServerTest.java:313)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at 
org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at 
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at 
com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at 
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at 
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

```

```
)

> IN expressions in UPDATE statements throwing Exceptions
> ---
>
> Key: CALCITE-3186
> URL: https://issues.apache.org/jira/browse/CALCITE-3186
> Project: Calcite
>  Issue Type: Bug
>Affects Versions: 1.20.0
>Reporter: Pressenna
>Priority: Major
>
> The patch to get correlated 

[jira] [Comment Edited] (CALCITE-3186) IN expressions in UPDATE statements throwing Exceptions

2019-07-09 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-3186?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16881223#comment-16881223
 ] 

yuqi edited comment on CALCITE-3186 at 7/9/19 1:33 PM:
---

[~danny0405] Confirm, see below
```
 @Test
  public void test() throws Exception {
try (Connection c = connect();
 Statement s = c.createStatement()) {
  final String sql1 = "create table t1 (\n"
  + " id1 int, \n"
  + " val1 VARCHAR )";

  final String sql2 = "create table t2 (\n"
  + " id2 int, \n"
  + " val2 VARCHAR )";

  boolean b1 = s.execute(sql1);
  boolean b2 = s.execute(sql2);

  assertThat(b1, is(false));
  assertThat(b2, is(false));

  int x = s.executeUpdate("UPDATE t1 SET val1 = 't2' WHERE id1 IN (1, 2, 
3)");
  assertThat(x, is(1));
}
  }
```

Exception stack: 
```
java.lang.AssertionError: UPDATE

at 
org.apache.calcite.adapter.enumerable.EnumerableTableModify.implement(EnumerableTableModify.java:137)
at 
org.apache.calcite.adapter.enumerable.EnumerableRelImplementor.implementRoot(EnumerableRelImplementor.java:100)
at 
org.apache.calcite.adapter.enumerable.EnumerableInterpretable.toBindable(EnumerableInterpretable.java:112)
at 
org.apache.calcite.prepare.CalcitePrepareImpl$CalcitePreparingStmt.implement(CalcitePrepareImpl.java:1233)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:332)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:231)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:767)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:631)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:601)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:229)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:550)
at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
at 
org.apache.calcite.avatica.AvaticaStatement.executeLargeUpdate(AvaticaStatement.java:246)
at 
org.apache.calcite.avatica.AvaticaStatement.executeUpdate(AvaticaStatement.java:240)
at org.apache.calcite.test.ServerTest.test(ServerTest.java:313)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at 
org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at 
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at 
com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at 
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at 
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

```

```



was (Author: yuqi):
[~danny0405] Confirm, see below
```java
 @Test
  public void test() throws Exception {
try (Connection c = connect();
 Statement s = c.createStatement()) {
  final String sql1 = "create table t1 (\n"
  + " id1 int, \n"
  + " val1 VARCHAR )";

  final String sql2 = "create table t2 (\n"

[jira] [Commented] (CALCITE-3186) IN expressions in UPDATE statements throwing Exceptions

2019-07-09 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-3186?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16881223#comment-16881223
 ] 

yuqi commented on CALCITE-3186:
---

[~danny0405] Confirm, see below
```java
 @Test
  public void test() throws Exception {
try (Connection c = connect();
 Statement s = c.createStatement()) {
  final String sql1 = "create table t1 (\n"
  + " id1 int, \n"
  + " val1 VARCHAR )";

  final String sql2 = "create table t2 (\n"
  + " id2 int, \n"
  + " val2 VARCHAR )";

  boolean b1 = s.execute(sql1);
  boolean b2 = s.execute(sql2);

  assertThat(b1, is(false));
  assertThat(b2, is(false));

  int x = s.executeUpdate("UPDATE t1 SET val1 = 't2' WHERE id1 IN (1, 2, 
3)");
  assertThat(x, is(1));
}
  }

Exception stack: 
```
java.lang.AssertionError: UPDATE

at 
org.apache.calcite.adapter.enumerable.EnumerableTableModify.implement(EnumerableTableModify.java:137)
at 
org.apache.calcite.adapter.enumerable.EnumerableRelImplementor.implementRoot(EnumerableRelImplementor.java:100)
at 
org.apache.calcite.adapter.enumerable.EnumerableInterpretable.toBindable(EnumerableInterpretable.java:112)
at 
org.apache.calcite.prepare.CalcitePrepareImpl$CalcitePreparingStmt.implement(CalcitePrepareImpl.java:1233)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:332)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:231)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:767)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:631)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:601)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:229)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:550)
at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
at 
org.apache.calcite.avatica.AvaticaStatement.executeLargeUpdate(AvaticaStatement.java:246)
at 
org.apache.calcite.avatica.AvaticaStatement.executeUpdate(AvaticaStatement.java:240)
at org.apache.calcite.test.ServerTest.test(ServerTest.java:313)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at 
org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at 
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at 
com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at 
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at 
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

```

```


> IN expressions in UPDATE statements throwing Exceptions
> ---
>
> Key: CALCITE-3186
> URL: https://issues.apache.org/jira/browse/CALCITE-3186
> Project: Calcite
>  Issue Type: Bug
>Affects Versions: 1.20.0
>Reporter: Pressenna
>Priority: Major
>
> The patch to get 

[jira] [Commented] (CALCITE-3100) cast(? as DATE) won't work with PreparedStatement

2019-07-05 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-3100?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16879198#comment-16879198
 ] 

yuqi commented on CALCITE-3100:
---

By the way, can anyone give me contribution permission ?

> cast(? as DATE) won't work with PreparedStatement
> -
>
> Key: CALCITE-3100
> URL: https://issues.apache.org/jira/browse/CALCITE-3100
> Project: Calcite
>  Issue Type: Bug
>Reporter: Li Xian
>Assignee: Danny Chan
>Priority: Minor
>  Labels: pull-request-available
>  Time Spent: 10m
>  Remaining Estimate: 0h
>
> When I do something like
>  
> {code:java}
> Connection connection =
> DriverManager.getConnection("jdbc:calcite:", info);
> PreparedStatement ps = connection.prepareStatement("select * from EMPS where 
> JOINEDAT=cast(? as DATE)");
> ps.setString(1, "1996-08-03");
> ps.execute();{code}
>  
> It will produce error like below
>  
> {code:java}
> java.sql.SQLException: exception while executing query: java.lang.String 
> cannot be cast to java.lang.Integer
> at org.apache.calcite.avatica.Helper.createException(Helper.java:56)
>  at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
>  at 
> org.apache.calcite.avatica.AvaticaConnection.executeQueryInternal(AvaticaConnection.java:577)
>  at 
> org.apache.calcite.avatica.AvaticaPreparedStatement.execute(AvaticaPreparedStatement.java:239)
>  at org.apache.calcite.test.CsvTest.testDate(CsvTest.java:185)
>  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>  at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>  at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  at java.lang.reflect.Method.invoke(Method.java:498)
>  at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
>  at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>  at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
>  at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
>  at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
>  at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
>  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
>  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
>  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
>  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
>  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
>  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
>  at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
>  at 
> com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
>  at 
> com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
>  at 
> com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
>  at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
>  Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to 
> java.lang.Integer
>  at Baz$1$1.moveNext(Unknown Source)
>  at 
> org.apache.calcite.linq4j.Linq4j$EnumeratorIterator.(Linq4j.java:675)
>  at org.apache.calcite.linq4j.Linq4j.enumeratorIterator(Linq4j.java:95)
>  at 
> org.apache.calcite.linq4j.AbstractEnumerable.iterator(AbstractEnumerable.java:33)
>  at org.apache.calcite.avatica.MetaImpl.createCursor(MetaImpl.java:90)
>  at 
> org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:184)
>  at org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64)
>  at org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43)
>  at 
> org.apache.calcite.avatica.AvaticaConnection.executeQueryInternal(AvaticaConnection.java:573)
>  ... 24 more
> {code}
>  
> It looks like that the 'cast' clause doesn't make effect here with the '?' 
> placeholder parameter.
> I am able to reproduce this error by adding the below testcase to 
> org.apache.calcite.test.CsvTest and run it
> {code:java}
> @Test
> public void testDate() throws Exception {
>   Properties info = new Properties();
>   info.put("model", jsonPath("model"));
>   Connection connection =
>   DriverManager.getConnection("jdbc:calcite:", info);
>   PreparedStatement ps = connection.prepareStatement("select * from EMPS 
> where JOINEDAT=cast(? as DATE)");
>   ps.setString(1, "1996-08-03");
>   ps.execute();
> }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Closed] (CALCITE-2879) Improve filter condition in Join

2019-07-05 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2879?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi closed CALCITE-2879.
-
Resolution: Not A Problem

> Improve filter condition in Join
> 
>
> Key: CALCITE-2879
> URL: https://issues.apache.org/jira/browse/CALCITE-2879
> Project: Calcite
>  Issue Type: Improvement
>Reporter: yuqi
>Priority: Major
>  Labels: pull-request-available
>  Time Spent: 50m
>  Remaining Estimate: 0h
>
> Currently, filter condition in join have not been optimized very well, let's 
> take a simple example
> {code:sql}
> select a.id, b.name from Ta a inner join Tb b on a.id = b.id and a.id < 5;
> {code}
> now, only a.id < 5 can push down, however, as for the sql above,  
> we can infer a.id < 5 and b.id < 5 and both of them can push down. 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-2879) Improve filter condition in Join

2019-07-05 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2879?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16879195#comment-16879195
 ] 

yuqi commented on CALCITE-2879:
---

(y), Indeed, this is a duplication of rule JoinPushTransitivePredicatesRule. i 
will close this issue later

> Improve filter condition in Join
> 
>
> Key: CALCITE-2879
> URL: https://issues.apache.org/jira/browse/CALCITE-2879
> Project: Calcite
>  Issue Type: Improvement
>Reporter: yuqi
>Priority: Major
>  Labels: pull-request-available
>  Time Spent: 50m
>  Remaining Estimate: 0h
>
> Currently, filter condition in join have not been optimized very well, let's 
> take a simple example
> {code:sql}
> select a.id, b.name from Ta a inner join Tb b on a.id = b.id and a.id < 5;
> {code}
> now, only a.id < 5 can push down, however, as for the sql above,  
> we can infer a.id < 5 and b.id < 5 and both of them can push down. 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-3100) cast(? as DATE) won't work with PreparedStatement

2019-07-05 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-3100?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16879124#comment-16879124
 ] 

yuqi commented on CALCITE-3100:
---

[~danny0405] , I have just make a PR on this issue, can you take time to view 
it ?
https://github.com/apache/calcite/pull/1299/files

> cast(? as DATE) won't work with PreparedStatement
> -
>
> Key: CALCITE-3100
> URL: https://issues.apache.org/jira/browse/CALCITE-3100
> Project: Calcite
>  Issue Type: Bug
>Reporter: Li Xian
>Assignee: Danny Chan
>Priority: Minor
>  Labels: pull-request-available
>  Time Spent: 10m
>  Remaining Estimate: 0h
>
> When I do something like
>  
> {code:java}
> Connection connection =
> DriverManager.getConnection("jdbc:calcite:", info);
> PreparedStatement ps = connection.prepareStatement("select * from EMPS where 
> JOINEDAT=cast(? as DATE)");
> ps.setString(1, "1996-08-03");
> ps.execute();{code}
>  
> It will produce error like below
>  
> {code:java}
> java.sql.SQLException: exception while executing query: java.lang.String 
> cannot be cast to java.lang.Integer
> at org.apache.calcite.avatica.Helper.createException(Helper.java:56)
>  at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
>  at 
> org.apache.calcite.avatica.AvaticaConnection.executeQueryInternal(AvaticaConnection.java:577)
>  at 
> org.apache.calcite.avatica.AvaticaPreparedStatement.execute(AvaticaPreparedStatement.java:239)
>  at org.apache.calcite.test.CsvTest.testDate(CsvTest.java:185)
>  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>  at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>  at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  at java.lang.reflect.Method.invoke(Method.java:498)
>  at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
>  at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>  at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
>  at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
>  at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
>  at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
>  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
>  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
>  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
>  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
>  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
>  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
>  at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
>  at 
> com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
>  at 
> com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
>  at 
> com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
>  at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
>  Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to 
> java.lang.Integer
>  at Baz$1$1.moveNext(Unknown Source)
>  at 
> org.apache.calcite.linq4j.Linq4j$EnumeratorIterator.(Linq4j.java:675)
>  at org.apache.calcite.linq4j.Linq4j.enumeratorIterator(Linq4j.java:95)
>  at 
> org.apache.calcite.linq4j.AbstractEnumerable.iterator(AbstractEnumerable.java:33)
>  at org.apache.calcite.avatica.MetaImpl.createCursor(MetaImpl.java:90)
>  at 
> org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:184)
>  at org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64)
>  at org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43)
>  at 
> org.apache.calcite.avatica.AvaticaConnection.executeQueryInternal(AvaticaConnection.java:573)
>  ... 24 more
> {code}
>  
> It looks like that the 'cast' clause doesn't make effect here with the '?' 
> placeholder parameter.
> I am able to reproduce this error by adding the below testcase to 
> org.apache.calcite.test.CsvTest and run it
> {code:java}
> @Test
> public void testDate() throws Exception {
>   Properties info = new Properties();
>   info.put("model", jsonPath("model"));
>   Connection connection =
>   DriverManager.getConnection("jdbc:calcite:", info);
>   PreparedStatement ps = connection.prepareStatement("select * from EMPS 
> where JOINEDAT=cast(? as DATE)");
>   ps.setString(1, "1996-08-03");
>   ps.execute();
> }
> {code}



--
This message was sent by 

[jira] [Comment Edited] (CALCITE-3030) merge sql problem

2019-04-28 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-3030?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16827983#comment-16827983
 ] 

yuqi edited comment on CALCITE-3030 at 4/28/19 12:50 PM:
-

[~wzqiang1332], There seems a bug in calcite
 !wx20190428-204...@2x.png! 

The problem is that calcite only accpet simple identifier in this sentence. 
[~zhanghe] What do you think about this problem ?


was (Author: yuqi):
[~wzqiang1332], There seems a bug in calcite
 !wx20190428-204...@2x.png! 

The problem is that calcite only accpet simple identifier in this sentence. 
[~zhanghe]

> merge sql problem
> -
>
> Key: CALCITE-3030
> URL: https://issues.apache.org/jira/browse/CALCITE-3030
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.19.0
> Environment: OS: win10 (17763)
> JDK: 1.7
>Reporter: wuzq
>Priority: Major
> Fix For: next
>
> Attachments: wx20190428-204...@2x.png
>
>
> The update section of "merge SQL" reports an error when using an alias
> {code:java}
> // if i replace red code with "b = '123456'", I don't get an error
> String sql = "merge into xxx as t1 using yyy as t2 on t1.a = t2.a when 
> matched then update set t1.b = '123456'" ; 
> SqlParser.ConfigBuilder configBuilder = SqlParser.configBuilder();
> configBuilder.setCaseSensitive(false);
> SqlParser.Config config = configBuilder.build();
> SqlParser parser = SqlParser.create(sql, config);
> SqlNode node = parser.parseQuery();
> {code}
> the error
> {code:java}
> //代码占位符
> Exception in thread "main" org.apache.calcite.sql.parser.SqlParseException: 
> Encountered "." at line 1, column 84.
> Was expecting:
> "=" ...
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.convertException(SqlParserImpl.java:355)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.normalizeException(SqlParserImpl.java:143)
> at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:156)
> at com.yatop.Calcite.main(Calcite.java:39)
> Caused by: org.apache.calcite.sql.parser.impl.ParseException: Encountered "." 
> at line 1, column 84.
> Was expecting:
> "=" ...
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.generateParseException(SqlParserImpl.java:25299)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.jj_consume_token(SqlParserImpl.java:25116)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.WhenMatchedClause(SqlParserImpl.java:1414)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlMerge(SqlParserImpl.java:1383)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlStmt(SqlParserImpl.java:861)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlStmtEof(SqlParserImpl.java:877)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.parseSqlStmtEof(SqlParserImpl.java:199)
> at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:148)
> ... 1 more
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Updated] (CALCITE-3030) merge sql problem

2019-04-28 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-3030?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-3030:
--
Attachment: wx20190428-204...@2x.png

> merge sql problem
> -
>
> Key: CALCITE-3030
> URL: https://issues.apache.org/jira/browse/CALCITE-3030
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.19.0
> Environment: OS: win10 (17763)
> JDK: 1.7
>Reporter: wuzq
>Priority: Major
> Fix For: next
>
> Attachments: wx20190428-204...@2x.png
>
>
> The update section of "merge SQL" reports an error when using an alias
> {code:java}
> // if i replace red code with "b = '123456'", I don't get an error
> String sql = "merge into xxx as t1 using yyy as t2 on t1.a = t2.a when 
> matched then update set t1.b = '123456'" ; 
> SqlParser.ConfigBuilder configBuilder = SqlParser.configBuilder();
> configBuilder.setCaseSensitive(false);
> SqlParser.Config config = configBuilder.build();
> SqlParser parser = SqlParser.create(sql, config);
> SqlNode node = parser.parseQuery();
> {code}
> the error
> {code:java}
> //代码占位符
> Exception in thread "main" org.apache.calcite.sql.parser.SqlParseException: 
> Encountered "." at line 1, column 84.
> Was expecting:
> "=" ...
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.convertException(SqlParserImpl.java:355)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.normalizeException(SqlParserImpl.java:143)
> at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:156)
> at com.yatop.Calcite.main(Calcite.java:39)
> Caused by: org.apache.calcite.sql.parser.impl.ParseException: Encountered "." 
> at line 1, column 84.
> Was expecting:
> "=" ...
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.generateParseException(SqlParserImpl.java:25299)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.jj_consume_token(SqlParserImpl.java:25116)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.WhenMatchedClause(SqlParserImpl.java:1414)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlMerge(SqlParserImpl.java:1383)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlStmt(SqlParserImpl.java:861)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlStmtEof(SqlParserImpl.java:877)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.parseSqlStmtEof(SqlParserImpl.java:199)
> at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:148)
> ... 1 more
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-3030) merge sql problem

2019-04-28 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-3030?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16827983#comment-16827983
 ] 

yuqi commented on CALCITE-3030:
---

[~wzqiang1332], There seems a bug in calcite
 !wx20190428-204...@2x.png! 

The problem is that calcite only accpet simple identifier in this sentence. 
[~zhanghe]

> merge sql problem
> -
>
> Key: CALCITE-3030
> URL: https://issues.apache.org/jira/browse/CALCITE-3030
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.19.0
> Environment: OS: win10 (17763)
> JDK: 1.7
>Reporter: wuzq
>Priority: Major
> Fix For: next
>
> Attachments: wx20190428-204...@2x.png
>
>
> The update section of "merge SQL" reports an error when using an alias
> {code:java}
> // if i replace red code with "b = '123456'", I don't get an error
> String sql = "merge into xxx as t1 using yyy as t2 on t1.a = t2.a when 
> matched then update set t1.b = '123456'" ; 
> SqlParser.ConfigBuilder configBuilder = SqlParser.configBuilder();
> configBuilder.setCaseSensitive(false);
> SqlParser.Config config = configBuilder.build();
> SqlParser parser = SqlParser.create(sql, config);
> SqlNode node = parser.parseQuery();
> {code}
> the error
> {code:java}
> //代码占位符
> Exception in thread "main" org.apache.calcite.sql.parser.SqlParseException: 
> Encountered "." at line 1, column 84.
> Was expecting:
> "=" ...
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.convertException(SqlParserImpl.java:355)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.normalizeException(SqlParserImpl.java:143)
> at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:156)
> at com.yatop.Calcite.main(Calcite.java:39)
> Caused by: org.apache.calcite.sql.parser.impl.ParseException: Encountered "." 
> at line 1, column 84.
> Was expecting:
> "=" ...
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.generateParseException(SqlParserImpl.java:25299)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.jj_consume_token(SqlParserImpl.java:25116)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.WhenMatchedClause(SqlParserImpl.java:1414)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlMerge(SqlParserImpl.java:1383)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlStmt(SqlParserImpl.java:861)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.SqlStmtEof(SqlParserImpl.java:877)
> at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.parseSqlStmtEof(SqlParserImpl.java:199)
> at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:148)
> ... 1 more
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Comment Edited] (CALCITE-2999) Can't get the right column value in LogicalSort

2019-04-15 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2999?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16817844#comment-16817844
 ] 

yuqi edited comment on CALCITE-2999 at 4/15/19 10:23 AM:
-

[~zhztheplayer] amzaing, RelRoot output Type is correct and the output value of 
LogicalSort is wrong, indeed, the the value of root.rel is LogicalSort, see 
picture below.
 !picture4.png! 

I have not execute it on my data as i just want to analyze the structure of 
logicalSort and make codegen according to the result from analysis, but run 
into this problem.

On this issue, do you have any suggestions, if i want to get the output type of 
logicalsort and the corresponding mapping relation to the input? thanks a lot 


was (Author: yuqi):
[~zhztheplayer] amzaing, RelRoot output Type is correct and the output value of 
LogicalSort is wrong, indeed, the the value of root.rel is LogicalSort, see 
picture below.
 !picture4.png! 

I have not execute it on my data as i just want to analyze the structure of 
logicalSort and make codegen according to the result from analysis, but run 
into this problem.

On this issue, do you have any suggestions ? thanks a lot

> Can't get the right column value in LogicalSort
> ---
>
> Key: CALCITE-2999
> URL: https://issues.apache.org/jira/browse/CALCITE-2999
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.19.0
>Reporter: yuqi
>Assignee: Danny Chan
>Priority: Critical
> Attachments: picture2.png, picture4.png, problem.png, problem.png
>
>
> Let's consider the sql:
> {code:sql}
> // Some comments here
> select 'hello', tag from b where text = '2' or text = '1' order by cast(text 
> as int) + 1 asc , tag desc limit 1"
> {code}
> And the Plan can be seen in the picture below
> We can't get the right column value of LogicalSort if sort condition is not 
> the select column list
> Can anyone help to explain this problem if i'm wrong



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-2999) Can't get the right column value in LogicalSort

2019-04-15 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2999?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16817844#comment-16817844
 ] 

yuqi commented on CALCITE-2999:
---

[~zhztheplayer] amzaing, RelRoot output Type is correct and the output value of 
LogicalSort is wrong, indeed, the the value of root.rel is LogicalSort, see 
picture below.
 !picture4.png! 

I have not execute it on my data as i just want to analyze the structure of 
logicalSort and make codegen according to the result from analysis, but run 
into this problem.

On this issue, do you have any suggestions ? thanks a lot

> Can't get the right column value in LogicalSort
> ---
>
> Key: CALCITE-2999
> URL: https://issues.apache.org/jira/browse/CALCITE-2999
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.19.0
>Reporter: yuqi
>Assignee: Danny Chan
>Priority: Critical
> Attachments: picture2.png, picture4.png, problem.png, problem.png
>
>
> Let's consider the sql:
> {code:sql}
> // Some comments here
> select 'hello', tag from b where text = '2' or text = '1' order by cast(text 
> as int) + 1 asc , tag desc limit 1"
> {code}
> And the Plan can be seen in the picture below
> We can't get the right column value of LogicalSort if sort condition is not 
> the select column list
> Can anyone help to explain this problem if i'm wrong



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Updated] (CALCITE-2999) Can't get the right column value in LogicalSort

2019-04-15 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2999?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2999:
--
Attachment: picture4.png

> Can't get the right column value in LogicalSort
> ---
>
> Key: CALCITE-2999
> URL: https://issues.apache.org/jira/browse/CALCITE-2999
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.19.0
>Reporter: yuqi
>Assignee: Danny Chan
>Priority: Critical
> Attachments: picture2.png, picture4.png, problem.png, problem.png
>
>
> Let's consider the sql:
> {code:sql}
> // Some comments here
> select 'hello', tag from b where text = '2' or text = '1' order by cast(text 
> as int) + 1 asc , tag desc limit 1"
> {code}
> And the Plan can be seen in the picture below
> We can't get the right column value of LogicalSort if sort condition is not 
> the select column list
> Can anyone help to explain this problem if i'm wrong



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Comment Edited] (CALCITE-2999) Can't get the right column value in LogicalSort

2019-04-15 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2999?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16817677#comment-16817677
 ] 

yuqi edited comment on CALCITE-2999 at 4/15/19 9:18 AM:


[~danny0405] I do agree with you on this point, there seems a bug on the output 
column where sorting key is not in the project list, for now, we should try to 
confirm whether this is really a bug and then try to fix it


was (Author: yuqi):
[~zhztheplayer], I do agree with you on this point, there seems a bug on the 
output column where sorting key is not in the project list, for now, we should 
try to confirm whether this is really a bug and then try to fix it

> Can't get the right column value in LogicalSort
> ---
>
> Key: CALCITE-2999
> URL: https://issues.apache.org/jira/browse/CALCITE-2999
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.19.0
>Reporter: yuqi
>Assignee: Danny Chan
>Priority: Critical
> Attachments: picture2.png, problem.png, problem.png
>
>
> Let's consider the sql:
> {code:sql}
> // Some comments here
> select 'hello', tag from b where text = '2' or text = '1' order by cast(text 
> as int) + 1 asc , tag desc limit 1"
> {code}
> And the Plan can be seen in the picture below
> We can't get the right column value of LogicalSort if sort condition is not 
> the select column list
> Can anyone help to explain this problem if i'm wrong



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Updated] (CALCITE-2999) Can't get the right column value in LogicalSort

2019-04-15 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2999?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2999:
--
Attachment: picture2.png

> Can't get the right column value in LogicalSort
> ---
>
> Key: CALCITE-2999
> URL: https://issues.apache.org/jira/browse/CALCITE-2999
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.19.0
>Reporter: yuqi
>Assignee: Danny Chan
>Priority: Critical
> Attachments: picture2.png, problem.png, problem.png
>
>
> Let's consider the sql:
> {code:sql}
> // Some comments here
> select 'hello', tag from b where text = '2' or text = '1' order by cast(text 
> as int) + 1 asc , tag desc limit 1"
> {code}
> And the Plan can be seen in the picture below
> We can't get the right column value of LogicalSort if sort condition is not 
> the select column list
> Can anyone help to explain this problem if i'm wrong



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-2999) Can't get the right column value in LogicalSort

2019-04-15 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2999?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16817677#comment-16817677
 ] 

yuqi commented on CALCITE-2999:
---

[~zhztheplayer], I do agree with you on this point, there seems a bug on the 
output column where sorting key is not in the project list, for now, we should 
try to confirm whether this is really a bug and then try to fix it

> Can't get the right column value in LogicalSort
> ---
>
> Key: CALCITE-2999
> URL: https://issues.apache.org/jira/browse/CALCITE-2999
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.19.0
>Reporter: yuqi
>Assignee: Danny Chan
>Priority: Critical
> Attachments: picture2.png, problem.png, problem.png
>
>
> Let's consider the sql:
> {code:sql}
> // Some comments here
> select 'hello', tag from b where text = '2' or text = '1' order by cast(text 
> as int) + 1 asc , tag desc limit 1"
> {code}
> And the Plan can be seen in the picture below
> We can't get the right column value of LogicalSort if sort condition is not 
> the select column list
> Can anyone help to explain this problem if i'm wrong



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-2999) Can't get the right column value in LogicalSort

2019-04-15 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2999?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16817675#comment-16817675
 ] 

yuqi commented on CALCITE-2999:
---

[~zhztheplayer] Thanks for your attention, see the picture below
 !picture2.png! 

> Can't get the right column value in LogicalSort
> ---
>
> Key: CALCITE-2999
> URL: https://issues.apache.org/jira/browse/CALCITE-2999
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.19.0
>Reporter: yuqi
>Assignee: Danny Chan
>Priority: Critical
> Attachments: problem.png, problem.png
>
>
> Let's consider the sql:
> {code:sql}
> // Some comments here
> select 'hello', tag from b where text = '2' or text = '1' order by cast(text 
> as int) + 1 asc , tag desc limit 1"
> {code}
> And the Plan can be seen in the picture below
> We can't get the right column value of LogicalSort if sort condition is not 
> the select column list
> Can anyone help to explain this problem if i'm wrong



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Issue Comment Deleted] (CALCITE-2999) Can't get the right column value in LogicalSort

2019-04-15 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2999?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2999:
--
Comment: was deleted

(was: [~zhztheplayer] Thanks for you attention 
My problems are in the picture below
 !problem.png! )

> Can't get the right column value in LogicalSort
> ---
>
> Key: CALCITE-2999
> URL: https://issues.apache.org/jira/browse/CALCITE-2999
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.19.0
>Reporter: yuqi
>Assignee: Danny Chan
>Priority: Critical
> Attachments: problem.png, problem.png
>
>
> Let's consider the sql:
> {code:sql}
> // Some comments here
> select 'hello', tag from b where text = '2' or text = '1' order by cast(text 
> as int) + 1 asc , tag desc limit 1"
> {code}
> And the Plan can be seen in the picture below
> We can't get the right column value of LogicalSort if sort condition is not 
> the select column list
> Can anyone help to explain this problem if i'm wrong



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-2999) Can't get the right column value in LogicalSort

2019-04-15 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2999?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16817673#comment-16817673
 ] 

yuqi commented on CALCITE-2999:
---

[~zhztheplayer] Thanks for you attention 
My problems are in the picture below
 !problem.png! 

> Can't get the right column value in LogicalSort
> ---
>
> Key: CALCITE-2999
> URL: https://issues.apache.org/jira/browse/CALCITE-2999
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.19.0
>Reporter: yuqi
>Assignee: Danny Chan
>Priority: Critical
> Attachments: problem.png, problem.png
>
>
> Let's consider the sql:
> {code:sql}
> // Some comments here
> select 'hello', tag from b where text = '2' or text = '1' order by cast(text 
> as int) + 1 asc , tag desc limit 1"
> {code}
> And the Plan can be seen in the picture below
> We can't get the right column value of LogicalSort if sort condition is not 
> the select column list
> Can anyone help to explain this problem if i'm wrong



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Updated] (CALCITE-2999) Can't get the right column value in LogicalSort

2019-04-15 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2999?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2999:
--
Attachment: problem.png

> Can't get the right column value in LogicalSort
> ---
>
> Key: CALCITE-2999
> URL: https://issues.apache.org/jira/browse/CALCITE-2999
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.19.0
>Reporter: yuqi
>Assignee: Danny Chan
>Priority: Critical
> Attachments: problem.png, problem.png
>
>
> Let's consider the sql:
> {code:sql}
> // Some comments here
> select 'hello', tag from b where text = '2' or text = '1' order by cast(text 
> as int) + 1 asc , tag desc limit 1"
> {code}
> And the Plan can be seen in the picture below
> We can't get the right column value of LogicalSort if sort condition is not 
> the select column list
> Can anyone help to explain this problem if i'm wrong



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Updated] (CALCITE-2999) Can't get the right column value in LogicalSort

2019-04-15 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2999?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2999:
--
Description: 
Let's consider the sql:

{code:sql}
// Some comments here
select 'hello', tag from b where text = '2' or text = '1' order by cast(text as 
int) + 1 asc , tag desc limit 1"
{code}

And the Plan can be seen in the picture below

We can't get the right column value of LogicalSort if sort condition is not the 
select column list
Can anyone help to explain this problem if i'm wrong

  was:
Let's consider the sql:

{code:sql}
// Some comments here
select 'hello', tag from b where text = '2' or text = '1' order by cast(text as 
int) + 1 asc , tag desc limit 1"
{code}

And the Plan is as follows
 !image-2019-04-15-16-22-24-105.png! 

We can't get the right column value of LogicalSort if sort condition is not the 
select column list


> Can't get the right column value in LogicalSort
> ---
>
> Key: CALCITE-2999
> URL: https://issues.apache.org/jira/browse/CALCITE-2999
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.19.0
>Reporter: yuqi
>Priority: Critical
> Attachments: problem.png
>
>
> Let's consider the sql:
> {code:sql}
> // Some comments here
> select 'hello', tag from b where text = '2' or text = '1' order by cast(text 
> as int) + 1 asc , tag desc limit 1"
> {code}
> And the Plan can be seen in the picture below
> We can't get the right column value of LogicalSort if sort condition is not 
> the select column list
> Can anyone help to explain this problem if i'm wrong



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Updated] (CALCITE-2999) Can't get the right column value in LogicalSort

2019-04-15 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2999?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2999:
--
Attachment: problem.png

> Can't get the right column value in LogicalSort
> ---
>
> Key: CALCITE-2999
> URL: https://issues.apache.org/jira/browse/CALCITE-2999
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.19.0
>Reporter: yuqi
>Priority: Critical
> Attachments: problem.png
>
>
> Let's consider the sql:
> {code:sql}
> // Some comments here
> select 'hello', tag from b where text = '2' or text = '1' order by cast(text 
> as int) + 1 asc , tag desc limit 1"
> {code}
> And the Plan is as follows
>  !image-2019-04-15-16-22-24-105.png! 
> We can't get the right column value of LogicalSort if sort condition is not 
> the select column list



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Created] (CALCITE-2999) Can't get the right column value in LogicalSort

2019-04-15 Thread yuqi (JIRA)
yuqi created CALCITE-2999:
-

 Summary: Can't get the right column value in LogicalSort
 Key: CALCITE-2999
 URL: https://issues.apache.org/jira/browse/CALCITE-2999
 Project: Calcite
  Issue Type: Bug
  Components: core
Affects Versions: 1.19.0
Reporter: yuqi


Let's consider the sql:

{code:sql}
// Some comments here
select 'hello', tag from b where text = '2' or text = '1' order by cast(text as 
int) + 1 asc , tag desc limit 1"
{code}

And the Plan is as follows
 !image-2019-04-15-16-22-24-105.png! 

We can't get the right column value of LogicalSort if sort condition is not the 
select column list



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-2861) Exception occurs when do arithmetic between decimal and other numeric types

2019-03-27 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2861?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16802716#comment-16802716
 ] 

yuqi commented on CALCITE-2861:
---

[~zhztheplayer] Thanks for your carefully review, When I add the decimal type 
in `CatchallSchema`, the existing test `ReflectiveSchemaTest#testOp` could 
cover the corresponding changes, anyhow, you are right, i will add a 
independent test case for this problem.

> Exception occurs when do arithmetic between decimal and other numeric types
> ---
>
> Key: CALCITE-2861
> URL: https://issues.apache.org/jira/browse/CALCITE-2861
> Project: Calcite
>  Issue Type: Improvement
>  Components: core
>Reporter: yuqi
>Priority: Major
>  Labels: pull-request-available
>  Time Spent: 10m
>  Remaining Estimate: 0h
>
> 1. add decimal type in ReflectiveSchemaTest#EveryType
> 
> {code:java}
>  public static class EveryType {
>...
> public final String string;
> public final BigDecimal decimal;
> public EveryType(
> ...
> String string,
> BigDecimal decimal) {
>...
>   this.string = string;
>   this.decimal = decimal;
> }
> {code}
> 2. Reconstruct ReflectiveSchemaTest#CatchallSchema#everyTypes with the new 
> constructor, for example you can't assign the decimal field 1.2.
> 3. Run ReflectiveSchemaTest#testOp() 
> 4. Exceptions are as followings
>   
> {code:java}
> java.lang.AssertionError
>   at 
> org.apache.calcite.sql.type.ReturnTypes.lambda$static$6(ReturnTypes.java:510)
>   at 
> org.apache.calcite.sql.type.SqlTypeTransformCascade.inferReturnType(SqlTypeTransformCascade.java:54)
>   at 
> org.apache.calcite.sql.type.SqlReturnTypeInferenceChain.inferReturnType(SqlReturnTypeInferenceChain.java:56)
>   at 
> org.apache.calcite.sql.SqlOperator.inferReturnType(SqlOperator.java:470)
>   at 
> org.apache.calcite.sql.SqlOperator.validateOperands(SqlOperator.java:437)
>   at org.apache.calcite.sql.SqlOperator.deriveType(SqlOperator.java:515)
>   at 
> org.apache.calcite.sql.SqlBinaryOperator.deriveType(SqlBinaryOperator.java:144)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5547)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5534)
>   at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1639)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1624)
>   at 
> org.apache.calcite.sql.SqlAsOperator.deriveType(SqlAsOperator.java:133)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5547)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5534)
>   at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1639)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1624)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.expandSelectItem(SqlValidatorImpl.java:461)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelectList(SqlValidatorImpl.java:4052)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3315)
>   at 
> org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60)
>   at 
> org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:977)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:953)
>   at org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:216)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:928)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:632)
>   at 
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:556)
>   at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:265)
>   at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:231)
>   at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:772)
>   at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:636)
>   at 
> 

[jira] [Updated] (CALCITE-2861) Exception occurs when do arithmetic between decimal and other numeric types

2019-03-27 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2861?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2861:
--
Summary: Exception occurs when do arithmetic between decimal and other 
numeric types  (was: Exception occurs when do  +-*/ between decimal and other 
numeric types)

> Exception occurs when do arithmetic between decimal and other numeric types
> ---
>
> Key: CALCITE-2861
> URL: https://issues.apache.org/jira/browse/CALCITE-2861
> Project: Calcite
>  Issue Type: Improvement
>  Components: core
>Reporter: yuqi
>Priority: Major
>  Labels: pull-request-available
>  Time Spent: 10m
>  Remaining Estimate: 0h
>
> 1. add decimal type in ReflectiveSchemaTest#EveryType
> 
> {code:java}
>  public static class EveryType {
>...
> public final String string;
> public final BigDecimal decimal;
> public EveryType(
> ...
> String string,
> BigDecimal decimal) {
>...
>   this.string = string;
>   this.decimal = decimal;
> }
> {code}
> 2. Reconstruct ReflectiveSchemaTest#CatchallSchema#everyTypes with the new 
> constructor, for example you can't assign the decimal field 1.2.
> 3. Run ReflectiveSchemaTest#testOp() 
> 4. Exceptions are as followings
>   
> {code:java}
> java.lang.AssertionError
>   at 
> org.apache.calcite.sql.type.ReturnTypes.lambda$static$6(ReturnTypes.java:510)
>   at 
> org.apache.calcite.sql.type.SqlTypeTransformCascade.inferReturnType(SqlTypeTransformCascade.java:54)
>   at 
> org.apache.calcite.sql.type.SqlReturnTypeInferenceChain.inferReturnType(SqlReturnTypeInferenceChain.java:56)
>   at 
> org.apache.calcite.sql.SqlOperator.inferReturnType(SqlOperator.java:470)
>   at 
> org.apache.calcite.sql.SqlOperator.validateOperands(SqlOperator.java:437)
>   at org.apache.calcite.sql.SqlOperator.deriveType(SqlOperator.java:515)
>   at 
> org.apache.calcite.sql.SqlBinaryOperator.deriveType(SqlBinaryOperator.java:144)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5547)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5534)
>   at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1639)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1624)
>   at 
> org.apache.calcite.sql.SqlAsOperator.deriveType(SqlAsOperator.java:133)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5547)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5534)
>   at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1639)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1624)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.expandSelectItem(SqlValidatorImpl.java:461)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelectList(SqlValidatorImpl.java:4052)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3315)
>   at 
> org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60)
>   at 
> org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:977)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:953)
>   at org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:216)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:928)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:632)
>   at 
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:556)
>   at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:265)
>   at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:231)
>   at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:772)
>   at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:636)
>   at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:606)
>   at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:229)
>   at 
> 

[jira] [Created] (CALCITE-2879) Improve filter condition in Join

2019-02-27 Thread yuqi (JIRA)
yuqi created CALCITE-2879:
-

 Summary: Improve filter condition in Join
 Key: CALCITE-2879
 URL: https://issues.apache.org/jira/browse/CALCITE-2879
 Project: Calcite
  Issue Type: Improvement
Reporter: yuqi


Currently, filter condition in join have not been optimized very well, let's 
take a simple example


{code:sql}
select a.id, b.name from Ta a inner join Tb b on a.id = b.id and a.id < 5;

{code}

now, only a.id < 5 can push down, however, as for the sql above,  
we can infer a.id < 5 and b.id < 5 and both of them can push down. 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Updated] (CALCITE-2861) Exception occurs when do +-*/ between decimal and other numeric types

2019-02-22 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2861?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2861:
--
Description: 
1. add decimal type in ReflectiveSchemaTest#EveryType

{code:java}
 public static class EveryType {
   ...
public final String string;
public final BigDecimal decimal;

public EveryType(
...
String string,
BigDecimal decimal) {
   ...
  this.string = string;
  this.decimal = decimal;
}
{code}

2. Reconstruct ReflectiveSchemaTest#CatchallSchema#everyTypes with the new 
constructor, for example you can't assign the decimal field 1.2.

3. Run ReflectiveSchemaTest#testOp() 
4. Exceptions are as followings
  
{code:java}
java.lang.AssertionError
at 
org.apache.calcite.sql.type.ReturnTypes.lambda$static$6(ReturnTypes.java:510)
at 
org.apache.calcite.sql.type.SqlTypeTransformCascade.inferReturnType(SqlTypeTransformCascade.java:54)
at 
org.apache.calcite.sql.type.SqlReturnTypeInferenceChain.inferReturnType(SqlReturnTypeInferenceChain.java:56)
at 
org.apache.calcite.sql.SqlOperator.inferReturnType(SqlOperator.java:470)
at 
org.apache.calcite.sql.SqlOperator.validateOperands(SqlOperator.java:437)
at org.apache.calcite.sql.SqlOperator.deriveType(SqlOperator.java:515)
at 
org.apache.calcite.sql.SqlBinaryOperator.deriveType(SqlBinaryOperator.java:144)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5547)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5534)
at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1639)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1624)
at 
org.apache.calcite.sql.SqlAsOperator.deriveType(SqlAsOperator.java:133)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5547)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5534)
at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1639)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1624)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.expandSelectItem(SqlValidatorImpl.java:461)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelectList(SqlValidatorImpl.java:4052)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3315)
at 
org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60)
at 
org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:977)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:953)
at org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:216)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:928)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:632)
at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:556)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:265)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:231)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:772)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:636)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:606)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:229)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:550)
at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
at 
org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:227)
at 
org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:541)
at 
org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1450)
at 
org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1426)
at 
org.apache.calcite.test.ReflectiveSchemaTest.checkOp(ReflectiveSchemaTest.java:653)
at 

[jira] [Updated] (CALCITE-2861) Exception occurs when do +-*/ between decimal and other numeric types

2019-02-22 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2861?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2861:
--
Description: 
1. add decimal type in ReflectiveSchemaTest#EveryType

{code:java}
 public static class EveryType {
   ...
public final String string;
public final BigDecimal decimal;

public EveryType(
...
String string,
BigDecimal decimal) {
   ...
  this.string = string;
  this.decimal = decimal;
}
{code}

2. Reconstruct ReflectiveSchemaTest#CatchallSchema#everyTypes with the new 
constructor, for example you can't assign the decimal field 1.2.

3. Run ReflectiveSchemaTest#testOp() 
4. Exceptions are as followings
  
{code:java}
java.lang.AssertionError
at 
org.apache.calcite.sql.type.ReturnTypes.lambda$static$6(ReturnTypes.java:510)
at 
org.apache.calcite.sql.type.SqlTypeTransformCascade.inferReturnType(SqlTypeTransformCascade.java:54)
at 
org.apache.calcite.sql.type.SqlReturnTypeInferenceChain.inferReturnType(SqlReturnTypeInferenceChain.java:56)
at 
org.apache.calcite.sql.SqlOperator.inferReturnType(SqlOperator.java:470)
at 
org.apache.calcite.sql.SqlOperator.validateOperands(SqlOperator.java:437)
at org.apache.calcite.sql.SqlOperator.deriveType(SqlOperator.java:515)
at 
org.apache.calcite.sql.SqlBinaryOperator.deriveType(SqlBinaryOperator.java:144)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5547)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5534)
at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1639)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1624)
at 
org.apache.calcite.sql.SqlAsOperator.deriveType(SqlAsOperator.java:133)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5547)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5534)
at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1639)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1624)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.expandSelectItem(SqlValidatorImpl.java:461)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelectList(SqlValidatorImpl.java:4052)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3315)
at 
org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60)
at 
org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:977)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:953)
at org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:216)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:928)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:632)
at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:556)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:265)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:231)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:772)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:636)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:606)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:229)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:550)
at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
at 
org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:227)
at 
org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:541)
at 
org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1450)
at 
org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1426)
at 
org.apache.calcite.test.ReflectiveSchemaTest.checkOp(ReflectiveSchemaTest.java:653)
at 

[jira] [Updated] (CALCITE-2861) Exception occurs when do +-*/ between decimal and other numeric types

2019-02-22 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2861?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2861:
--
Description: 
1. add decimal type in ReflectiveSchemaTest.EveryType


{code:java}
 public static class EveryType {
   ...
public final String string;
public final BigDecimal decimal;

public EveryType(
...
String string,
BigDecimal decimal) {
   ...
  this.string = string;
  this.decimal = decimal;
}
{code}

2. run ReflectiveSchemaTest#testOp() 
3. Exceptions are as followings
  
{code:java}
java.lang.AssertionError
at 
org.apache.calcite.sql.type.ReturnTypes.lambda$static$6(ReturnTypes.java:510)
at 
org.apache.calcite.sql.type.SqlTypeTransformCascade.inferReturnType(SqlTypeTransformCascade.java:54)
at 
org.apache.calcite.sql.type.SqlReturnTypeInferenceChain.inferReturnType(SqlReturnTypeInferenceChain.java:56)
at 
org.apache.calcite.sql.SqlOperator.inferReturnType(SqlOperator.java:470)
at 
org.apache.calcite.sql.SqlOperator.validateOperands(SqlOperator.java:437)
at org.apache.calcite.sql.SqlOperator.deriveType(SqlOperator.java:515)
at 
org.apache.calcite.sql.SqlBinaryOperator.deriveType(SqlBinaryOperator.java:144)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5547)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5534)
at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1639)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1624)
at 
org.apache.calcite.sql.SqlAsOperator.deriveType(SqlAsOperator.java:133)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5547)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5534)
at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1639)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1624)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.expandSelectItem(SqlValidatorImpl.java:461)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelectList(SqlValidatorImpl.java:4052)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3315)
at 
org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60)
at 
org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:977)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:953)
at org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:216)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:928)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:632)
at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:556)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:265)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:231)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:772)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:636)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:606)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:229)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:550)
at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
at 
org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:227)
at 
org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:541)
at 
org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1450)
at 
org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1426)
at 
org.apache.calcite.test.ReflectiveSchemaTest.checkOp(ReflectiveSchemaTest.java:653)
at 
org.apache.calcite.test.ReflectiveSchemaTest.testOp(ReflectiveSchemaTest.java:632)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  

[jira] [Created] (CALCITE-2861) Exception occurs when do +-*/ between decimal and other numeric types

2019-02-22 Thread yuqi (JIRA)
yuqi created CALCITE-2861:
-

 Summary: Exception occurs when do  +-*/ between decimal and other 
numeric types
 Key: CALCITE-2861
 URL: https://issues.apache.org/jira/browse/CALCITE-2861
 Project: Calcite
  Issue Type: Improvement
  Components: core
Reporter: yuqi


1. add decimal type in ReflectiveSchemaTest.EveryType


{code:java}
 public static class EveryType {
   ...
public final String string;
public final BigDecimal decimal;

public EveryType(
...
String string,
BigDecimal decimal) {
   ...
  this.string = string;
  this.decimal = decimal;
}

2. run  testOp() 
3. Exceptions are as followings
  

{code:java}
java.lang.AssertionError
at 
org.apache.calcite.sql.type.ReturnTypes.lambda$static$6(ReturnTypes.java:510)
at 
org.apache.calcite.sql.type.SqlTypeTransformCascade.inferReturnType(SqlTypeTransformCascade.java:54)
at 
org.apache.calcite.sql.type.SqlReturnTypeInferenceChain.inferReturnType(SqlReturnTypeInferenceChain.java:56)
at 
org.apache.calcite.sql.SqlOperator.inferReturnType(SqlOperator.java:470)
at 
org.apache.calcite.sql.SqlOperator.validateOperands(SqlOperator.java:437)
at org.apache.calcite.sql.SqlOperator.deriveType(SqlOperator.java:515)
at 
org.apache.calcite.sql.SqlBinaryOperator.deriveType(SqlBinaryOperator.java:144)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5547)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5534)
at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1639)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1624)
at 
org.apache.calcite.sql.SqlAsOperator.deriveType(SqlAsOperator.java:133)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5547)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5534)
at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1639)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1624)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.expandSelectItem(SqlValidatorImpl.java:461)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelectList(SqlValidatorImpl.java:4052)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3315)
at 
org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60)
at 
org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:977)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:953)
at org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:216)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:928)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:632)
at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:556)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:265)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:231)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:772)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:636)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:606)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:229)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:550)
at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
at 
org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:227)
at 
org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:541)
at 
org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1450)
at 
org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1426)
at 
org.apache.calcite.test.ReflectiveSchemaTest.checkOp(ReflectiveSchemaTest.java:653)
at 

[jira] [Commented] (CALCITE-2841) Simplification: push negation into Case expression

2019-02-12 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2841?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16765989#comment-16765989
 ] 

yuqi commented on CALCITE-2841:
---

Is there any detail about this issue ?

> Simplification: push negation into Case expression
> --
>
> Key: CALCITE-2841
> URL: https://issues.apache.org/jira/browse/CALCITE-2841
> Project: Calcite
>  Issue Type: Improvement
>Reporter: Zoltan Haindrich
>Assignee: Julian Hyde
>Priority: Major
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-2637) Prefix minus operator failed in between and clause

2018-12-01 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2637?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16706060#comment-16706060
 ] 

yuqi commented on CALCITE-2637:
---

Fixed

> Prefix minus operator failed in between and clause
> --
>
> Key: CALCITE-2637
> URL: https://issues.apache.org/jira/browse/CALCITE-2637
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.17.0
>Reporter: yuqi
>Assignee: Julian Hyde
>Priority: Major
> Fix For: 1.18.0
>
>
> We can reproduce it like this 
> {code:java}
> public static void main(String[] args) {
>   try {
>   SchemaPlus rootSchema = 
> Frameworks.createRootSchema(true);
>   rootSchema.add("TABLE_RESULT", new AbstractTable() {
>   public RelDataType getRowType(final 
> RelDataTypeFactory typeFactory) {
>   RelDataTypeFactory.FieldInfoBuilder 
> builder = typeFactory.builder();
>   RelDataType t1 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
>  true);
>   RelDataType t2 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.CHAR),
>  true);
>   RelDataType t3 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
>  true);
>   builder.add("ID", t1);
>   builder.add("NAME", t2);
>   builder.add("SCORE", t3);;
>   return builder.build();
>   }
>   });
>   final FrameworkConfig config = 
> Frameworks.newConfigBuilder()
>   .parserConfig(SqlParser.Config.DEFAULT)
>   .defaultSchema(rootSchema)
>   .build();
>   Planner planner = Frameworks.getPlanner(config);
>   String sql = "select id, score between - score * 5 and 
> 100 from table_result";
>   SqlNode parse = planner.parse(sql);
>   SqlNode validate = planner.validate(parse);
>   RelRoot root = planner.rel(validate);
>   } catch (Exception e) {
>   e.printStackTrace();
>   }
>   }
> {code}
> the above code will cause the following problem:
> {code:java}
> org.apache.calcite.sql.parser.SqlParseException: Encountered "- score" at 
> line 1, column 26.
> Was expecting one of:
> "SYMMETRIC" ...
> "ASYMMETRIC" ...
> "+" ...
> "-" ...
> "-"  ...
> "-"  ...
> "-"  ...
>  ...
>  ...
>  ...
>  ...
>  ...
>  ...
>  ...
> "TRUE" ...
> "FALSE" ...
> "UNKNOWN" ...
> "NULL" ...
>  ...
>  ...
>  ...
> "DATE" ...
> "TIME" ...
> "TIMESTAMP" ...
> "INTERVAL" ...
> "?" ...
> "CAST" ...
> "EXTRACT" ...
> "POSITION" ...
> "CONVERT" ...
> "TRANSLATE" ...
> "OVERLAY" ...
> "FLOOR" ...
> "CEIL" ...
> "CEILING" ...
> "SUBSTRING" ...
> "TRIM" ...
> "CLASSIFIER" ...
> "MATCH_NUMBER" ...
> "RUNNING" ...
> "PREV" ...
> "NEXT" ...
>  ...
> "MULTISET" ...
> "ARRAY" ...
> "PERIOD" ...
> "SPECIFIC" ...
>  ...
>  ...
>  ...
>  ...
>  ...
> "ABS" ...
> "AVG" ...
> "CARDINALITY" ...
> "CHAR_LENGTH" ...
> "CHARACTER_LENGTH" ...
> "COALESCE" ...
> "COLLECT" ...
> "COVAR_POP" ...
> "COVAR_SAMP" ...
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-2659) Wrong plan In natural left/right join

2018-11-09 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2659?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16681553#comment-16681553
 ] 

yuqi commented on CALCITE-2659:
---

[~julianhyde], i could not understand your answer 'The plan produces the 
correct result' clearly. The function COALESCE do omit the left attribute. if 
left value is null and right is not null, COALESCE will return a value that is 
not null. I will appreciate it if you can explain it in detail, thanks


> Wrong plan In natural left/right  join
> --
>
> Key: CALCITE-2659
> URL: https://issues.apache.org/jira/browse/CALCITE-2659
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.17.0
>Reporter: yuqi
>Assignee: Julian Hyde
>Priority: Major
>
> The following is the code:
> {code:java}
> public static void main(String[] args) {
>   try {
>   SchemaPlus rootSchema = 
> Frameworks.createRootSchema(true);
>   rootSchema.add("TABLE_RESULT", new AbstractTable() {
>   public RelDataType getRowType(final 
> RelDataTypeFactory typeFactory) {
>   RelDataTypeFactory.FieldInfoBuilder 
> builder = typeFactory.builder();
>   RelDataType t0 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
>  true);
>   RelDataType t1 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TINYINT),
>  true);
>   RelDataType t2 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.SMALLINT),
>  true);
>   RelDataType t3 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
>  true);
>   RelDataType t4 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.FLOAT),
>  true);
>   RelDataType t5 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DOUBLE),
>  true);
>   RelDataType t6 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
>  true);
>   RelDataType t7 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BOOLEAN),
>  true);
>   RelDataType t8 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DATE),
>  true);
>   RelDataType t9 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIME),
>  true);
>   RelDataType t10 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIMESTAMP),
>  true);
>   RelDataType t11 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.VARCHAR),
>  true);
>   builder.add("ID", t0);
>   builder.add("byte_test".toUpperCase(), 
> t1);
>   builder.add("short_test".toUpperCase(), 
> t2);
>   builder.add("int_test".toUpperCase(), 
> t3);
>   builder.add("float_test".toUpperCase(), 
> t4);
>   
> builder.add("double_test".toUpperCase(), t5);
>   builder.add("long_test".toUpperCase(), 
> t6);
>   
> builder.add("boolean_test".toUpperCase(), t7);
>   builder.add("date_test".toUpperCase(), 
> t8);
>   builder.add("time_test".toUpperCase(), 
> t9);
>   
> builder.add("timestamp_test".toUpperCase(), t10);
>   
> builder.add("string_test".toUpperCase(), t11);
>   return builder.build();
>   }
>   });
>   rootSchema.add("TABLE_RESULT_COPY", new AbstractTable() 
> {
>   public RelDataType getRowType(final 
> RelDataTypeFactory typeFactory) {
>   RelDataTypeFactory.FieldInfoBuilder 
> builder = typeFactory.builder();
>   RelDataType t0 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
>  true);
>   RelDataType t1 = 
> 

[jira] [Updated] (CALCITE-2659) Wrong plan In natural left/right join

2018-11-07 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2659?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2659:
--
Description: 
The following is the code:


{code:java}
public static void main(String[] args) {
try {
SchemaPlus rootSchema = 
Frameworks.createRootSchema(true);

rootSchema.add("TABLE_RESULT", new AbstractTable() {
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();

RelDataType t0 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t1 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TINYINT),
 true);
RelDataType t2 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.SMALLINT),
 true);
RelDataType t3 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);
RelDataType t4 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.FLOAT),
 true);
RelDataType t5 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DOUBLE),
 true);
RelDataType t6 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t7 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BOOLEAN),
 true);
RelDataType t8 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DATE),
 true);
RelDataType t9 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIME),
 true);
RelDataType t10 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIMESTAMP),
 true);
RelDataType t11 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.VARCHAR),
 true);


builder.add("ID", t0);
builder.add("byte_test".toUpperCase(), 
t1);
builder.add("short_test".toUpperCase(), 
t2);
builder.add("int_test".toUpperCase(), 
t3);
builder.add("float_test".toUpperCase(), 
t4);

builder.add("double_test".toUpperCase(), t5);
builder.add("long_test".toUpperCase(), 
t6);

builder.add("boolean_test".toUpperCase(), t7);
builder.add("date_test".toUpperCase(), 
t8);
builder.add("time_test".toUpperCase(), 
t9);

builder.add("timestamp_test".toUpperCase(), t10);

builder.add("string_test".toUpperCase(), t11);

return builder.build();
}
});


rootSchema.add("TABLE_RESULT_COPY", new AbstractTable() 
{
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();

RelDataType t0 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t1 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TINYINT),
 true);
RelDataType t2 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.SMALLINT),
 true);
RelDataType t3 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);
RelDataType t4 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.FLOAT),
 true);
RelDataType t5 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DOUBLE),
 true);
RelDataType t6 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 

[jira] [Updated] (CALCITE-2659) Wrong plan In natural left/right join

2018-11-07 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2659?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2659:
--
Description: 
The following is the code:


{code:java}
public static void main(String[] args) {
try {
SchemaPlus rootSchema = 
Frameworks.createRootSchema(true);

rootSchema.add("TABLE_RESULT", new AbstractTable() {
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();

RelDataType t0 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t1 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TINYINT),
 true);
RelDataType t2 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.SMALLINT),
 true);
RelDataType t3 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);
RelDataType t4 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.FLOAT),
 true);
RelDataType t5 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DOUBLE),
 true);
RelDataType t6 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t7 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BOOLEAN),
 true);
RelDataType t8 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DATE),
 true);
RelDataType t9 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIME),
 true);
RelDataType t10 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIMESTAMP),
 true);
RelDataType t11 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.VARCHAR),
 true);


builder.add("ID", t0);
builder.add("byte_test".toUpperCase(), 
t1);
builder.add("short_test".toUpperCase(), 
t2);
builder.add("int_test".toUpperCase(), 
t3);
builder.add("float_test".toUpperCase(), 
t4);

builder.add("double_test".toUpperCase(), t5);
builder.add("long_test".toUpperCase(), 
t6);

builder.add("boolean_test".toUpperCase(), t7);
builder.add("date_test".toUpperCase(), 
t8);
builder.add("time_test".toUpperCase(), 
t9);

builder.add("timestamp_test".toUpperCase(), t10);

builder.add("string_test".toUpperCase(), t11);

return builder.build();
}
});


rootSchema.add("TABLE_RESULT_COPY", new AbstractTable() 
{
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();

RelDataType t0 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t1 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TINYINT),
 true);
RelDataType t2 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.SMALLINT),
 true);
RelDataType t3 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);
RelDataType t4 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.FLOAT),
 true);
RelDataType t5 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DOUBLE),
 true);
RelDataType t6 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 

[jira] [Updated] (CALCITE-2659) Wrong plan In natural left/right join

2018-11-07 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2659?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2659:
--
Description: 
The following is the code:


{code:java}
public static void main(String[] args) {
try {
SchemaPlus rootSchema = 
Frameworks.createRootSchema(true);

rootSchema.add("TABLE_RESULT", new AbstractTable() {
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();

RelDataType t0 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t1 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TINYINT),
 true);
RelDataType t2 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.SMALLINT),
 true);
RelDataType t3 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);
RelDataType t4 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.FLOAT),
 true);
RelDataType t5 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DOUBLE),
 true);
RelDataType t6 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t7 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BOOLEAN),
 true);
RelDataType t8 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DATE),
 true);
RelDataType t9 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIME),
 true);
RelDataType t10 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIMESTAMP),
 true);
RelDataType t11 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.VARCHAR),
 true);


builder.add("ID", t0);
builder.add("byte_test".toUpperCase(), 
t1);
builder.add("short_test".toUpperCase(), 
t2);
builder.add("int_test".toUpperCase(), 
t3);
builder.add("float_test".toUpperCase(), 
t4);

builder.add("double_test".toUpperCase(), t5);
builder.add("long_test".toUpperCase(), 
t6);

builder.add("boolean_test".toUpperCase(), t7);
builder.add("date_test".toUpperCase(), 
t8);
builder.add("time_test".toUpperCase(), 
t9);

builder.add("timestamp_test".toUpperCase(), t10);

builder.add("string_test".toUpperCase(), t11);

return builder.build();
}
});


rootSchema.add("TABLE_RESULT_COPY", new AbstractTable() 
{
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();

RelDataType t0 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t1 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TINYINT),
 true);
RelDataType t2 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.SMALLINT),
 true);
RelDataType t3 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);
RelDataType t4 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.FLOAT),
 true);
RelDataType t5 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DOUBLE),
 true);
RelDataType t6 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 

[jira] [Updated] (CALCITE-2659) Wrong plan In natural left/right join

2018-11-07 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2659?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2659:
--
Description: 
The following is the code:


{code:java}
public static void main(String[] args) {
try {
SchemaPlus rootSchema = 
Frameworks.createRootSchema(true);

rootSchema.add("TABLE_RESULT", new AbstractTable() {
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();

RelDataType t0 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t1 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TINYINT),
 true);
RelDataType t2 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.SMALLINT),
 true);
RelDataType t3 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);
RelDataType t4 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.FLOAT),
 true);
RelDataType t5 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DOUBLE),
 true);
RelDataType t6 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t7 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BOOLEAN),
 true);
RelDataType t8 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DATE),
 true);
RelDataType t9 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIME),
 true);
RelDataType t10 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIMESTAMP),
 true);
RelDataType t11 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.VARCHAR),
 true);


builder.add("ID", t0);
builder.add("byte_test".toUpperCase(), 
t1);
builder.add("short_test".toUpperCase(), 
t2);
builder.add("int_test".toUpperCase(), 
t3);
builder.add("float_test".toUpperCase(), 
t4);

builder.add("double_test".toUpperCase(), t5);
builder.add("long_test".toUpperCase(), 
t6);

builder.add("boolean_test".toUpperCase(), t7);
builder.add("date_test".toUpperCase(), 
t8);
builder.add("time_test".toUpperCase(), 
t9);

builder.add("timestamp_test".toUpperCase(), t10);

builder.add("string_test".toUpperCase(), t11);

return builder.build();
}
});


rootSchema.add("TABLE_RESULT_COPY", new AbstractTable() 
{
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();

RelDataType t0 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t1 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TINYINT),
 true);
RelDataType t2 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.SMALLINT),
 true);
RelDataType t3 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);
RelDataType t4 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.FLOAT),
 true);
RelDataType t5 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DOUBLE),
 true);
RelDataType t6 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 

[jira] [Updated] (CALCITE-2659) Wrong plan In natural left/right join

2018-11-07 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2659?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2659:
--
Description: 
The following is the code:


{code:java}
public static void main(String[] args) {
try {
SchemaPlus rootSchema = 
Frameworks.createRootSchema(true);

rootSchema.add("TABLE_RESULT", new AbstractTable() {
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();

RelDataType t0 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t1 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TINYINT),
 true);
RelDataType t2 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.SMALLINT),
 true);
RelDataType t3 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);
RelDataType t4 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.FLOAT),
 true);
RelDataType t5 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DOUBLE),
 true);
RelDataType t6 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t7 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BOOLEAN),
 true);
RelDataType t8 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DATE),
 true);
RelDataType t9 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIME),
 true);
RelDataType t10 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIMESTAMP),
 true);
RelDataType t11 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.VARCHAR),
 true);


builder.add("ID", t0);
builder.add("byte_test".toUpperCase(), 
t1);
builder.add("short_test".toUpperCase(), 
t2);
builder.add("int_test".toUpperCase(), 
t3);
builder.add("float_test".toUpperCase(), 
t4);

builder.add("double_test".toUpperCase(), t5);
builder.add("long_test".toUpperCase(), 
t6);

builder.add("boolean_test".toUpperCase(), t7);
builder.add("date_test".toUpperCase(), 
t8);
builder.add("time_test".toUpperCase(), 
t9);

builder.add("timestamp_test".toUpperCase(), t10);

builder.add("string_test".toUpperCase(), t11);

return builder.build();
}
});


rootSchema.add("TABLE_RESULT_COPY", new AbstractTable() 
{
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();

RelDataType t0 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t1 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TINYINT),
 true);
RelDataType t2 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.SMALLINT),
 true);
RelDataType t3 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);
RelDataType t4 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.FLOAT),
 true);
RelDataType t5 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DOUBLE),
 true);
RelDataType t6 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 

[jira] [Updated] (CALCITE-2659) Wrong plan In natural left/right join

2018-11-07 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2659?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2659:
--
Description: 
public static void main(String[] args) {
try {
SchemaPlus rootSchema = 
Frameworks.createRootSchema(true);

rootSchema.add("TABLE_RESULT", new AbstractTable() {
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();

RelDataType t0 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t1 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TINYINT),
 true);
RelDataType t2 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.SMALLINT),
 true);
RelDataType t3 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);
RelDataType t4 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.FLOAT),
 true);
RelDataType t5 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DOUBLE),
 true);
RelDataType t6 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t7 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BOOLEAN),
 true);
RelDataType t8 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DATE),
 true);
RelDataType t9 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIME),
 true);
RelDataType t10 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIMESTAMP),
 true);
RelDataType t11 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.VARCHAR),
 true);


builder.add("ID", t0);
builder.add("byte_test".toUpperCase(), 
t1);
builder.add("short_test".toUpperCase(), 
t2);
builder.add("int_test".toUpperCase(), 
t3);
builder.add("float_test".toUpperCase(), 
t4);

builder.add("double_test".toUpperCase(), t5);
builder.add("long_test".toUpperCase(), 
t6);

builder.add("boolean_test".toUpperCase(), t7);
builder.add("date_test".toUpperCase(), 
t8);
builder.add("time_test".toUpperCase(), 
t9);

builder.add("timestamp_test".toUpperCase(), t10);

builder.add("string_test".toUpperCase(), t11);

return builder.build();
}
});


rootSchema.add("TABLE_RESULT_COPY", new AbstractTable() 
{
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();

RelDataType t0 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t1 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TINYINT),
 true);
RelDataType t2 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.SMALLINT),
 true);
RelDataType t3 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);
RelDataType t4 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.FLOAT),
 true);
RelDataType t5 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DOUBLE),
 true);
RelDataType t6 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
  

[jira] [Created] (CALCITE-2659) Wrong plan In natural left/right join

2018-11-07 Thread yuqi (JIRA)
yuqi created CALCITE-2659:
-

 Summary: Wrong plan In natural left/right  join
 Key: CALCITE-2659
 URL: https://issues.apache.org/jira/browse/CALCITE-2659
 Project: Calcite
  Issue Type: Bug
  Components: core
Affects Versions: 1.17.0
 Environment: 
{code:java}
public static void main(String[] args) {
try {
SchemaPlus rootSchema = 
Frameworks.createRootSchema(true);

rootSchema.add("TABLE_RESULT", new AbstractTable() {
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();

RelDataType t0 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t1 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TINYINT),
 true);
RelDataType t2 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.SMALLINT),
 true);
RelDataType t3 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);
RelDataType t4 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.FLOAT),
 true);
RelDataType t5 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DOUBLE),
 true);
RelDataType t6 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t7 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BOOLEAN),
 true);
RelDataType t8 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DATE),
 true);
RelDataType t9 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIME),
 true);
RelDataType t10 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIMESTAMP),
 true);
RelDataType t11 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.VARCHAR),
 true);


builder.add("ID", t0);
builder.add("byte_test".toUpperCase(), 
t1);
builder.add("short_test".toUpperCase(), 
t2);
builder.add("int_test".toUpperCase(), 
t3);
builder.add("float_test".toUpperCase(), 
t4);

builder.add("double_test".toUpperCase(), t5);
builder.add("long_test".toUpperCase(), 
t6);

builder.add("boolean_test".toUpperCase(), t7);
builder.add("date_test".toUpperCase(), 
t8);
builder.add("time_test".toUpperCase(), 
t9);

builder.add("timestamp_test".toUpperCase(), t10);

builder.add("string_test".toUpperCase(), t11);

return builder.build();
}
});


rootSchema.add("TABLE_RESULT_COPY", new AbstractTable() 
{
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();

RelDataType t0 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t1 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TINYINT),
 true);
RelDataType t2 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.SMALLINT),
 true);
RelDataType t3 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);
RelDataType t4 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.FLOAT),
 true);
RelDataType t5 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DOUBLE),
 true);
  

[jira] [Updated] (CALCITE-2659) Wrong plan In natural left/right join

2018-11-07 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2659?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2659:
--
Environment: (was: 
{code:java}
public static void main(String[] args) {
try {
SchemaPlus rootSchema = 
Frameworks.createRootSchema(true);

rootSchema.add("TABLE_RESULT", new AbstractTable() {
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();

RelDataType t0 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t1 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TINYINT),
 true);
RelDataType t2 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.SMALLINT),
 true);
RelDataType t3 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);
RelDataType t4 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.FLOAT),
 true);
RelDataType t5 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DOUBLE),
 true);
RelDataType t6 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t7 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BOOLEAN),
 true);
RelDataType t8 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DATE),
 true);
RelDataType t9 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIME),
 true);
RelDataType t10 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIMESTAMP),
 true);
RelDataType t11 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.VARCHAR),
 true);


builder.add("ID", t0);
builder.add("byte_test".toUpperCase(), 
t1);
builder.add("short_test".toUpperCase(), 
t2);
builder.add("int_test".toUpperCase(), 
t3);
builder.add("float_test".toUpperCase(), 
t4);

builder.add("double_test".toUpperCase(), t5);
builder.add("long_test".toUpperCase(), 
t6);

builder.add("boolean_test".toUpperCase(), t7);
builder.add("date_test".toUpperCase(), 
t8);
builder.add("time_test".toUpperCase(), 
t9);

builder.add("timestamp_test".toUpperCase(), t10);

builder.add("string_test".toUpperCase(), t11);

return builder.build();
}
});


rootSchema.add("TABLE_RESULT_COPY", new AbstractTable() 
{
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();

RelDataType t0 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);
RelDataType t1 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TINYINT),
 true);
RelDataType t2 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.SMALLINT),
 true);
RelDataType t3 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);
RelDataType t4 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.FLOAT),
 true);
RelDataType t5 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DOUBLE),
 true);
RelDataType t6 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT),
 true);

[jira] [Commented] (CALCITE-2637) Prefix minus operator failed in between and clause

2018-10-23 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2637?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16660696#comment-16660696
 ] 

yuqi commented on CALCITE-2637:
---

[~julianhyde], Can you help to confirm this problem? Thanks

> Prefix minus operator failed in between and clause
> --
>
> Key: CALCITE-2637
> URL: https://issues.apache.org/jira/browse/CALCITE-2637
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.17.0
>Reporter: yuqi
>Assignee: Julian Hyde
>Priority: Major
> Fix For: 1.18.0
>
>
> We can reproduce it like this 
> {code:java}
> public static void main(String[] args) {
>   try {
>   SchemaPlus rootSchema = 
> Frameworks.createRootSchema(true);
>   rootSchema.add("TABLE_RESULT", new AbstractTable() {
>   public RelDataType getRowType(final 
> RelDataTypeFactory typeFactory) {
>   RelDataTypeFactory.FieldInfoBuilder 
> builder = typeFactory.builder();
>   RelDataType t1 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
>  true);
>   RelDataType t2 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.CHAR),
>  true);
>   RelDataType t3 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
>  true);
>   builder.add("ID", t1);
>   builder.add("NAME", t2);
>   builder.add("SCORE", t3);;
>   return builder.build();
>   }
>   });
>   final FrameworkConfig config = 
> Frameworks.newConfigBuilder()
>   .parserConfig(SqlParser.Config.DEFAULT)
>   .defaultSchema(rootSchema)
>   .build();
>   Planner planner = Frameworks.getPlanner(config);
>   String sql = "select id, score between - score * 5 and 
> 100 from table_result";
>   SqlNode parse = planner.parse(sql);
>   SqlNode validate = planner.validate(parse);
>   RelRoot root = planner.rel(validate);
>   } catch (Exception e) {
>   e.printStackTrace();
>   }
>   }
> {code}
> the above code will cause the following problem:
> {code:java}
> org.apache.calcite.sql.parser.SqlParseException: Encountered "- score" at 
> line 1, column 26.
> Was expecting one of:
> "SYMMETRIC" ...
> "ASYMMETRIC" ...
> "+" ...
> "-" ...
> "-"  ...
> "-"  ...
> "-"  ...
>  ...
>  ...
>  ...
>  ...
>  ...
>  ...
>  ...
> "TRUE" ...
> "FALSE" ...
> "UNKNOWN" ...
> "NULL" ...
>  ...
>  ...
>  ...
> "DATE" ...
> "TIME" ...
> "TIMESTAMP" ...
> "INTERVAL" ...
> "?" ...
> "CAST" ...
> "EXTRACT" ...
> "POSITION" ...
> "CONVERT" ...
> "TRANSLATE" ...
> "OVERLAY" ...
> "FLOOR" ...
> "CEIL" ...
> "CEILING" ...
> "SUBSTRING" ...
> "TRIM" ...
> "CLASSIFIER" ...
> "MATCH_NUMBER" ...
> "RUNNING" ...
> "PREV" ...
> "NEXT" ...
>  ...
> "MULTISET" ...
> "ARRAY" ...
> "PERIOD" ...
> "SPECIFIC" ...
>  ...
>  ...
>  ...
>  ...
>  ...
> "ABS" ...
> "AVG" ...
> "CARDINALITY" ...
> "CHAR_LENGTH" ...
> "CHARACTER_LENGTH" ...
> "COALESCE" ...
> "COLLECT" ...
> "COVAR_POP" ...
> "COVAR_SAMP" ...
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Updated] (CALCITE-2637) Prefix minus operator failed in between and clause

2018-10-23 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2637?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2637:
--
Environment: (was: We can reproduce it like this 


{code:java}
public static void main(String[] args) {
try {
SchemaPlus rootSchema = 
Frameworks.createRootSchema(true);

rootSchema.add("TABLE_RESULT", new AbstractTable() {
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();

RelDataType t1 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);
RelDataType t2 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.CHAR),
 true);
RelDataType t3 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);

builder.add("ID", t1);
builder.add("NAME", t2);
builder.add("SCORE", t3);;
return builder.build();
}
});
final FrameworkConfig config = 
Frameworks.newConfigBuilder()
.parserConfig(SqlParser.Config.DEFAULT)
.defaultSchema(rootSchema)
.build();
Planner planner = Frameworks.getPlanner(config);

String sql = "select id, score between - score * 5 and 
100 from table_result";


SqlNode parse = planner.parse(sql);
SqlNode validate = planner.validate(parse);

RelRoot root = planner.rel(validate);

} catch (Exception e) {
e.printStackTrace();
}
}
{code}

the above code will cause the following problem:


{code:java}
org.apache.calcite.sql.parser.SqlParseException: Encountered "- score" at line 
1, column 26.
Was expecting one of:
"SYMMETRIC" ...
"ASYMMETRIC" ...
"+" ...
"-" ...
"-"  ...
"-"  ...
"-"  ...
 ...
 ...
 ...
 ...
 ...
 ...
 ...
"TRUE" ...
"FALSE" ...
"UNKNOWN" ...
"NULL" ...
 ...
 ...
 ...
"DATE" ...
"TIME" ...
"TIMESTAMP" ...
"INTERVAL" ...
"?" ...
"CAST" ...
"EXTRACT" ...
"POSITION" ...
"CONVERT" ...
"TRANSLATE" ...
"OVERLAY" ...
"FLOOR" ...
"CEIL" ...
"CEILING" ...
"SUBSTRING" ...
"TRIM" ...
"CLASSIFIER" ...
"MATCH_NUMBER" ...
"RUNNING" ...
"PREV" ...
"NEXT" ...
 ...
"MULTISET" ...
"ARRAY" ...
"PERIOD" ...
"SPECIFIC" ...
 ...
 ...
 ...
 ...
 ...
"ABS" ...
"AVG" ...
"CARDINALITY" ...
"CHAR_LENGTH" ...
"CHARACTER_LENGTH" ...
"COALESCE" ...
"COLLECT" ...
"COVAR_POP" ...
"COVAR_SAMP" ...
{code}
)

> Prefix minus operator failed in between and clause
> --
>
> Key: CALCITE-2637
> URL: https://issues.apache.org/jira/browse/CALCITE-2637
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.17.0
>Reporter: yuqi
>Assignee: Julian Hyde
>Priority: Major
> Fix For: 1.18.0
>
>
> We can reproduce it like this 
> {code:java}
> public static void main(String[] args) {
>   try {
>   SchemaPlus rootSchema = 
> Frameworks.createRootSchema(true);
>   rootSchema.add("TABLE_RESULT", new AbstractTable() {
>   public RelDataType getRowType(final 
> RelDataTypeFactory typeFactory) {
>   RelDataTypeFactory.FieldInfoBuilder 
> builder = typeFactory.builder();
>   RelDataType t1 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
>  true);
>   RelDataType t2 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.CHAR),
>  true);
>   RelDataType t3 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
>  true);
>   builder.add("ID", t1);
>   builder.add("NAME", t2);
>   builder.add("SCORE", t3);;
> 

[jira] [Updated] (CALCITE-2637) Prefix minus operator failed in between and clause

2018-10-23 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2637?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2637:
--
Description: 
We can reproduce it like this 


{code:java}
public static void main(String[] args) {
try {
SchemaPlus rootSchema = 
Frameworks.createRootSchema(true);

rootSchema.add("TABLE_RESULT", new AbstractTable() {
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();

RelDataType t1 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);
RelDataType t2 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.CHAR),
 true);
RelDataType t3 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);

builder.add("ID", t1);
builder.add("NAME", t2);
builder.add("SCORE", t3);;
return builder.build();
}
});
final FrameworkConfig config = 
Frameworks.newConfigBuilder()
.parserConfig(SqlParser.Config.DEFAULT)
.defaultSchema(rootSchema)
.build();
Planner planner = Frameworks.getPlanner(config);

String sql = "select id, score between - score * 5 and 
100 from table_result";


SqlNode parse = planner.parse(sql);
SqlNode validate = planner.validate(parse);

RelRoot root = planner.rel(validate);

} catch (Exception e) {
e.printStackTrace();
}
}
{code}

the above code will cause the following problem:


{code:java}
org.apache.calcite.sql.parser.SqlParseException: Encountered "- score" at line 
1, column 26.
Was expecting one of:
"SYMMETRIC" ...
"ASYMMETRIC" ...
"+" ...
"-" ...
"-"  ...
"-"  ...
"-"  ...
 ...
 ...
 ...
 ...
 ...
 ...
 ...
"TRUE" ...
"FALSE" ...
"UNKNOWN" ...
"NULL" ...
 ...
 ...
 ...
"DATE" ...
"TIME" ...
"TIMESTAMP" ...
"INTERVAL" ...
"?" ...
"CAST" ...
"EXTRACT" ...
"POSITION" ...
"CONVERT" ...
"TRANSLATE" ...
"OVERLAY" ...
"FLOOR" ...
"CEIL" ...
"CEILING" ...
"SUBSTRING" ...
"TRIM" ...
"CLASSIFIER" ...
"MATCH_NUMBER" ...
"RUNNING" ...
"PREV" ...
"NEXT" ...
 ...
"MULTISET" ...
"ARRAY" ...
"PERIOD" ...
"SPECIFIC" ...
 ...
 ...
 ...
 ...
 ...
"ABS" ...
"AVG" ...
"CARDINALITY" ...
"CHAR_LENGTH" ...
"CHARACTER_LENGTH" ...
"COALESCE" ...
"COLLECT" ...
"COVAR_POP" ...
"COVAR_SAMP" ...
{code}


> Prefix minus operator failed in between and clause
> --
>
> Key: CALCITE-2637
> URL: https://issues.apache.org/jira/browse/CALCITE-2637
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.17.0
> Environment: We can reproduce it like this 
> {code:java}
> public static void main(String[] args) {
>   try {
>   SchemaPlus rootSchema = 
> Frameworks.createRootSchema(true);
>   rootSchema.add("TABLE_RESULT", new AbstractTable() {
>   public RelDataType getRowType(final 
> RelDataTypeFactory typeFactory) {
>   RelDataTypeFactory.FieldInfoBuilder 
> builder = typeFactory.builder();
>   RelDataType t1 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
>  true);
>   RelDataType t2 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.CHAR),
>  true);
>   RelDataType t3 = 
> typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
>  true);
>   builder.add("ID", t1);
>   builder.add("NAME", t2);
>   builder.add("SCORE", t3);;
>   return builder.build();
>   }
>   });
>  

[jira] [Created] (CALCITE-2637) Prefix minus operator failed in between and clause

2018-10-23 Thread yuqi (JIRA)
yuqi created CALCITE-2637:
-

 Summary: Prefix minus operator failed in between and clause
 Key: CALCITE-2637
 URL: https://issues.apache.org/jira/browse/CALCITE-2637
 Project: Calcite
  Issue Type: Bug
  Components: core
Affects Versions: 1.17.0
 Environment: We can reproduce it like this 


{code:java}
public static void main(String[] args) {
try {
SchemaPlus rootSchema = 
Frameworks.createRootSchema(true);

rootSchema.add("TABLE_RESULT", new AbstractTable() {
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();

RelDataType t1 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);
RelDataType t2 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.CHAR),
 true);
RelDataType t3 = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER),
 true);

builder.add("ID", t1);
builder.add("NAME", t2);
builder.add("SCORE", t3);;
return builder.build();
}
});
final FrameworkConfig config = 
Frameworks.newConfigBuilder()
.parserConfig(SqlParser.Config.DEFAULT)
.defaultSchema(rootSchema)
.build();
Planner planner = Frameworks.getPlanner(config);

String sql = "select id, score between - score * 5 and 
100 from table_result";


SqlNode parse = planner.parse(sql);
SqlNode validate = planner.validate(parse);

RelRoot root = planner.rel(validate);

} catch (Exception e) {
e.printStackTrace();
}
}
{code}

the above code will cause the following problem:


{code:java}
org.apache.calcite.sql.parser.SqlParseException: Encountered "- score" at line 
1, column 26.
Was expecting one of:
"SYMMETRIC" ...
"ASYMMETRIC" ...
"+" ...
"-" ...
"-"  ...
"-"  ...
"-"  ...
 ...
 ...
 ...
 ...
 ...
 ...
 ...
"TRUE" ...
"FALSE" ...
"UNKNOWN" ...
"NULL" ...
 ...
 ...
 ...
"DATE" ...
"TIME" ...
"TIMESTAMP" ...
"INTERVAL" ...
"?" ...
"CAST" ...
"EXTRACT" ...
"POSITION" ...
"CONVERT" ...
"TRANSLATE" ...
"OVERLAY" ...
"FLOOR" ...
"CEIL" ...
"CEILING" ...
"SUBSTRING" ...
"TRIM" ...
"CLASSIFIER" ...
"MATCH_NUMBER" ...
"RUNNING" ...
"PREV" ...
"NEXT" ...
 ...
"MULTISET" ...
"ARRAY" ...
"PERIOD" ...
"SPECIFIC" ...
 ...
 ...
 ...
 ...
 ...
"ABS" ...
"AVG" ...
"CARDINALITY" ...
"CHAR_LENGTH" ...
"CHARACTER_LENGTH" ...
"COALESCE" ...
"COLLECT" ...
"COVAR_POP" ...
"COVAR_SAMP" ...
{code}

Reporter: yuqi
Assignee: Julian Hyde
 Fix For: 1.18.0






--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-2349) Failed to build RexCall with SqlDatetimeSubtractionOperator

2018-06-06 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2349?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16503048#comment-16503048
 ] 

yuqi commented on CALCITE-2349:
---

[~julianhyde]
As the JavaDoc says:

A special operator for the subtraction of two DATETIMEs. The format of DATETIME 
subtraction is:
"("  "-"  ")" 
This operator is special since* it needs to hold the additional interval 
qualifier specification*, when in SqlCall form. *In RexNode form, it has only 
two parameters, and the return type describes the desired type of intervall*.

This may be a little puzzled.  In SqlCall it have three operands and In RexNode 
only two. However, SqlDatetimeSubtractionOperator was initialized three and the 
return type of this operator is the type of the third operand. 

So, can you help me clarify this ? thanks 



> Failed to build RexCall with SqlDatetimeSubtractionOperator
> ---
>
> Key: CALCITE-2349
> URL: https://issues.apache.org/jira/browse/CALCITE-2349
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.16.0
>Reporter: yuqi
>Assignee: Julian Hyde
>Priority: Minor
> Fix For: 1.17.0
>
> Attachments: 1.png, screenshot-1.png
>
>
> When use RexBuilder to build RexCall with SqlDatetimeSubtractionOperator, it 
> will throw exception.
> {code:java}
> java.lang.IndexOutOfBoundsException: index (2) must be less than size (2)
>   at 
> com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:310)
>   at 
> com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:293)
>   at 
> com.google.common.collect.RegularImmutableList.get(RegularImmutableList.java:67)
>   at 
> org.apache.calcite.rex.RexCallBinding.getOperandType(RexCallBinding.java:132)
>   at 
> org.apache.calcite.sql.type.OrdinalReturnTypeInference.inferReturnType(OrdinalReturnTypeInference.java:40)
>   at 
> org.apache.calcite.sql.type.SqlTypeTransformCascade.inferReturnType(SqlTypeTransformCascade.java:54)
>   at 
> org.apache.calcite.sql.SqlOperator.inferReturnType(SqlOperator.java:470)
>   at 
> org.apache.calcite.rex.RexBuilder.deriveReturnType(RexBuilder.java:274)
>   at org.apache.calcite.rex.RexBuilder.makeCall(RexBuilder.java:248)
>   at com.netease.yuqi.calcatetest.TestThree.main(TestThree.java:100)
> {code}
> Below is My code:
> {code:java}
> public static void main(String[] args) {
>   try {
>   SchemaPlus rootSchema = 
> Frameworks.createRootSchema(true);
>   rootSchema.add("USERS", new AbstractTable() {
>   public RelDataType getRowType(final 
> RelDataTypeFactory typeFactory) {
>   RelDataTypeFactory.FieldInfoBuilder 
> builder = typeFactory.builder();
>   builder.add("ID", new BasicSqlType(new 
> RelDataTypeSystemImpl() {
>   }, SqlTypeName.INTEGER));
>   builder.add("NAME", new 
> BasicSqlType(new RelDataTypeSystemImpl() {
>   }, SqlTypeName.CHAR));
>   builder.add("TIME_D", new 
> BasicSqlType(new RelDataTypeSystemImpl() {
>   }, SqlTypeName.TIMESTAMP));
>   return builder.build();
>   }
>   });
>   rootSchema.add("TABLE_RESULT", new AbstractTable() {
>   public RelDataType getRowType(final 
> RelDataTypeFactory typeFactory) {
>   RelDataTypeFactory.FieldInfoBuilder 
> builder = typeFactory.builder();
>   builder.add("ID", new BasicSqlType(new 
> RelDataTypeSystemImpl() {
>   }, SqlTypeName.INTEGER));
>   builder.add("NAME", new 
> BasicSqlType(new RelDataTypeSystemImpl() {
>   }, SqlTypeName.CHAR));
>   builder.add("SCORE", new 
> BasicSqlType(new RelDataTypeSystemImpl() {
>   }, SqlTypeName.INTEGER));
>   return builder.build();
>   }
>   });
>   final FrameworkConfig config = 
> Frameworks.newConfigBuilder()
>   .parserConfig(SqlParser.Config.DEFAULT)
>   .defaultSchema(rootSchema)
>   .build();
>   Planner planner = Frameworks.getPlanner(config);
>   

[jira] [Commented] (CALCITE-2349) Failed to build RexCall with SqlDatetimeSubtractionOperator

2018-06-02 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2349?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16498965#comment-16498965
 ] 

yuqi commented on CALCITE-2349:
---

[~julianhyde]
I'am a little confused, DateTime is not a type in calcite, but a type set, 
SqlTypeName do not contains type of DateTime


{code:java}
  public static final List DATETIME_TYPES =
  ImmutableList.of(DATE, TIME, TIME_WITH_LOCAL_TIME_ZONE,
  TIMESTAMP, TIMESTAMP_WITH_LOCAL_TIME_ZONE);
{code}

So, i can't understand why you say it only accept datetime. 

More about it,  I wonder why calcite can pass that sql, as you know field 
time_d is a timestamp 
 !screenshot-1.png! 

Value of $2 is a timestamp, if i do make call the RexBuilder.makeCall(),  the 
function will goes well.




> Failed to build RexCall with SqlDatetimeSubtractionOperator
> ---
>
> Key: CALCITE-2349
> URL: https://issues.apache.org/jira/browse/CALCITE-2349
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.16.0
>Reporter: yuqi
>Assignee: Julian Hyde
>Priority: Minor
> Fix For: 1.17.0
>
> Attachments: 1.png, screenshot-1.png
>
>
> When use RexBuilder to build RexCall with SqlDatetimeSubtractionOperator, it 
> will throw exception.
> {code:java}
> java.lang.IndexOutOfBoundsException: index (2) must be less than size (2)
>   at 
> com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:310)
>   at 
> com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:293)
>   at 
> com.google.common.collect.RegularImmutableList.get(RegularImmutableList.java:67)
>   at 
> org.apache.calcite.rex.RexCallBinding.getOperandType(RexCallBinding.java:132)
>   at 
> org.apache.calcite.sql.type.OrdinalReturnTypeInference.inferReturnType(OrdinalReturnTypeInference.java:40)
>   at 
> org.apache.calcite.sql.type.SqlTypeTransformCascade.inferReturnType(SqlTypeTransformCascade.java:54)
>   at 
> org.apache.calcite.sql.SqlOperator.inferReturnType(SqlOperator.java:470)
>   at 
> org.apache.calcite.rex.RexBuilder.deriveReturnType(RexBuilder.java:274)
>   at org.apache.calcite.rex.RexBuilder.makeCall(RexBuilder.java:248)
>   at com.netease.yuqi.calcatetest.TestThree.main(TestThree.java:100)
> {code}
> Below is My code:
> {code:java}
> public static void main(String[] args) {
>   try {
>   SchemaPlus rootSchema = 
> Frameworks.createRootSchema(true);
>   rootSchema.add("USERS", new AbstractTable() {
>   public RelDataType getRowType(final 
> RelDataTypeFactory typeFactory) {
>   RelDataTypeFactory.FieldInfoBuilder 
> builder = typeFactory.builder();
>   builder.add("ID", new BasicSqlType(new 
> RelDataTypeSystemImpl() {
>   }, SqlTypeName.INTEGER));
>   builder.add("NAME", new 
> BasicSqlType(new RelDataTypeSystemImpl() {
>   }, SqlTypeName.CHAR));
>   builder.add("TIME_D", new 
> BasicSqlType(new RelDataTypeSystemImpl() {
>   }, SqlTypeName.TIMESTAMP));
>   return builder.build();
>   }
>   });
>   rootSchema.add("TABLE_RESULT", new AbstractTable() {
>   public RelDataType getRowType(final 
> RelDataTypeFactory typeFactory) {
>   RelDataTypeFactory.FieldInfoBuilder 
> builder = typeFactory.builder();
>   builder.add("ID", new BasicSqlType(new 
> RelDataTypeSystemImpl() {
>   }, SqlTypeName.INTEGER));
>   builder.add("NAME", new 
> BasicSqlType(new RelDataTypeSystemImpl() {
>   }, SqlTypeName.CHAR));
>   builder.add("SCORE", new 
> BasicSqlType(new RelDataTypeSystemImpl() {
>   }, SqlTypeName.INTEGER));
>   return builder.build();
>   }
>   });
>   final FrameworkConfig config = 
> Frameworks.newConfigBuilder()
>   .parserConfig(SqlParser.Config.DEFAULT)
>   .defaultSchema(rootSchema)
>   .build();
>   Planner planner = Frameworks.getPlanner(config);
>   SqlNode parse1 = planner.parse("insert into 
> 

[jira] [Updated] (CALCITE-2349) Failed to build RexCall with SqlDatetimeSubtractionOperator

2018-06-02 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2349?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2349:
--
Attachment: screenshot-1.png

> Failed to build RexCall with SqlDatetimeSubtractionOperator
> ---
>
> Key: CALCITE-2349
> URL: https://issues.apache.org/jira/browse/CALCITE-2349
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.16.0
>Reporter: yuqi
>Assignee: Julian Hyde
>Priority: Minor
> Fix For: 1.17.0
>
> Attachments: 1.png, screenshot-1.png
>
>
> When use RexBuilder to build RexCall with SqlDatetimeSubtractionOperator, it 
> will throw exception.
> {code:java}
> java.lang.IndexOutOfBoundsException: index (2) must be less than size (2)
>   at 
> com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:310)
>   at 
> com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:293)
>   at 
> com.google.common.collect.RegularImmutableList.get(RegularImmutableList.java:67)
>   at 
> org.apache.calcite.rex.RexCallBinding.getOperandType(RexCallBinding.java:132)
>   at 
> org.apache.calcite.sql.type.OrdinalReturnTypeInference.inferReturnType(OrdinalReturnTypeInference.java:40)
>   at 
> org.apache.calcite.sql.type.SqlTypeTransformCascade.inferReturnType(SqlTypeTransformCascade.java:54)
>   at 
> org.apache.calcite.sql.SqlOperator.inferReturnType(SqlOperator.java:470)
>   at 
> org.apache.calcite.rex.RexBuilder.deriveReturnType(RexBuilder.java:274)
>   at org.apache.calcite.rex.RexBuilder.makeCall(RexBuilder.java:248)
>   at com.netease.yuqi.calcatetest.TestThree.main(TestThree.java:100)
> {code}
> Below is My code:
> {code:java}
> public static void main(String[] args) {
>   try {
>   SchemaPlus rootSchema = 
> Frameworks.createRootSchema(true);
>   rootSchema.add("USERS", new AbstractTable() {
>   public RelDataType getRowType(final 
> RelDataTypeFactory typeFactory) {
>   RelDataTypeFactory.FieldInfoBuilder 
> builder = typeFactory.builder();
>   builder.add("ID", new BasicSqlType(new 
> RelDataTypeSystemImpl() {
>   }, SqlTypeName.INTEGER));
>   builder.add("NAME", new 
> BasicSqlType(new RelDataTypeSystemImpl() {
>   }, SqlTypeName.CHAR));
>   builder.add("TIME_D", new 
> BasicSqlType(new RelDataTypeSystemImpl() {
>   }, SqlTypeName.TIMESTAMP));
>   return builder.build();
>   }
>   });
>   rootSchema.add("TABLE_RESULT", new AbstractTable() {
>   public RelDataType getRowType(final 
> RelDataTypeFactory typeFactory) {
>   RelDataTypeFactory.FieldInfoBuilder 
> builder = typeFactory.builder();
>   builder.add("ID", new BasicSqlType(new 
> RelDataTypeSystemImpl() {
>   }, SqlTypeName.INTEGER));
>   builder.add("NAME", new 
> BasicSqlType(new RelDataTypeSystemImpl() {
>   }, SqlTypeName.CHAR));
>   builder.add("SCORE", new 
> BasicSqlType(new RelDataTypeSystemImpl() {
>   }, SqlTypeName.INTEGER));
>   return builder.build();
>   }
>   });
>   final FrameworkConfig config = 
> Frameworks.newConfigBuilder()
>   .parserConfig(SqlParser.Config.DEFAULT)
>   .defaultSchema(rootSchema)
>   .build();
>   Planner planner = Frameworks.getPlanner(config);
>   SqlNode parse1 = planner.parse("insert into 
> table_result(id, name, score) select a.id as id, a.name as name, 1 from users 
> a where month(a.time_d - interval '30' day) >= 2");
>   SqlNode validate = planner.validate(parse1);
>   RelRoot root = planner.rel(validate);
>   RexBuilder builder1 = 
> root.rel.getCluster().getRexBuilder();
>   LogicalFilter filter = (LogicalFilter) 
> root.rel.getInput(0).getInput(0);
> //get RexCall of SqlDatetimeSubtractionOperator
>   RexCall call = (RexCall) ((RexCall) ((RexCall) 
> 

[jira] [Updated] (CALCITE-2349) Failed to build RexCall with SqlDatetimeSubtractionOperator

2018-06-01 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2349?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2349:
--
Attachment: 1.png

> Failed to build RexCall with SqlDatetimeSubtractionOperator
> ---
>
> Key: CALCITE-2349
> URL: https://issues.apache.org/jira/browse/CALCITE-2349
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.16.0
>Reporter: yuqi
>Assignee: Julian Hyde
>Priority: Minor
> Fix For: 1.17.0
>
> Attachments: 1.png
>
>
> When use RexBuilder to build RexCall with SqlDatetimeSubtractionOperator, it 
> will throw exception.
> {code:java}
> java.lang.IndexOutOfBoundsException: index (2) must be less than size (2)
>   at 
> com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:310)
>   at 
> com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:293)
>   at 
> com.google.common.collect.RegularImmutableList.get(RegularImmutableList.java:67)
>   at 
> org.apache.calcite.rex.RexCallBinding.getOperandType(RexCallBinding.java:132)
>   at 
> org.apache.calcite.sql.type.OrdinalReturnTypeInference.inferReturnType(OrdinalReturnTypeInference.java:40)
>   at 
> org.apache.calcite.sql.type.SqlTypeTransformCascade.inferReturnType(SqlTypeTransformCascade.java:54)
>   at 
> org.apache.calcite.sql.SqlOperator.inferReturnType(SqlOperator.java:470)
>   at 
> org.apache.calcite.rex.RexBuilder.deriveReturnType(RexBuilder.java:274)
>   at org.apache.calcite.rex.RexBuilder.makeCall(RexBuilder.java:248)
>   at com.netease.yuqi.calcatetest.TestThree.main(TestThree.java:100)
> {code}
> Below is My code:
> {code:java}
> public static void main(String[] args) {
>   try {
>   SchemaPlus rootSchema = 
> Frameworks.createRootSchema(true);
>   rootSchema.add("USERS", new AbstractTable() {
>   public RelDataType getRowType(final 
> RelDataTypeFactory typeFactory) {
>   RelDataTypeFactory.FieldInfoBuilder 
> builder = typeFactory.builder();
>   builder.add("ID", new BasicSqlType(new 
> RelDataTypeSystemImpl() {
>   }, SqlTypeName.INTEGER));
>   builder.add("NAME", new 
> BasicSqlType(new RelDataTypeSystemImpl() {
>   }, SqlTypeName.CHAR));
>   builder.add("TIME_D", new 
> BasicSqlType(new RelDataTypeSystemImpl() {
>   }, SqlTypeName.TIMESTAMP));
>   return builder.build();
>   }
>   });
>   rootSchema.add("TABLE_RESULT", new AbstractTable() {
>   public RelDataType getRowType(final 
> RelDataTypeFactory typeFactory) {
>   RelDataTypeFactory.FieldInfoBuilder 
> builder = typeFactory.builder();
>   builder.add("ID", new BasicSqlType(new 
> RelDataTypeSystemImpl() {
>   }, SqlTypeName.INTEGER));
>   builder.add("NAME", new 
> BasicSqlType(new RelDataTypeSystemImpl() {
>   }, SqlTypeName.CHAR));
>   builder.add("SCORE", new 
> BasicSqlType(new RelDataTypeSystemImpl() {
>   }, SqlTypeName.INTEGER));
>   return builder.build();
>   }
>   });
>   final FrameworkConfig config = 
> Frameworks.newConfigBuilder()
>   .parserConfig(SqlParser.Config.DEFAULT)
>   .defaultSchema(rootSchema)
>   .build();
>   Planner planner = Frameworks.getPlanner(config);
>   SqlNode parse1 = planner.parse("insert into 
> table_result(id, name, score) select a.id as id, a.name as name, 1 from users 
> a where month(a.time_d - interval '30' day) >= 2");
>   SqlNode validate = planner.validate(parse1);
>   RelRoot root = planner.rel(validate);
>   RexBuilder builder1 = 
> root.rel.getCluster().getRexBuilder();
>   LogicalFilter filter = (LogicalFilter) 
> root.rel.getInput(0).getInput(0);
> //get RexCall of SqlDatetimeSubtractionOperator
>   RexCall call = (RexCall) ((RexCall) ((RexCall) 
> 

[jira] [Commented] (CALCITE-2349) Failed to build RexCall with SqlDatetimeSubtractionOperator

2018-06-01 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2349?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16498864#comment-16498864
 ] 

yuqi commented on CALCITE-2349:
---

[~julianhyde]
I debug it and the number of operands of two, not three, am i wrong ? see the 
picture.
 !1.png! 


> Failed to build RexCall with SqlDatetimeSubtractionOperator
> ---
>
> Key: CALCITE-2349
> URL: https://issues.apache.org/jira/browse/CALCITE-2349
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.16.0
>Reporter: yuqi
>Assignee: Julian Hyde
>Priority: Minor
> Fix For: 1.17.0
>
> Attachments: 1.png
>
>
> When use RexBuilder to build RexCall with SqlDatetimeSubtractionOperator, it 
> will throw exception.
> {code:java}
> java.lang.IndexOutOfBoundsException: index (2) must be less than size (2)
>   at 
> com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:310)
>   at 
> com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:293)
>   at 
> com.google.common.collect.RegularImmutableList.get(RegularImmutableList.java:67)
>   at 
> org.apache.calcite.rex.RexCallBinding.getOperandType(RexCallBinding.java:132)
>   at 
> org.apache.calcite.sql.type.OrdinalReturnTypeInference.inferReturnType(OrdinalReturnTypeInference.java:40)
>   at 
> org.apache.calcite.sql.type.SqlTypeTransformCascade.inferReturnType(SqlTypeTransformCascade.java:54)
>   at 
> org.apache.calcite.sql.SqlOperator.inferReturnType(SqlOperator.java:470)
>   at 
> org.apache.calcite.rex.RexBuilder.deriveReturnType(RexBuilder.java:274)
>   at org.apache.calcite.rex.RexBuilder.makeCall(RexBuilder.java:248)
>   at com.netease.yuqi.calcatetest.TestThree.main(TestThree.java:100)
> {code}
> Below is My code:
> {code:java}
> public static void main(String[] args) {
>   try {
>   SchemaPlus rootSchema = 
> Frameworks.createRootSchema(true);
>   rootSchema.add("USERS", new AbstractTable() {
>   public RelDataType getRowType(final 
> RelDataTypeFactory typeFactory) {
>   RelDataTypeFactory.FieldInfoBuilder 
> builder = typeFactory.builder();
>   builder.add("ID", new BasicSqlType(new 
> RelDataTypeSystemImpl() {
>   }, SqlTypeName.INTEGER));
>   builder.add("NAME", new 
> BasicSqlType(new RelDataTypeSystemImpl() {
>   }, SqlTypeName.CHAR));
>   builder.add("TIME_D", new 
> BasicSqlType(new RelDataTypeSystemImpl() {
>   }, SqlTypeName.TIMESTAMP));
>   return builder.build();
>   }
>   });
>   rootSchema.add("TABLE_RESULT", new AbstractTable() {
>   public RelDataType getRowType(final 
> RelDataTypeFactory typeFactory) {
>   RelDataTypeFactory.FieldInfoBuilder 
> builder = typeFactory.builder();
>   builder.add("ID", new BasicSqlType(new 
> RelDataTypeSystemImpl() {
>   }, SqlTypeName.INTEGER));
>   builder.add("NAME", new 
> BasicSqlType(new RelDataTypeSystemImpl() {
>   }, SqlTypeName.CHAR));
>   builder.add("SCORE", new 
> BasicSqlType(new RelDataTypeSystemImpl() {
>   }, SqlTypeName.INTEGER));
>   return builder.build();
>   }
>   });
>   final FrameworkConfig config = 
> Frameworks.newConfigBuilder()
>   .parserConfig(SqlParser.Config.DEFAULT)
>   .defaultSchema(rootSchema)
>   .build();
>   Planner planner = Frameworks.getPlanner(config);
>   SqlNode parse1 = planner.parse("insert into 
> table_result(id, name, score) select a.id as id, a.name as name, 1 from users 
> a where month(a.time_d - interval '30' day) >= 2");
>   SqlNode validate = planner.validate(parse1);
>   RelRoot root = planner.rel(validate);
>   RexBuilder builder1 = 
> root.rel.getCluster().getRexBuilder();
>   LogicalFilter filter = (LogicalFilter) 
> root.rel.getInput(0).getInput(0);
> //get RexCall of 

[jira] [Created] (CALCITE-2349) Failed to build RexCall with SqlDatetimeSubtractionOperator

2018-06-01 Thread yuqi (JIRA)
yuqi created CALCITE-2349:
-

 Summary: Failed to build RexCall with 
SqlDatetimeSubtractionOperator
 Key: CALCITE-2349
 URL: https://issues.apache.org/jira/browse/CALCITE-2349
 Project: Calcite
  Issue Type: Bug
  Components: core
Affects Versions: 1.16.0
Reporter: yuqi
Assignee: Julian Hyde
 Fix For: 1.17.0


When use RexBuilder to build RexCall with SqlDatetimeSubtractionOperator, it 
will throw exception.


{code:java}
java.lang.IndexOutOfBoundsException: index (2) must be less than size (2)
at 
com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:310)
at 
com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:293)
at 
com.google.common.collect.RegularImmutableList.get(RegularImmutableList.java:67)
at 
org.apache.calcite.rex.RexCallBinding.getOperandType(RexCallBinding.java:132)
at 
org.apache.calcite.sql.type.OrdinalReturnTypeInference.inferReturnType(OrdinalReturnTypeInference.java:40)
at 
org.apache.calcite.sql.type.SqlTypeTransformCascade.inferReturnType(SqlTypeTransformCascade.java:54)
at 
org.apache.calcite.sql.SqlOperator.inferReturnType(SqlOperator.java:470)
at 
org.apache.calcite.rex.RexBuilder.deriveReturnType(RexBuilder.java:274)
at org.apache.calcite.rex.RexBuilder.makeCall(RexBuilder.java:248)
at com.netease.yuqi.calcatetest.TestThree.main(TestThree.java:100)
{code}


Below is My code:


{code:java}
public static void main(String[] args) {
try {
SchemaPlus rootSchema = 
Frameworks.createRootSchema(true);
rootSchema.add("USERS", new AbstractTable() {
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();
builder.add("ID", new BasicSqlType(new 
RelDataTypeSystemImpl() {
}, SqlTypeName.INTEGER));
builder.add("NAME", new 
BasicSqlType(new RelDataTypeSystemImpl() {
}, SqlTypeName.CHAR));

builder.add("TIME_D", new 
BasicSqlType(new RelDataTypeSystemImpl() {
}, SqlTypeName.TIMESTAMP));
return builder.build();
}
});

rootSchema.add("TABLE_RESULT", new AbstractTable() {
public RelDataType getRowType(final 
RelDataTypeFactory typeFactory) {
RelDataTypeFactory.FieldInfoBuilder 
builder = typeFactory.builder();
builder.add("ID", new BasicSqlType(new 
RelDataTypeSystemImpl() {
}, SqlTypeName.INTEGER));
builder.add("NAME", new 
BasicSqlType(new RelDataTypeSystemImpl() {
}, SqlTypeName.CHAR));
builder.add("SCORE", new 
BasicSqlType(new RelDataTypeSystemImpl() {
}, SqlTypeName.INTEGER));
return builder.build();
}
});
final FrameworkConfig config = 
Frameworks.newConfigBuilder()
.parserConfig(SqlParser.Config.DEFAULT)
.defaultSchema(rootSchema)
.build();
Planner planner = Frameworks.getPlanner(config);

SqlNode parse1 = planner.parse("insert into 
table_result(id, name, score) select a.id as id, a.name as name, 1 from users a 
where month(a.time_d - interval '30' day) >= 2");
SqlNode validate = planner.validate(parse1);

RelRoot root = planner.rel(validate);

RexBuilder builder1 = 
root.rel.getCluster().getRexBuilder();
LogicalFilter filter = (LogicalFilter) 
root.rel.getInput(0).getInput(0);

//get RexCall of SqlDatetimeSubtractionOperator
RexCall call = (RexCall) ((RexCall) ((RexCall) 
filter.getCondition()).operands.get(0)).getOperands().get(1);

builder1.makeCall(call.getOperator(), 
call.getOperands());

HepProgramBuilder builder = new HepProgramBuilder();

//builder.addRuleInstance(FilterJoinRule.FilterIntoJoinRule.FILTER_ON_JOIN);

[jira] [Commented] (CALCITE-2336) SqlValidatorImpl throws java.lang.IndexOutOfBoundsException

2018-05-31 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16497488#comment-16497488
 ] 

yuqi commented on CALCITE-2336:
---

[~xu fei] You can make a MR about this problem or i do it later

> SqlValidatorImpl throws java.lang.IndexOutOfBoundsException
> ---
>
> Key: CALCITE-2336
> URL: https://issues.apache.org/jira/browse/CALCITE-2336
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Reporter: Fei Xu
>Assignee: Julian Hyde
>Priority: Major
> Attachments: 1.patch
>
>
> I register a table "users" with a single column, age. And try to insert two 
> columns into the "users".
> {code:java}
> rootSchema = Frameworks.createRootSchema(true);
> rootSchema.add("USERS", new AbstractTable() {
>   @Override public RelDataType getRowType(final RelDataTypeFactory 
> typeFactory) {
> RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
> builder.add("age", new BasicSqlType(new RelDataTypeSystemImpl() {}, 
> SqlTypeName.CHAR));
> return builder.build();
>   }
> });
> final FrameworkConfig config = Frameworks.newConfigBuilder()
> .parserConfig(SqlParser.Config.DEFAULT)
> .defaultSchema(rootSchema)
> .build();
> planner = Frameworks.getPlanner(config);
> dataContext = new MyDataContext(planner);
> SqlNode parse =
> planner.parse("insert into users select y, x\n"
> + "from (values (1, 'a'), (2, 'b'), (3, 'c')) as t(x, y)\n"
> + "where x > 1");
> SqlNode validate = planner.validate(parse);
> {code}
> Apparently, I want to see some error message like:
> {code:java}
> Number of INSERT target columns (1) does not equal number of source items (2)
> {code}
> But actually, I got message:
> {code:java}
> org.apache.calcite.tools.ValidationException: 
> java.lang.IndexOutOfBoundsException: index (1) must be less than size (1)
> {code}
> which was confused.
> Then I debug the code in SqlValidatorImpl#validateSelectList method.
>  
> {code:java}
> protected RelDataType validateSelectList(
> final SqlNodeList selectItems,
> SqlSelect select,
> RelDataType targetRowType) {
>   // First pass, ensure that aliases are unique. "*" and "TABLE.*" items
>   // are ignored.
>   // Validate SELECT list. Expand terms of the form "*" or "TABLE.*".
>   final SqlValidatorScope selectScope = getSelectScope(select);
>   final List expandedSelectItems = new ArrayList<>();
>   final Set aliases = Sets.newHashSet();
>   final List> fieldList = new ArrayList<>();
>   for (int i = 0; i < selectItems.size(); i++) {
> SqlNode selectItem = selectItems.get(i);
> if (selectItem instanceof SqlSelect) {
>   handleScalarSubQuery(
>   select,
>   (SqlSelect) selectItem,
>   expandedSelectItems,
>   aliases,
>   fieldList);
> } else {
>   expandSelectItem(
>   selectItem,
>   select,
>   targetRowType.isStruct()
>   && targetRowType.getFieldCount() >= i
>   ? targetRowType.getFieldList().get(i).getType()
>   : unknownType,
>   expandedSelectItems,
>   aliases,
>   fieldList,
>   false);
> }
>   }
> {code}
> See the exception is throw from here, if selectItems's size more than 
> targetRowType's field count
> {code:java}
> && targetRowType.getFieldCount() >= i
> ? targetRowType.getFieldList().get(i).getType(){code}
> When I change it to this, I get what I need.
> {code:java}
> && targetRowType.getFieldCount() - 1 >= i  
> ? targetRowType.getFieldList().get(i).getType(){code}
> So is this a Bug ? Do we need fix it ? 
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Comment Edited] (CALCITE-2336) SqlValidatorImpl throws java.lang.IndexOutOfBoundsException

2018-05-31 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16496548#comment-16496548
 ] 

yuqi edited comment on CALCITE-2336 at 5/31/18 1:43 PM:


[~xu fei]
I suggest you check column size in function `validateInsert `, for example, 
should check row column size of insert should not less than size of select. see 
the patch
 [^1.patch] 

and you will get error information as below:


{code:java}
org.apache.calcite.tools.ValidationException: 
java.lang.IllegalArgumentException: Insert column size(1) should not less than 
that of select column(2)
at org.apache.calcite.prepare.PlannerImpl.validate(PlannerImpl.java:196)
at com.netease.yuqi.calcatetest.TestTwo.main(TestTwo.java:46)
Caused by: java.lang.IllegalArgumentException: Insert column size(1) should not 
less than that of select column(2)
at 
com.google.common.base.Preconditions.checkArgument(Preconditions.java:122)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3188)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateInsert(SqlValidatorImpl.java:4175)
at org.apache.calcite.sql.SqlInsert.validate(SqlInsert.java:148)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:915)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:625)
at org.apache.calcite.prepare.PlannerImpl.validate(PlannerImpl.java:194)
... 1 more

{code}





was (Author: yuqi):
[~xu fei]
I suggest you check column size in function `validateInsert `, for example, 
should check row column size of insert should not less than size of select. see 
the patch
 [^1.patch] 

and you will get error information as below:
```java
org.apache.calcite.tools.ValidationException: 
java.lang.IllegalArgumentException: Insert column size(1) should not less than 
that of select column(2)
at org.apache.calcite.prepare.PlannerImpl.validate(PlannerImpl.java:196)
at com.netease.yuqi.calcatetest.TestTwo.main(TestTwo.java:46)
Caused by: java.lang.IllegalArgumentException: Insert column size(1) should not 
less than that of select column(2)
at 
com.google.common.base.Preconditions.checkArgument(Preconditions.java:122)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3188)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateInsert(SqlValidatorImpl.java:4175)
at org.apache.calcite.sql.SqlInsert.validate(SqlInsert.java:148)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:915)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:625)
at org.apache.calcite.prepare.PlannerImpl.validate(PlannerImpl.java:194)
... 1 more
```



> SqlValidatorImpl throws java.lang.IndexOutOfBoundsException
> ---
>
> Key: CALCITE-2336
> URL: https://issues.apache.org/jira/browse/CALCITE-2336
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Reporter: Fei Xu
>Assignee: Julian Hyde
>Priority: Major
> Attachments: 1.patch
>
>
> I register a table "users" with a single column, age. And try to insert two 
> columns into the "users".
> {code:java}
> rootSchema = Frameworks.createRootSchema(true);
> rootSchema.add("USERS", new AbstractTable() {
>   @Override public RelDataType getRowType(final RelDataTypeFactory 
> typeFactory) {
> RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
> builder.add("age", new BasicSqlType(new RelDataTypeSystemImpl() {}, 
> SqlTypeName.CHAR));
> return builder.build();
>   }
> });
> final FrameworkConfig config = Frameworks.newConfigBuilder()
> .parserConfig(SqlParser.Config.DEFAULT)
> .defaultSchema(rootSchema)
> .build();
> planner = Frameworks.getPlanner(config);
> dataContext = new MyDataContext(planner);
> SqlNode parse =
> planner.parse("insert into users select y, x\n"
> + "from (values (1, 'a'), (2, 'b'), (3, 'c')) as t(x, y)\n"
> + "where x > 1");
> SqlNode validate = planner.validate(parse);
> {code}
> Apparently, I want to see some error message like:
> {code:java}
> Number of INSERT target columns (1) does not equal number of source items (2)
> {code}
> But actually, I got message:
> {code:java}
> org.apache.calcite.tools.ValidationException: 
> java.lang.IndexOutOfBoundsException: index (1) must be less than size (1)
> {code}
> which was confused.
> Then I debug the code in SqlValidatorImpl#validateSelectList method.
>  
> {code:java}
> protected RelDataType 

[jira] [Commented] (CALCITE-2336) SqlValidatorImpl throws java.lang.IndexOutOfBoundsException

2018-05-31 Thread yuqi (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16496548#comment-16496548
 ] 

yuqi commented on CALCITE-2336:
---

[~xu fei]
I suggest you check column size in function `validateInsert `, for example, 
should check row column size of insert should not less than size of select. see 
the patch
 [^1.patch] 

and you will get error information as below:
```java
org.apache.calcite.tools.ValidationException: 
java.lang.IllegalArgumentException: Insert column size(1) should not less than 
that of select column(2)
at org.apache.calcite.prepare.PlannerImpl.validate(PlannerImpl.java:196)
at com.netease.yuqi.calcatetest.TestTwo.main(TestTwo.java:46)
Caused by: java.lang.IllegalArgumentException: Insert column size(1) should not 
less than that of select column(2)
at 
com.google.common.base.Preconditions.checkArgument(Preconditions.java:122)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3188)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateInsert(SqlValidatorImpl.java:4175)
at org.apache.calcite.sql.SqlInsert.validate(SqlInsert.java:148)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:915)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:625)
at org.apache.calcite.prepare.PlannerImpl.validate(PlannerImpl.java:194)
... 1 more
```



> SqlValidatorImpl throws java.lang.IndexOutOfBoundsException
> ---
>
> Key: CALCITE-2336
> URL: https://issues.apache.org/jira/browse/CALCITE-2336
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Reporter: Fei Xu
>Assignee: Julian Hyde
>Priority: Major
> Attachments: 1.patch
>
>
> I register a table "users" with a single column, age. And try to insert two 
> columns into the "users".
> {code:java}
> rootSchema = Frameworks.createRootSchema(true);
> rootSchema.add("USERS", new AbstractTable() {
>   @Override public RelDataType getRowType(final RelDataTypeFactory 
> typeFactory) {
> RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
> builder.add("age", new BasicSqlType(new RelDataTypeSystemImpl() {}, 
> SqlTypeName.CHAR));
> return builder.build();
>   }
> });
> final FrameworkConfig config = Frameworks.newConfigBuilder()
> .parserConfig(SqlParser.Config.DEFAULT)
> .defaultSchema(rootSchema)
> .build();
> planner = Frameworks.getPlanner(config);
> dataContext = new MyDataContext(planner);
> SqlNode parse =
> planner.parse("insert into users select y, x\n"
> + "from (values (1, 'a'), (2, 'b'), (3, 'c')) as t(x, y)\n"
> + "where x > 1");
> SqlNode validate = planner.validate(parse);
> {code}
> Apparently, I want to see some error message like:
> {code:java}
> Number of INSERT target columns (1) does not equal number of source items (2)
> {code}
> But actually, I got message:
> {code:java}
> org.apache.calcite.tools.ValidationException: 
> java.lang.IndexOutOfBoundsException: index (1) must be less than size (1)
> {code}
> which was confused.
> Then I debug the code in SqlValidatorImpl#validateSelectList method.
>  
> {code:java}
> protected RelDataType validateSelectList(
> final SqlNodeList selectItems,
> SqlSelect select,
> RelDataType targetRowType) {
>   // First pass, ensure that aliases are unique. "*" and "TABLE.*" items
>   // are ignored.
>   // Validate SELECT list. Expand terms of the form "*" or "TABLE.*".
>   final SqlValidatorScope selectScope = getSelectScope(select);
>   final List expandedSelectItems = new ArrayList<>();
>   final Set aliases = Sets.newHashSet();
>   final List> fieldList = new ArrayList<>();
>   for (int i = 0; i < selectItems.size(); i++) {
> SqlNode selectItem = selectItems.get(i);
> if (selectItem instanceof SqlSelect) {
>   handleScalarSubQuery(
>   select,
>   (SqlSelect) selectItem,
>   expandedSelectItems,
>   aliases,
>   fieldList);
> } else {
>   expandSelectItem(
>   selectItem,
>   select,
>   targetRowType.isStruct()
>   && targetRowType.getFieldCount() >= i
>   ? targetRowType.getFieldList().get(i).getType()
>   : unknownType,
>   expandedSelectItems,
>   aliases,
>   fieldList,
>   false);
> }
>   }
> {code}
> See the exception is throw from here, if selectItems's size more than 
> targetRowType's field count
> {code:java}
> && targetRowType.getFieldCount() >= i
> ? targetRowType.getFieldList().get(i).getType(){code}
> When I change it to this, I 

[jira] [Updated] (CALCITE-2336) SqlValidatorImpl throws java.lang.IndexOutOfBoundsException

2018-05-31 Thread yuqi (JIRA)


 [ 
https://issues.apache.org/jira/browse/CALCITE-2336?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2336:
--
Attachment: 1.patch

> SqlValidatorImpl throws java.lang.IndexOutOfBoundsException
> ---
>
> Key: CALCITE-2336
> URL: https://issues.apache.org/jira/browse/CALCITE-2336
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Reporter: Fei Xu
>Assignee: Julian Hyde
>Priority: Major
> Attachments: 1.patch
>
>
> I register a table "users" with a single column, age. And try to insert two 
> columns into the "users".
> {code:java}
> rootSchema = Frameworks.createRootSchema(true);
> rootSchema.add("USERS", new AbstractTable() {
>   @Override public RelDataType getRowType(final RelDataTypeFactory 
> typeFactory) {
> RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
> builder.add("age", new BasicSqlType(new RelDataTypeSystemImpl() {}, 
> SqlTypeName.CHAR));
> return builder.build();
>   }
> });
> final FrameworkConfig config = Frameworks.newConfigBuilder()
> .parserConfig(SqlParser.Config.DEFAULT)
> .defaultSchema(rootSchema)
> .build();
> planner = Frameworks.getPlanner(config);
> dataContext = new MyDataContext(planner);
> SqlNode parse =
> planner.parse("insert into users select y, x\n"
> + "from (values (1, 'a'), (2, 'b'), (3, 'c')) as t(x, y)\n"
> + "where x > 1");
> SqlNode validate = planner.validate(parse);
> {code}
> Apparently, I want to see some error message like:
> {code:java}
> Number of INSERT target columns (1) does not equal number of source items (2)
> {code}
> But actually, I got message:
> {code:java}
> org.apache.calcite.tools.ValidationException: 
> java.lang.IndexOutOfBoundsException: index (1) must be less than size (1)
> {code}
> which was confused.
> Then I debug the code in SqlValidatorImpl#validateSelectList method.
>  
> {code:java}
> protected RelDataType validateSelectList(
> final SqlNodeList selectItems,
> SqlSelect select,
> RelDataType targetRowType) {
>   // First pass, ensure that aliases are unique. "*" and "TABLE.*" items
>   // are ignored.
>   // Validate SELECT list. Expand terms of the form "*" or "TABLE.*".
>   final SqlValidatorScope selectScope = getSelectScope(select);
>   final List expandedSelectItems = new ArrayList<>();
>   final Set aliases = Sets.newHashSet();
>   final List> fieldList = new ArrayList<>();
>   for (int i = 0; i < selectItems.size(); i++) {
> SqlNode selectItem = selectItems.get(i);
> if (selectItem instanceof SqlSelect) {
>   handleScalarSubQuery(
>   select,
>   (SqlSelect) selectItem,
>   expandedSelectItems,
>   aliases,
>   fieldList);
> } else {
>   expandSelectItem(
>   selectItem,
>   select,
>   targetRowType.isStruct()
>   && targetRowType.getFieldCount() >= i
>   ? targetRowType.getFieldList().get(i).getType()
>   : unknownType,
>   expandedSelectItems,
>   aliases,
>   fieldList,
>   false);
> }
>   }
> {code}
> See the exception is throw from here, if selectItems's size more than 
> targetRowType's field count
> {code:java}
> && targetRowType.getFieldCount() >= i
> ? targetRowType.getFieldList().get(i).getType(){code}
> When I change it to this, I get what I need.
> {code:java}
> && targetRowType.getFieldCount() - 1 >= i  
> ? targetRowType.getFieldList().get(i).getType(){code}
> So is this a Bug ? Do we need fix it ? 
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Updated] (CALCITE-2328) Operand of Logical And/OR should support type like INT, DOUTLE not only Boolean

2018-05-25 Thread yuqi (JIRA)

 [ 
https://issues.apache.org/jira/browse/CALCITE-2328?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2328:
--
Summary: Operand of Logical And/OR should support type like INT, DOUTLE not 
only Boolean  (was: Operand of Logical And/OR should support type like INT, 
DOUTLE not only boolean)

> Operand of Logical And/OR should support type like INT, DOUTLE not only 
> Boolean
> ---
>
> Key: CALCITE-2328
> URL: https://issues.apache.org/jira/browse/CALCITE-2328
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.16.0
>Reporter: yuqi
>Assignee: Julian Hyde
>Priority: Minor
> Fix For: 1.17.0
>
>
> As far as i see , MySQL support the following sql
> {code:java}
> select id, name from tb where 1 and 1;
> select id, name from tb where 1 and true;
> {code}
> However, calcite would not recognize that sql and says:
> {code:java}
> Caused by: org.apache.calcite.sql.validate.SqlValidatorException: Cannot 
> apply 'AND' to arguments of type ' AND '. Supported 
> form(s): ' AND '
>   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>   at 
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
>   at 
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
>   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
>   at 
> org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463)
>   at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:572)
>   ... 27 more
> {code}
> So, I propose if we should introduce more type support for logical AND/OR



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Created] (CALCITE-2328) Operand of Logical And/OR should support type like INT, DOUTLE not only boolean

2018-05-25 Thread yuqi (JIRA)
yuqi created CALCITE-2328:
-

 Summary: Operand of Logical And/OR should support type like INT, 
DOUTLE not only boolean
 Key: CALCITE-2328
 URL: https://issues.apache.org/jira/browse/CALCITE-2328
 Project: Calcite
  Issue Type: Bug
  Components: core
Affects Versions: 1.16.0
Reporter: yuqi
Assignee: Julian Hyde
 Fix For: 1.17.0


As far as i see , MySQL support the following sql

{code:java}
select id, name from tb where 1 and 1;
select id, name from tb where 1 and true;

{code}

However, calcite would not recognize that sql and says:
Caused by: org.apache.calcite.sql.validate.SqlValidatorException: Cannot apply 
'AND' to arguments of type ' AND '. Supported form(s): 
' AND '
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at 
org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463)
at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:572)
... 27 more

So, I propose if we should introduce more type support for logical AND/OR




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Updated] (CALCITE-2328) Operand of Logical And/OR should support type like INT, DOUTLE not only boolean

2018-05-25 Thread yuqi (JIRA)

 [ 
https://issues.apache.org/jira/browse/CALCITE-2328?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2328:
--
Description: 
As far as i see , MySQL support the following sql

{code:java}
select id, name from tb where 1 and 1;
select id, name from tb where 1 and true;

{code}

However, calcite would not recognize that sql and says:

{code:java}
Caused by: org.apache.calcite.sql.validate.SqlValidatorException: Cannot apply 
'AND' to arguments of type ' AND '. Supported form(s): 
' AND '
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at 
org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463)
at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:572)
... 27 more
{code}


So, I propose if we should introduce more type support for logical AND/OR


  was:
As far as i see , MySQL support the following sql

{code:java}
select id, name from tb where 1 and 1;
select id, name from tb where 1 and true;

{code}

However, calcite would not recognize that sql and says:
Caused by: org.apache.calcite.sql.validate.SqlValidatorException: Cannot apply 
'AND' to arguments of type ' AND '. Supported form(s): 
' AND '
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at 
org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463)
at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:572)
... 27 more

So, I propose if we should introduce more type support for logical AND/OR



> Operand of Logical And/OR should support type like INT, DOUTLE not only 
> boolean
> ---
>
> Key: CALCITE-2328
> URL: https://issues.apache.org/jira/browse/CALCITE-2328
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.16.0
>Reporter: yuqi
>Assignee: Julian Hyde
>Priority: Minor
> Fix For: 1.17.0
>
>
> As far as i see , MySQL support the following sql
> {code:java}
> select id, name from tb where 1 and 1;
> select id, name from tb where 1 and true;
> {code}
> However, calcite would not recognize that sql and says:
> {code:java}
> Caused by: org.apache.calcite.sql.validate.SqlValidatorException: Cannot 
> apply 'AND' to arguments of type ' AND '. Supported 
> form(s): ' AND '
>   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>   at 
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
>   at 
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
>   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
>   at 
> org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463)
>   at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:572)
>   ... 27 more
> {code}
> So, I propose if we should introduce more type support for logical AND/OR



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-2311) case when returns redundant white space

2018-05-15 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2311?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16476707#comment-16476707
 ] 

yuqi commented on CALCITE-2311:
---

It's depends on the type of the column that the value will be given to.  I 
guess you intend to put the result of 
{code:java}
case when id>0 then 'a' else 'abc' end{code}
to a column with type of char(3), As far as i know, char(3) will always take 3 
bytes no matter the length of real value is 3 or not. 'a' will be converted to 
'a  ' and 'abcde' will be changed to 'abc'.

> case when returns redundant white space
> ---
>
> Key: CALCITE-2311
> URL: https://issues.apache.org/jira/browse/CALCITE-2311
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.12.0
>Reporter: pengzhiwei
>Assignee: Julian Hyde
>Priority: Major
> Fix For: 1.17.0
>
>
> If the case-when expression has two branches which returns string 
> literal,redundant white space will append to the short string literal  after 
> the ReduceExpressionsRule. For example:
> {code:java}
> case when id>0 then 'a' else 'abc' end{code}
> will actually be convert to 
> {code:java}
> case when id>0 then 'a  ' else 'abc' end{code}
>  
> The reason is that the type of  'a' is CHAR(1),but CHAR(3) for 'abc',so the 
> return type of  the case-when is CHAR(3). The RexBuilder#ensureType() method 
> append a cast convertion for 'a' to cast it to CHAR(3) type.The 
> ReduceExpressionsRule execute the cast convertion which fill two whilte space 
> to 'a'.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Comment Edited] (CALCITE-2273) misinterpreted

2018-04-28 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2273?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16457488#comment-16457488
 ] 

yuqi edited comment on CALCITE-2273 at 4/28/18 9:31 AM:


As far as i see, unicode that have length more than 4 will be converted to two 
normal unicode with length of 4
{code:java}
U&'\01'{code}
will be covert to
{code:java}
U&'\D833\DCCC'{code}
So, if you want to describe unicode like the above value, use the latter instead


was (Author: yuqi):
As far as i see, unicode that have length more than 4 will be converted to two 
normal unicode with length of 4
{code:java}
U&'\01'{code}
will be covert to '\uD833\uDCCC'.

>  misinterpreted 
> --
>
> Key: CALCITE-2273
> URL: https://issues.apache.org/jira/browse/CALCITE-2273
> Project: Calcite
>  Issue Type: Bug
>Reporter: Zhong Yu
>Assignee: Julian Hyde
>Priority: Major
>
>  
>  
> The following string literal is accepted by Calcite parser, but the result 
> value in Java is incorrect
> {code:java}
> U&'\+01F600'{code}
>  
> Cause: currently, SqlLiteral.unescapeUnicode() only intends to handle 4-digit 
> unicode escape value in the form of "\xyzw" . When given the 6-digit form 
> "\+xyzwrs", it parses the four chars "+xyz" as a hexadecimal, which succeeds 
> too. Therefore the result value contains 4 characters: [\u0xyz, w, r, s]



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Comment Edited] (CALCITE-2273) misinterpreted

2018-04-28 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2273?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16457488#comment-16457488
 ] 

yuqi edited comment on CALCITE-2273 at 4/28/18 9:29 AM:


As far as i see, unicode that have length more than 4 will be converted to two 
normal unicode with length of 4
{code:java}
U&'\01'{code}
will be covert to '\uD833\uDCCC'.


was (Author: yuqi):
As far as i see, unicode that have length more than 4 will be converted to two 
normal unicode with length of 4
U&'\01'
will be covert to '\uD833\uDCCC'.

>  misinterpreted 
> --
>
> Key: CALCITE-2273
> URL: https://issues.apache.org/jira/browse/CALCITE-2273
> Project: Calcite
>  Issue Type: Bug
>Reporter: Zhong Yu
>Assignee: Julian Hyde
>Priority: Major
>
>  
>  
> The following string literal is accepted by Calcite parser, but the result 
> value in Java is incorrect
> {code:java}
> U&'\+01F600'{code}
>  
> Cause: currently, SqlLiteral.unescapeUnicode() only intends to handle 4-digit 
> unicode escape value in the form of "\xyzw" . When given the 6-digit form 
> "\+xyzwrs", it parses the four chars "+xyz" as a hexadecimal, which succeeds 
> too. Therefore the result value contains 4 characters: [\u0xyz, w, r, s]



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-2273) misinterpreted

2018-04-28 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2273?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16457488#comment-16457488
 ] 

yuqi commented on CALCITE-2273:
---

As far as i see, unicode that have length more than 4 will be converted to two 
normal unicode with length of 4
U&'\01'
will be covert to '\uD833\uDCCC'.

>  misinterpreted 
> --
>
> Key: CALCITE-2273
> URL: https://issues.apache.org/jira/browse/CALCITE-2273
> Project: Calcite
>  Issue Type: Bug
>Reporter: Zhong Yu
>Assignee: Julian Hyde
>Priority: Major
>
>  
>  
> The following string literal is accepted by Calcite parser, but the result 
> value in Java is incorrect
> {code:java}
> U&'\+01F600'{code}
>  
> Cause: currently, SqlLiteral.unescapeUnicode() only intends to handle 4-digit 
> unicode escape value in the form of "\xyzw" . When given the 6-digit form 
> "\+xyzwrs", it parses the four chars "+xyz" as a hexadecimal, which succeeds 
> too. Therefore the result value contains 4 characters: [\u0xyz, w, r, s]



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-1882) Can't obtain the user defined aggregate function such as sum,avg by calcite

2018-04-19 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-1882?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16445123#comment-16445123
 ] 

yuqi commented on CALCITE-1882:
---

Ok, [~vladimirsitnikov] , If you have time, please help to review the code. 

> Can't obtain the user defined aggregate function such as sum,avg by calcite
> ---
>
> Key: CALCITE-1882
> URL: https://issues.apache.org/jira/browse/CALCITE-1882
> Project: Calcite
>  Issue Type: Bug
>Affects Versions: 1.12.0
>Reporter: yuemeng
>Assignee: yuemeng
>Priority: Critical
>
> If we want to register a sum or avg aggregate function to deal with different 
> data type such as sum(double) ,we implement a SqlUserDefinedAggFunction and 
> register with name sum,but when we execute a sql like:
> {code}
> select id,sum(payment) from table test group by id
> {code}
> in fact,it always give the SqlSumAggFunction function which builtin by 
> calcite,never find the exactly function which we register by ourself.
> During sql parse process,method createCall in SqlAbstractParserImpl will be 
> called,
> {code}
>   protected SqlCall createCall(
>   SqlIdentifier funName,
>   SqlParserPos pos,
>   SqlFunctionCategory funcType,
>   SqlLiteral functionQualifier,
>   SqlNode[] operands) {
> SqlOperator fun = null;
> // First, try a half-hearted resolution as a builtin function.
> // If we find one, use it; this will guarantee that we
> // preserve the correct syntax (i.e. don't quote builtin function
> /// name when regenerating SQL).
> if (funName.isSimple()) {
>   final List list = Lists.newArrayList();
>   opTab.lookupOperatorOverloads(funName, funcType, SqlSyntax.FUNCTION, 
> list);//we lookup in SqlStdOperatorTable,and always find buidin function for 
> sum ,avg .eg
>   if (list.size() == 1) {
> fun = list.get(0);
>   }
> }
> // Otherwise, just create a placeholder function.  Later, during
> // validation, it will be resolved into a real function reference.
> if (fun == null) {
>   fun = new SqlUnresolvedFunction(funName, null, null, null, null,
>   funcType);
> }
> return fun.createCall(functionQualifier, pos, operands);
>   }
> {code}
> but the problem will be appear in deriveType,because of we get the 
> SqlSumAggFunction previously,and the sqlKind of SqlSumAggFunction is AVG,but 
> the sqlKind of sql user defined agg function (sum) which we register by 
> ourself is OTHER_FUNCTION,so it filter out our sum function.
> {code}
>   private static Iterator
>   filterOperatorRoutinesByKind(Iterator routines,
>   final SqlKind sqlKind) {
> return Iterators.filter(routines,
> new PredicateImpl() {
>   public boolean test(SqlOperator input) {
> return input.getKind() == sqlKind;
>   }
> });
>   }
> {code}
> that cause we never obtain sum function which registered by user .



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-1882) Can't obtain the user defined aggregate function such as sum,avg by calcite

2018-04-19 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-1882?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16444071#comment-16444071
 ] 

yuqi commented on CALCITE-1882:
---

[~julianhyde]

Code have updated, Could you help to review it ? thanks

> Can't obtain the user defined aggregate function such as sum,avg by calcite
> ---
>
> Key: CALCITE-1882
> URL: https://issues.apache.org/jira/browse/CALCITE-1882
> Project: Calcite
>  Issue Type: Bug
>Affects Versions: 1.12.0
>Reporter: yuemeng
>Assignee: yuemeng
>Priority: Critical
>
> If we want to register a sum or avg aggregate function to deal with different 
> data type such as sum(double) ,we implement a SqlUserDefinedAggFunction and 
> register with name sum,but when we execute a sql like:
> {code}
> select id,sum(payment) from table test group by id
> {code}
> in fact,it always give the SqlSumAggFunction function which builtin by 
> calcite,never find the exactly function which we register by ourself.
> During sql parse process,method createCall in SqlAbstractParserImpl will be 
> called,
> {code}
>   protected SqlCall createCall(
>   SqlIdentifier funName,
>   SqlParserPos pos,
>   SqlFunctionCategory funcType,
>   SqlLiteral functionQualifier,
>   SqlNode[] operands) {
> SqlOperator fun = null;
> // First, try a half-hearted resolution as a builtin function.
> // If we find one, use it; this will guarantee that we
> // preserve the correct syntax (i.e. don't quote builtin function
> /// name when regenerating SQL).
> if (funName.isSimple()) {
>   final List list = Lists.newArrayList();
>   opTab.lookupOperatorOverloads(funName, funcType, SqlSyntax.FUNCTION, 
> list);//we lookup in SqlStdOperatorTable,and always find buidin function for 
> sum ,avg .eg
>   if (list.size() == 1) {
> fun = list.get(0);
>   }
> }
> // Otherwise, just create a placeholder function.  Later, during
> // validation, it will be resolved into a real function reference.
> if (fun == null) {
>   fun = new SqlUnresolvedFunction(funName, null, null, null, null,
>   funcType);
> }
> return fun.createCall(functionQualifier, pos, operands);
>   }
> {code}
> but the problem will be appear in deriveType,because of we get the 
> SqlSumAggFunction previously,and the sqlKind of SqlSumAggFunction is AVG,but 
> the sqlKind of sql user defined agg function (sum) which we register by 
> ourself is OTHER_FUNCTION,so it filter out our sum function.
> {code}
>   private static Iterator
>   filterOperatorRoutinesByKind(Iterator routines,
>   final SqlKind sqlKind) {
> return Iterators.filter(routines,
> new PredicateImpl() {
>   public boolean test(SqlOperator input) {
> return input.getKind() == sqlKind;
>   }
> });
>   }
> {code}
> that cause we never obtain sum function which registered by user .



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2018-04-07 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16429601#comment-16429601
 ] 

yuqi commented on CALCITE-2053:
---

[~julianhyde], Could you take time to this issue and look the change is 
reasonable ?

> Overloaded user-defined functions that have Double and BigDecimal arguments 
> will goes wrong
> ---
>
> Key: CALCITE-2053
> URL: https://issues.apache.org/jira/browse/CALCITE-2053
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.15.0
>Reporter: yuqi
>Assignee: Julian Hyde
>Priority: Major
>
> We add the following udf method in Smalls.AllTypesFunction
> {code:java}
>public double toDouble(BigDecimal var) {
>   return var.doubleValue();
>} 
>public double toDouble(Double var) {
>   return var;
> }
>
> {code}
> when test it :
> {code:java}
> @Test
> public void testBigDecimalAndLong() {
>  final CalciteAssert.AssertThat with = withUdf();
>  with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))")
>  .returns("EXPR$0=1.0\n");
> }{code}
> where price is a double value in table tb, exception occurs:
> {code:java}
> java.lang.AssertionError: DECIMAL(19, 0) at 
> org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
>  at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626) at 
> org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592)
>  at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446) at 
> org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371) at 
> org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245) at 
> org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5432)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5419)
>  at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591)
>  at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:236) at 
> org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5136)
>  at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at 
> org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:235) at 
> org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5136)
>  at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613)
>  at 
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553)
>  at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264) at 
> org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230) at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781)
>  at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:640)
>  at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:610)
>  at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:221)
>  at 
> org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603)
>  at 
> org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638)
>  at 
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149)
>  at 
> org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
>  at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:568) 
> at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1346)
>  at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1329)
>  at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1293)
>  at org.apache.calcite.test.UdfTest.testBigDecimalAndLong(UdfTest.java:891) 
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  at 

[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2018-03-12 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16394854#comment-16394854
 ] 

yuqi commented on CALCITE-2053:
---

[~julianhyde] Is this change look OK?

> Overloaded user-defined functions that have Double and BigDecimal arguments 
> will goes wrong
> ---
>
> Key: CALCITE-2053
> URL: https://issues.apache.org/jira/browse/CALCITE-2053
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.15.0
>Reporter: yuqi
>Assignee: Julian Hyde
>Priority: Major
>
> We add the following udf method in Smalls.AllTypesFunction
> {code:java}
>public double toDouble(BigDecimal var) {
>   return var.doubleValue();
>} 
>public double toDouble(Double var) {
>   return var;
> }
>
> {code}
> when test it :
> {code:java}
> @Test
> public void testBigDecimalAndLong() {
>  final CalciteAssert.AssertThat with = withUdf();
>  with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))")
>  .returns("EXPR$0=1.0\n");
> }{code}
> where price is a double value in table tb, exception occurs:
> {code:java}
> java.lang.AssertionError: DECIMAL(19, 0) at 
> org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
>  at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626) at 
> org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592)
>  at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446) at 
> org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371) at 
> org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245) at 
> org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5432)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5419)
>  at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591)
>  at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:236) at 
> org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5136)
>  at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at 
> org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:235) at 
> org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5136)
>  at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613)
>  at 
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553)
>  at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264) at 
> org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230) at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781)
>  at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:640)
>  at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:610)
>  at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:221)
>  at 
> org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603)
>  at 
> org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638)
>  at 
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149)
>  at 
> org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
>  at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:568) 
> at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1346)
>  at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1329)
>  at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1293)
>  at org.apache.calcite.test.UdfTest.testBigDecimalAndLong(UdfTest.java:891) 
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  at java.lang.reflect.Method.invoke(Method.java:497) at 
> 

[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2018-02-07 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16356590#comment-16356590
 ] 

yuqi commented on CALCITE-2053:
---

Thanks for your time.

> Overloaded user-defined functions that have Double and BigDecimal arguments 
> will goes wrong
> ---
>
> Key: CALCITE-2053
> URL: https://issues.apache.org/jira/browse/CALCITE-2053
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.15.0
>Reporter: yuqi
>Assignee: Julian Hyde
>Priority: Major
>
> We add the following udf method in Smalls.AllTypesFunction
> {code:java}
>public double toDouble(BigDecimal var) {
>   return var.doubleValue();
>} 
>public double toDouble(Double var) {
>   return var;
> }
>
> {code}
> when test it :
> {code:java}
> @Test
> public void testBigDecimalAndLong() {
>  final CalciteAssert.AssertThat with = withUdf();
>  with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))")
>  .returns("EXPR$0=1.0\n");
> }{code}
> where price is a double value in table tb, exception occurs:
> {code:java}
> java.lang.AssertionError: DECIMAL(19, 0) at 
> org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
>  at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626) at 
> org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592)
>  at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446) at 
> org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371) at 
> org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245) at 
> org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5432)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5419)
>  at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591)
>  at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:236) at 
> org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5136)
>  at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at 
> org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:235) at 
> org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5136)
>  at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613)
>  at 
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553)
>  at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264) at 
> org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230) at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781)
>  at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:640)
>  at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:610)
>  at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:221)
>  at 
> org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603)
>  at 
> org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638)
>  at 
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149)
>  at 
> org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
>  at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:568) 
> at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1346)
>  at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1329)
>  at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1293)
>  at org.apache.calcite.test.UdfTest.testBigDecimalAndLong(UdfTest.java:891) 
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  at java.lang.reflect.Method.invoke(Method.java:497) at 
> 

[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2018-02-04 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16351794#comment-16351794
 ] 

yuqi commented on CALCITE-2053:
---

En, FLOAT should take into consideration if we want to solve problem like this 
completely, Changes have been make. Still, I can't understand why calcite treat 
float in java as SqlTypeName.REAL in file JavaToSqlTypeConversionRules, see 
below
{code:java}
  ...
 .put(Float.class, SqlTypeName.REAL)
 .put(float.class, SqlTypeName.REAL)

{code}
and what's the type in java thats equals SqlTypeName.FLOAT in calcite? 
[~julianhyde]

> Overloaded user-defined functions that have Double and BigDecimal arguments 
> will goes wrong
> ---
>
> Key: CALCITE-2053
> URL: https://issues.apache.org/jira/browse/CALCITE-2053
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.15.0
>Reporter: yuqi
>Assignee: Julian Hyde
>Priority: Major
>
> We add the following udf method in Smalls.AllTypesFunction
> {code:java}
>public double toDouble(BigDecimal var) {
>   return var.doubleValue();
>} 
>public double toDouble(Double var) {
>   return var;
> }
>
> {code}
> when test it :
> {code:java}
> @Test
> public void testBigDecimalAndLong() {
>  final CalciteAssert.AssertThat with = withUdf();
>  with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))")
>  .returns("EXPR$0=1.0\n");
> }{code}
> where price is a double value in table tb, exception occurs:
> {code:java}
> java.lang.AssertionError: DECIMAL(19, 0) at 
> org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
>  at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626) at 
> org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592)
>  at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446) at 
> org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371) at 
> org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245) at 
> org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5432)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5419)
>  at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591)
>  at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:236) at 
> org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5136)
>  at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at 
> org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:235) at 
> org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5136)
>  at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613)
>  at 
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553)
>  at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264) at 
> org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230) at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781)
>  at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:640)
>  at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:610)
>  at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:221)
>  at 
> org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603)
>  at 
> org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638)
>  at 
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149)
>  at 
> org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
>  at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:568) 
> at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1346)
>  at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1329)
>  at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1293)
>  at 

[jira] [Updated] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2018-02-03 Thread yuqi (JIRA)

 [ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2053:
--
Affects Version/s: (was: 1.13.0)

> Overloaded user-defined functions that have Double and BigDecimal arguments 
> will goes wrong
> ---
>
> Key: CALCITE-2053
> URL: https://issues.apache.org/jira/browse/CALCITE-2053
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.15.0
>Reporter: yuqi
>Assignee: Julian Hyde
>Priority: Major
>
> We add the following udf method in Smalls.AllTypesFunction
> {code:java}
>public double toDouble(BigDecimal var) {
>   return var.doubleValue();
>} 
>public double toDouble(Double var) {
>   return var;
> }
>
> {code}
> when test it :
> {code:java}
> @Test
> public void testBigDecimalAndLong() {
>  final CalciteAssert.AssertThat with = withUdf();
>  with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))")
>  .returns("EXPR$0=1.0\n");
> }{code}
> where price is a double value in table tb, exception occurs:
> {code:java}
> java.lang.AssertionError: DECIMAL(19, 0) at 
> org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
>  at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626) at 
> org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592)
>  at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446) at 
> org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371) at 
> org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245) at 
> org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5432)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5419)
>  at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591)
>  at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:236) at 
> org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5136)
>  at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at 
> org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:235) at 
> org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5136)
>  at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613)
>  at 
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553)
>  at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264) at 
> org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230) at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781)
>  at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:640)
>  at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:610)
>  at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:221)
>  at 
> org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603)
>  at 
> org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638)
>  at 
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149)
>  at 
> org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
>  at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:568) 
> at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1346)
>  at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1329)
>  at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1293)
>  at org.apache.calcite.test.UdfTest.testBigDecimalAndLong(UdfTest.java:891) 
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  at java.lang.reflect.Method.invoke(Method.java:497) at 
> 

[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2018-02-02 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16350178#comment-16350178
 ] 

yuqi commented on CALCITE-2053:
---

Ok, I  change 
{code:java}
.put(SqlTypeName.DOUBLE, numeric(SqlTypeName.DOUBLE)){code}
to
{code:java}
.put(SqlTypeName.DOUBLE, list(SqlTypeName.DOUBLE, SqlTypeName.DECIMAL)){code}
but, i do think it's a little hard-code.  what's your opinion ? [~julianhyde]

> Overloaded user-defined functions that have Double and BigDecimal arguments 
> will goes wrong
> ---
>
> Key: CALCITE-2053
> URL: https://issues.apache.org/jira/browse/CALCITE-2053
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.13.0, 1.15.0
>Reporter: yuqi
>Assignee: Julian Hyde
>Priority: Major
>
> We add the following udf method in Smalls.AllTypesFunction
> {code:java}
>public double toDouble(BigDecimal var) {
>   return var.doubleValue();
>} 
>public double toDouble(Double var) {
>   return var;
> }
>
> {code}
> when test it :
> {code:java}
> @Test
> public void testBigDecimalAndLong() {
>  final CalciteAssert.AssertThat with = withUdf();
>  with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))")
>  .returns("EXPR$0=1.0\n");
> }{code}
> where price is a double value in table tb, exception occurs:
> {code:java}
> java.lang.AssertionError: DECIMAL(19, 0) at 
> org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
>  at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626) at 
> org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592)
>  at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446) at 
> org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371) at 
> org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245) at 
> org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5432)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5419)
>  at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591)
>  at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:236) at 
> org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5136)
>  at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at 
> org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:235) at 
> org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5136)
>  at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613)
>  at 
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553)
>  at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264) at 
> org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230) at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781)
>  at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:640)
>  at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:610)
>  at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:221)
>  at 
> org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603)
>  at 
> org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638)
>  at 
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149)
>  at 
> org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
>  at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:568) 
> at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1346)
>  at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1329)
>  at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1293)
>  at org.apache.calcite.test.UdfTest.testBigDecimalAndLong(UdfTest.java:891) 
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at 
> 

[jira] [Updated] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2018-02-01 Thread yuqi (JIRA)

 [ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2053:
--
Affects Version/s: 1.15.0

> Overloaded user-defined functions that have Double and BigDecimal arguments 
> will goes wrong
> ---
>
> Key: CALCITE-2053
> URL: https://issues.apache.org/jira/browse/CALCITE-2053
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.13.0, 1.15.0
>Reporter: yuqi
>Assignee: Julian Hyde
>Priority: Major
>
> We add the following udf method in Smalls.AllTypesFunction
> {code:java}
>public double toDouble(BigDecimal var) {
>   return var.doubleValue();
>} 
>public double toDouble(Double var) {
>   return var;
> }
>
> {code}
> when test it :
> {code:java}
> @Test
> public void testBigDecimalAndLong() {
>  final CalciteAssert.AssertThat with = withUdf();
>  with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))")
>  .returns("EXPR$0=1.0\n");
> }{code}
> where price is a double value in table tb, exception occurs:
> {code:java}
> java.lang.AssertionError: DECIMAL(19, 0) at 
> org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
>  at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626) at 
> org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592)
>  at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446) at 
> org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371) at 
> org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245) at 
> org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5432)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5419)
>  at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591)
>  at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:236) at 
> org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5136)
>  at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at 
> org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:235) at 
> org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5136)
>  at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613)
>  at 
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553)
>  at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264) at 
> org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230) at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781)
>  at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:640)
>  at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:610)
>  at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:221)
>  at 
> org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603)
>  at 
> org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638)
>  at 
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149)
>  at 
> org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
>  at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:568) 
> at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1346)
>  at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1329)
>  at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1293)
>  at org.apache.calcite.test.UdfTest.testBigDecimalAndLong(UdfTest.java:891) 
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  at java.lang.reflect.Method.invoke(Method.java:497) at 
> 

[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2018-01-31 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16348015#comment-16348015
 ] 

yuqi commented on CALCITE-2053:
---

[~julianhyde] , I confirm this,  here is my MR 
[https://github.com/apache/calcite/pull/619] , please help to review this PR if 
you have time, thanks

> Overloaded user-defined functions that have Double and BigDecimal arguments 
> will goes wrong
> ---
>
> Key: CALCITE-2053
> URL: https://issues.apache.org/jira/browse/CALCITE-2053
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.13.0
>Reporter: yuqi
>Assignee: Julian Hyde
>Priority: Major
>
> We add the following udf method in Smalls.AllTypesFunction
> {code:java}
>public double toDouble(BigDecimal var) {
>   return var.doubleValue();
>} 
>public double toDouble(Double var) {
>   return var;
> }
>
> {code}
> when test it :
> {code:java}
> @Test
> public void testBigDecimalAndLong() {
>  final CalciteAssert.AssertThat with = withUdf();
>  with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))")
>  .returns("EXPR$0=1.0\n");
> }{code}
> where price is a double value in table tb, exception occurs:
> {code:java}
> java.lang.AssertionError: DECIMAL(19, 0) at 
> org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
>  at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626) at 
> org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592)
>  at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446) at 
> org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371) at 
> org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245) at 
> org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5432)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5419)
>  at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591)
>  at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:236) at 
> org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5136)
>  at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at 
> org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:235) at 
> org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5136)
>  at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903)
>  at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613)
>  at 
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553)
>  at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264) at 
> org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230) at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781)
>  at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:640)
>  at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:610)
>  at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:221)
>  at 
> org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603)
>  at 
> org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638)
>  at 
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149)
>  at 
> org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
>  at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:568) 
> at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1346)
>  at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1329)
>  at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1293)
>  at org.apache.calcite.test.UdfTest.testBigDecimalAndLong(UdfTest.java:891) 
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> at 
> 

[jira] [Updated] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2018-01-31 Thread yuqi (JIRA)

 [ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2053:
--
Description: 
We add the following udf method in Smalls.AllTypesFunction
{code:java}
   public double toDouble(BigDecimal var) {
  return var.doubleValue();
   } 
   public double toDouble(Double var) {
  return var;
}
   
{code}
when test it :
{code:java}
@Test
public void testBigDecimalAndLong() {
 final CalciteAssert.AssertThat with = withUdf();
 with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))")
 .returns("EXPR$0=1.0\n");
}{code}
where price is a double value in table tb, exception occurs:
{code:java}
java.lang.AssertionError: DECIMAL(19, 0) at 
org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
 at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626) at 
org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592) 
at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446) at 
org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371) at 
org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245) at 
org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223) at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5432)
 at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5419)
 at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138) at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606)
 at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591)
 at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:236) at 
org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407) at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5136)
 at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at 
org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:235) at 
org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407) at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5136)
 at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115) at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:903)
 at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:613)
 at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553)
 at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264) at 
org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230) at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:781)
 at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:640)
 at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:610)
 at 
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:221)
 at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603)
 at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638)
 at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149)
 at 
org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
 at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:568) 
at 
org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1346)
 at 
org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1329)
 at 
org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1293)
 at org.apache.calcite.test.UdfTest.testBigDecimalAndLong(UdfTest.java:891) at 
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:497) at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
 at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
 at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
 at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
 at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
 at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at 
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at 

[jira] [Updated] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2018-01-31 Thread yuqi (JIRA)

 [ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2053:
--
Description: 
We add the following udf method in Smalls.AllTypesFunction
{code:java}
   public double toDouble(BigDecimal var) {
  return var.doubleValue();
   } 
   public double toDouble(Double var) {
  return var;
}
   
{code}
when test it :
{code:java}
@Test
public void testBigDecimalAndLong() {
 final CalciteAssert.AssertThat with = withUdf();
 with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))")
 .returns("EXPR$0=1.0\n");
}{code}
where price is a double value in table tb, exception occurs:
{code:java}
java.lang.AssertionError
at 
org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:153)
at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:627)
at 
org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:593)
at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:447)
at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371)
at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245)
at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5053)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5040)
at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:137)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1588)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1573)
at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:225)
at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:4764)
at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:114)
at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:224)
at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:4764)
at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:114)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:895)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:605)
at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:550)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:228)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:784)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:639)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:609)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:214)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603)
at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638)
at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149)
at 
org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
java.lang.AssertionError: DECIMAL(19, 0)

at 
org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626)
at 
org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592)
at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446)
at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371)
at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245)
at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5432)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5419)
at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1606)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1591)
at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:236)
at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5136)
at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115)
at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:235)
at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
at 

[jira] [Updated] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2018-01-31 Thread yuqi (JIRA)

 [ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2053:
--
Description: 
We add the following udf method in Smalls.AllTypesFunction
{code:java}
   public double toDouble(BigDecimal var) {
  return var.doubleValue();
   } 
   public double toDouble(Double var) {
  return var;
}
   
{code}
when test it :
{code:java}
@Test
public void testBigDecimalAndLong() {
 final CalciteAssert.AssertThat with = withUdf();
 with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))")
 .returns("EXPR$0=1.0\n");
}{code}
where price is a double value in table tb, exception occurs:
{code:java}
java.lang.AssertionError
at 
org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:153)
at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:627)
at 
org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:593)
at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:447)
at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371)
at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245)
at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5053)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5040)
at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:137)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1588)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1573)
at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:225)
at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:4764)
at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:114)
at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:224)
at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:4764)
at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:114)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:895)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:605)
at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:550)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:228)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:784)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:639)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:609)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:214)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603)
at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638)
at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149)
at 
org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
{code}

  was:
We add the following udf method in Smalls.AllTypesFunction
{code:java}
   public double toDouble(BigDecimal var) { return var.doubleValue(); } 
   public double toDouble(Double var) {
  return var;
}
   
{code}
when test it :
{code:java}
@Test
public void testBigDecimalAndLong() {
 final CalciteAssert.AssertThat with = withUdf();
 with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))")
 .returns("EXPR$0=1.0\n");
}{code}
where price is a double value in table tb, exception occurs:
{code:java}
java.lang.AssertionError
at 
org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:153)
at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:627)
at 
org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:593)
at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:447)
at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371)
at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245)
at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5053)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5040)
at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:137)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1588)
at 

[jira] [Updated] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2018-01-31 Thread yuqi (JIRA)

 [ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2053:
--
Description: 
We add the following udf method in Smalls.AllTypesFunction
{code:java}
public double toDouble(Double var) {
  return var;
}

 public double toDouble(BigDecimal var) {
  return var.doubleValue();
}
{code}
when test it :
{code:java}
@Test
public void testBigDecimalAndLong() {
 final CalciteAssert.AssertThat with = withUdf();
 with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))")
 .returns("EXPR$0=1.0\n");
}{code}
where price is a double value in table tb, exception occurs:
{code:java}
java.lang.AssertionError
at 
org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:153)
at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:627)
at 
org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:593)
at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:447)
at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371)
at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245)
at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5053)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5040)
at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:137)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1588)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1573)
at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:225)
at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:4764)
at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:114)
at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:224)
at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:4764)
at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:114)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:895)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:605)
at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:550)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:228)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:784)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:639)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:609)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:214)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603)
at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638)
at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149)
at 
org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
{code}

  was:
We define a udf function class have two function as follows 

{code:java}
public double toDouble(Double var) {
  return var;
}

 public double toDouble(BigDecimal var) {
  return var.doubleValue();
}
{code}

when use it in sql like:

{code:sql}
select sum(price) from tb;
{code}
where price is a double value in table tb, exception occurs:

{code:java}
java.lang.AssertionError: DECIMAL(19, 0)

at 
org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626)
at 
org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592)
at 
org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446)
at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371)
at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245)
at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5371)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5358)
at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1592)
at 

[jira] [Updated] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2018-01-31 Thread yuqi (JIRA)

 [ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

yuqi updated CALCITE-2053:
--
Description: 
We add the following udf method in Smalls.AllTypesFunction
{code:java}
   public double toDouble(BigDecimal var) { return var.doubleValue(); } 
   public double toDouble(Double var) {
  return var;
}
   
{code}
when test it :
{code:java}
@Test
public void testBigDecimalAndLong() {
 final CalciteAssert.AssertThat with = withUdf();
 with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))")
 .returns("EXPR$0=1.0\n");
}{code}
where price is a double value in table tb, exception occurs:
{code:java}
java.lang.AssertionError
at 
org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:153)
at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:627)
at 
org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:593)
at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:447)
at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371)
at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245)
at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5053)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5040)
at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:137)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1588)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1573)
at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:225)
at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:4764)
at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:114)
at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:224)
at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:4764)
at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:114)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:895)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:605)
at 
org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:550)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:228)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:784)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:639)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:609)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:214)
at 
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603)
at 
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638)
at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149)
at 
org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
{code}

  was:
We add the following udf method in Smalls.AllTypesFunction
{code:java}
public double toDouble(Double var) {
  return var;
}

 public double toDouble(BigDecimal var) {
  return var.doubleValue();
}
{code}
when test it :
{code:java}
@Test
public void testBigDecimalAndLong() {
 final CalciteAssert.AssertThat with = withUdf();
 with.query("values \"adhoc\".\"toDouble\"(cast(1.0 as double))")
 .returns("EXPR$0=1.0\n");
}{code}
where price is a double value in table tb, exception occurs:
{code:java}
java.lang.AssertionError
at 
org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:153)
at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:627)
at 
org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:593)
at org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:447)
at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371)
at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245)
at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5053)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5040)
at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:137)
at 
org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1588)
at 

[jira] [Commented] (CALCITE-1903) Support charset in LIKE expression

2017-11-22 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-1903?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16263683#comment-16263683
 ] 

yuqi commented on CALCITE-1903:
---

I see, thanks a lot

> Support charset in LIKE expression
> --
>
> Key: CALCITE-1903
> URL: https://issues.apache.org/jira/browse/CALCITE-1903
> Project: Calcite
>  Issue Type: Bug
>Reporter: Ted Yu
>Assignee: Julian Hyde
>
> From 
> http://search-hadoop.com/m/Flink/VkLeQbjp59T6PkF?subj=+How+can+I+set+charset+for+flink+sql+
> The following query
> {code}
> SELECT
>   'HIGH' AS LEVEL,
>   'Firewall uplink bandwidth exception:greater than 1' AS content,
>   `system.process.username`,
>   `system.process.memory.rss.bytes`
> FROM
>   test
> WHERE
>   `system.process.username` LIKE '%高危%'
> {code}
> produces the following:
> {code}
> Caused by: org.apache.calcite.runtime.CalciteException: Failed to encode 
> '%高危%' in character set 'ISO-8859-1'
>   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native 
> Method) ~[na:1.8.0_45]
>   at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown 
> Source) ~[na:1.8.0_45]
>   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown 
> Source) ~[na:1.8.0_45]
>   at java.lang.reflect.Constructor.newInstance(Unknown Source) 
> ~[na:1.8.0_45]
>   at 
> org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463) 
> ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:572) 
> ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at org.apache.calcite.util.NlsString.(NlsString.java:81) 
> ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at org.apache.calcite.rex.RexBuilder.makeLiteral(RexBuilder.java:864) 
> ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.rex.RexBuilder.makeCharLiteral(RexBuilder.java:1051) 
> ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.SqlNodeToRexConverterImpl.convertLiteral(SqlNodeToRexConverterImpl.java:117)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.visit(SqlToRelConverter.java:4408)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.visit(SqlToRelConverter.java:3787)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at org.apache.calcite.sql.SqlLiteral.accept(SqlLiteral.java:427) 
> ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.convertExpression(SqlToRelConverter.java:4321)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.StandardConvertletTable.convertExpressionList(StandardConvertletTable.java:968)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.StandardConvertletTable.convertCall(StandardConvertletTable.java:944)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.StandardConvertletTable.convertCall(StandardConvertletTable.java:928)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   ... 50 common frames omitted
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (CALCITE-1903) Support charset in LIKE expression

2017-11-22 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-1903?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16263653#comment-16263653
 ] 

yuqi commented on CALCITE-1903:
---

Ok, That closely depends on flink SQL, seems that for calcite, raw SQL still 
does not support non-ISO-8859-1 character

> Support charset in LIKE expression
> --
>
> Key: CALCITE-1903
> URL: https://issues.apache.org/jira/browse/CALCITE-1903
> Project: Calcite
>  Issue Type: Bug
>Reporter: Ted Yu
>Assignee: Julian Hyde
>
> From 
> http://search-hadoop.com/m/Flink/VkLeQbjp59T6PkF?subj=+How+can+I+set+charset+for+flink+sql+
> The following query
> {code}
> SELECT
>   'HIGH' AS LEVEL,
>   'Firewall uplink bandwidth exception:greater than 1' AS content,
>   `system.process.username`,
>   `system.process.memory.rss.bytes`
> FROM
>   test
> WHERE
>   `system.process.username` LIKE '%高危%'
> {code}
> produces the following:
> {code}
> Caused by: org.apache.calcite.runtime.CalciteException: Failed to encode 
> '%高危%' in character set 'ISO-8859-1'
>   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native 
> Method) ~[na:1.8.0_45]
>   at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown 
> Source) ~[na:1.8.0_45]
>   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown 
> Source) ~[na:1.8.0_45]
>   at java.lang.reflect.Constructor.newInstance(Unknown Source) 
> ~[na:1.8.0_45]
>   at 
> org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463) 
> ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:572) 
> ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at org.apache.calcite.util.NlsString.(NlsString.java:81) 
> ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at org.apache.calcite.rex.RexBuilder.makeLiteral(RexBuilder.java:864) 
> ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.rex.RexBuilder.makeCharLiteral(RexBuilder.java:1051) 
> ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.SqlNodeToRexConverterImpl.convertLiteral(SqlNodeToRexConverterImpl.java:117)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.visit(SqlToRelConverter.java:4408)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.visit(SqlToRelConverter.java:3787)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at org.apache.calcite.sql.SqlLiteral.accept(SqlLiteral.java:427) 
> ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.convertExpression(SqlToRelConverter.java:4321)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.StandardConvertletTable.convertExpressionList(StandardConvertletTable.java:968)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.StandardConvertletTable.convertCall(StandardConvertletTable.java:944)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.StandardConvertletTable.convertCall(StandardConvertletTable.java:928)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   ... 50 common frames omitted
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (CALCITE-1903) Support charset in LIKE expression

2017-11-22 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-1903?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16262141#comment-16262141
 ] 

yuqi commented on CALCITE-1903:
---

[~jark], is there is any solution about using chinese character ?

> Support charset in LIKE expression
> --
>
> Key: CALCITE-1903
> URL: https://issues.apache.org/jira/browse/CALCITE-1903
> Project: Calcite
>  Issue Type: Bug
>Reporter: Ted Yu
>Assignee: Julian Hyde
>
> From 
> http://search-hadoop.com/m/Flink/VkLeQbjp59T6PkF?subj=+How+can+I+set+charset+for+flink+sql+
> The following query
> {code}
> SELECT
>   'HIGH' AS LEVEL,
>   'Firewall uplink bandwidth exception:greater than 1' AS content,
>   `system.process.username`,
>   `system.process.memory.rss.bytes`
> FROM
>   test
> WHERE
>   `system.process.username` LIKE '%高危%'
> {code}
> produces the following:
> {code}
> Caused by: org.apache.calcite.runtime.CalciteException: Failed to encode 
> '%高危%' in character set 'ISO-8859-1'
>   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native 
> Method) ~[na:1.8.0_45]
>   at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown 
> Source) ~[na:1.8.0_45]
>   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown 
> Source) ~[na:1.8.0_45]
>   at java.lang.reflect.Constructor.newInstance(Unknown Source) 
> ~[na:1.8.0_45]
>   at 
> org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463) 
> ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:572) 
> ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at org.apache.calcite.util.NlsString.(NlsString.java:81) 
> ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at org.apache.calcite.rex.RexBuilder.makeLiteral(RexBuilder.java:864) 
> ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.rex.RexBuilder.makeCharLiteral(RexBuilder.java:1051) 
> ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.SqlNodeToRexConverterImpl.convertLiteral(SqlNodeToRexConverterImpl.java:117)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.visit(SqlToRelConverter.java:4408)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.visit(SqlToRelConverter.java:3787)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at org.apache.calcite.sql.SqlLiteral.accept(SqlLiteral.java:427) 
> ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.convertExpression(SqlToRelConverter.java:4321)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.StandardConvertletTable.convertExpressionList(StandardConvertletTable.java:968)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.StandardConvertletTable.convertCall(StandardConvertletTable.java:944)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   at 
> org.apache.calcite.sql2rel.StandardConvertletTable.convertCall(StandardConvertletTable.java:928)
>  ~[flink-table_2.11-1.3.1.jar:1.3.1]
>   ... 50 common frames omitted
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2017-11-19 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16258753#comment-16258753
 ] 

yuqi commented on CALCITE-2053:
---

yes, similar to CALCITE-1881, but it does exist and has not been fixed

> Overloaded user-defined functions that have Double and BigDecimal arguments 
> will goes wrong
> ---
>
> Key: CALCITE-2053
> URL: https://issues.apache.org/jira/browse/CALCITE-2053
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.13.0
>Reporter: yuqi
>Assignee: Julian Hyde
>
> We define a udf function class have two function as follows 
> {code:java}
> public double toDouble(Double var) {
>   return var;
> }
> 
>  public double toDouble(BigDecimal var) {
>   return var.doubleValue();
> }
> {code}
> when use it in sql like:
> {code:sql}
> select sum(price) from tb;
> {code}
> where price is a double value in table tb, exception occurs:
> {code:java}
> java.lang.AssertionError: DECIMAL(19, 0)
>   at 
> org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
>   at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626)
>   at 
> org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592)
>   at 
> org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446)
>   at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371)
>   at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245)
>   at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5371)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5358)
>   at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1592)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1577)
>   at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:236)
>   at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5081)
>   at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115)
>   at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:235)
>   at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5081)
>   at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:901)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:611)
>   at 
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:551)
>   at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:263)
>   at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:229)
>   at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:786)
>   at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:640)
>   at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:610)
>   at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:221)
>   at 
> org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:603)
>   at 
> org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638)
>   at 
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149)
>   at 
> org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
>   at 
> org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:564)
>   at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1337)
>   at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1320)
>   at 
> org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1284)
>   at 
> org.apache.calcite.test.UdfTest.testDoubleAndDecimal(UdfTest.java:896)
>   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>   at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>   at 
> 

[jira] [Comment Edited] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2017-11-15 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16253170#comment-16253170
 ] 

yuqi edited comment on CALCITE-2053 at 11/15/17 9:29 AM:
-

The problem is that  in function filterRoutinesByParameterType, calcite do 
think decimal(bigdecimal in java)  can transfer to double and vice versa(see 
SqlTypeAssignmentRules.java), however in function 
filterRoutinesByTypePrecedence,according to number type precedence list in 
SqlTypeExplicitPrecedentList.java, decimal value can to cast to decimal and 
double and double value can only be cast to double, this is why this problem 
exist.
My points to solve the problem are as follows:
1. we can change function  containsType in class SqlTypeExplicitPrecedentList, 
When containsType return false, containsType directly return a positive values 
which means  the second parameter does't precedent to the first one, thus best 
match parameter is still the former.
2. we can also change the precedent list in SqlTypeExplicitPrecedentList, what 
puzzle me is that how to choose the sequence of Decimal and Double ? now 
decimal is in front of double, double value can't cast to decimal, if put 
decimal after double then decimal, decimal value can't cast to double.

What's your opinion about this problem, suggestions are  welcome [~julianhyde], 
thanks


was (Author: yuqi):
The problem is that  in function filterRoutinesByParameterType, calcite do 
think decimal(bigdecimal in java)  can transfer to double and vice versa(see 
SqlTypeAssignmentRules.java), however in function filterRoutinesByTypePrecedence
, according to number type precedence list in SqlTypeExplicitPrecedentList.java
, decimal value can to cast to decimal and double and double value can only be 
cast to double, this is why this problem exist.
My points to solve the problem are as follows:
1. we can change function  
containsType 
in class 
SqlTypeExplicitPrecedentList
, When containsType return false, containsType directly return a positive 
values which means  the second parameter does't precedent to the first one, 
thus best match parameter is still the former.
2. we can also change the precedent list in 
SqlTypeExplicitPrecedentList
, what puzzle me is that how to choose the sequence of Decimal and Double ? now 
decimal is in front of double, double value can't cast to decimal, if put 
decimal after double then decimal, decimal value can't cast to double.

What's your opinion about this problem, suggestions are  welcome [~julianhyde], 
thanks

> Overloaded user-defined functions that have Double and BigDecimal arguments 
> will goes wrong
> ---
>
> Key: CALCITE-2053
> URL: https://issues.apache.org/jira/browse/CALCITE-2053
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.13.0
>Reporter: yuqi
>Assignee: Julian Hyde
> Fix For: 1.14.0
>
>
> We define a udf function class have two function as follows 
> {code:java}
> public double toDouble(Double var) {
>   return var;
> }
> 
>  public double toDouble(BigDecimal var) {
>   return var.doubleValue();
> }
> {code}
> when use it in sql like:
> {code:sql}
> select sum(price) from tb;
> {code}
> where price is a double value in table tb, exception occurs:
> {code:java}
> java.lang.AssertionError: DECIMAL(19, 0)
>   at 
> org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
>   at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626)
>   at 
> org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592)
>   at 
> org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446)
>   at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371)
>   at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245)
>   at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5371)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5358)
>   at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1592)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1577)
>   at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:236)
>   at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5081)
>   at 

[jira] [Comment Edited] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2017-11-15 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16253170#comment-16253170
 ] 

yuqi edited comment on CALCITE-2053 at 11/15/17 9:28 AM:
-

The problem is that  in function filterRoutinesByParameterType, calcite do 
think decimal(bigdecimal in java)  can transfer to double and vice versa(see 
SqlTypeAssignmentRules.java), however in function filterRoutinesByTypePrecedence
, according to number type precedence list in SqlTypeExplicitPrecedentList.java
, decimal value can to cast to decimal and double and double value can only be 
cast to double, this is why this problem exist.
My points to solve the problem are as follows:
1. we can change function  
containsType 
in class 
SqlTypeExplicitPrecedentList
, When containsType return false, containsType directly return a positive 
values which means  the second parameter does't precedent to the first one, 
thus best match parameter is still the former.
2. we can also change the precedent list in 
SqlTypeExplicitPrecedentList
, what puzzle me is that how to choose the sequence of Decimal and Double ? now 
decimal is in front of double, double value can't cast to decimal, if put 
decimal after double then decimal, decimal value can't cast to double.

What's your opinion about this problem, suggestions are  welcome [~julianhyde], 
thanks


was (Author: yuqi):
The problem is that  in function 
filterRoutinesByParameterType
 , calcite do think decimal(bigdecimal in java)  can transfer to double and 
vice versa(see 

SqlTypeAssignmentRules.java
{code}
) 
however in function 
{code:java}
filterRoutinesByTypePrecedence
{code}
, according to number type precedence list in 
{code:java}
SqlTypeExplicitPrecedentList.java
{code}
,  decimal value can to cast to decimal and double and double value can only be 
cast to double, this is why this problem exist.
My points to solve the problem are as follows:
1. we can change function  
{code:java}
containsType 
{code}
in class 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, When containsType return false, containsType directly return a positive 
values which means  the second parameter does't precedent to the first one, 
thus best match parameter is still the former.
2. we can also change the precedent list in 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, what puzzle me is that how to choose the sequence of Decimal and Double ? now 
decimal is in front of double, double value can't cast to decimal, if put 
decimal after double then decimal, decimal value can't cast to double.

What's your opinion about this problem, suggestions are  welcome [~julianhyde], 
thanks

> Overloaded user-defined functions that have Double and BigDecimal arguments 
> will goes wrong
> ---
>
> Key: CALCITE-2053
> URL: https://issues.apache.org/jira/browse/CALCITE-2053
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.13.0
>Reporter: yuqi
>Assignee: Julian Hyde
> Fix For: 1.14.0
>
>
> We define a udf function class have two function as follows 
> {code:java}
> public double toDouble(Double var) {
>   return var;
> }
> 
>  public double toDouble(BigDecimal var) {
>   return var.doubleValue();
> }
> {code}
> when use it in sql like:
> {code:sql}
> select sum(price) from tb;
> {code}
> where price is a double value in table tb, exception occurs:
> {code:java}
> java.lang.AssertionError: DECIMAL(19, 0)
>   at 
> org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
>   at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626)
>   at 
> org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592)
>   at 
> org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446)
>   at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371)
>   at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245)
>   at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5371)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5358)
>   at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1592)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1577)
>   at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:236)
>   at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
>   at 
> 

[jira] [Comment Edited] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2017-11-15 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16253170#comment-16253170
 ] 

yuqi edited comment on CALCITE-2053 at 11/15/17 9:27 AM:
-

The problem is that  in function 
filterRoutinesByParameterType
 , calcite do think decimal(bigdecimal in java)  can transfer to double and 
vice versa(see 

SqlTypeAssignmentRules.java
{code}
) 
however in function 
{code:java}
filterRoutinesByTypePrecedence
{code}
, according to number type precedence list in 
{code:java}
SqlTypeExplicitPrecedentList.java
{code}
,  decimal value can to cast to decimal and double and double value can only be 
cast to double, this is why this problem exist.
My points to solve the problem are as follows:
1. we can change function  
{code:java}
containsType 
{code}
in class 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, When containsType return false, containsType directly return a positive 
values which means  the second parameter does't precedent to the first one, 
thus best match parameter is still the former.
2. we can also change the precedent list in 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, what puzzle me is that how to choose the sequence of Decimal and Double ? now 
decimal is in front of double, double value can't cast to decimal, if put 
decimal after double then decimal, decimal value can't cast to double.

What's your opinion about this problem, suggestions are  welcome [~julianhyde], 
thanks


was (Author: yuqi):
The problem is that  in function 
@filterRoutinesByParameterType
 , calcite do think decimal(bigdecimal in java)  can transfer to double and 
vice versa(see 

SqlTypeAssignmentRules.java
{code}
) 
however in function 
{code:java}
filterRoutinesByTypePrecedence
{code}
, according to number type precedence list in 
{code:java}
SqlTypeExplicitPrecedentList.java
{code}
,  decimal value can to cast to decimal and double and double value can only be 
cast to double, this is why this problem exist.
My points to solve the problem are as follows:
1. we can change function  
{code:java}
containsType 
{code}
in class 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, When containsType return false, containsType directly return a positive 
values which means  the second parameter does't precedent to the first one, 
thus best match parameter is still the former.
2. we can also change the precedent list in 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, what puzzle me is that how to choose the sequence of Decimal and Double ? now 
decimal is in front of double, double value can't cast to decimal, if put 
decimal after double then decimal, decimal value can't cast to double.

What's your opinion about this problem, suggestions are  welcome [~julianhyde], 
thanks

> Overloaded user-defined functions that have Double and BigDecimal arguments 
> will goes wrong
> ---
>
> Key: CALCITE-2053
> URL: https://issues.apache.org/jira/browse/CALCITE-2053
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.13.0
>Reporter: yuqi
>Assignee: Julian Hyde
> Fix For: 1.14.0
>
>
> We define a udf function class have two function as follows 
> {code:java}
> public double toDouble(Double var) {
>   return var;
> }
> 
>  public double toDouble(BigDecimal var) {
>   return var.doubleValue();
> }
> {code}
> when use it in sql like:
> {code:sql}
> select sum(price) from tb;
> {code}
> where price is a double value in table tb, exception occurs:
> {code:java}
> java.lang.AssertionError: DECIMAL(19, 0)
>   at 
> org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
>   at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626)
>   at 
> org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592)
>   at 
> org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446)
>   at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371)
>   at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245)
>   at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5371)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5358)
>   at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1592)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1577)
>   at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:236)
> 

[jira] [Comment Edited] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2017-11-15 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16253170#comment-16253170
 ] 

yuqi edited comment on CALCITE-2053 at 11/15/17 9:26 AM:
-

The problem is that  in function 
@filterRoutinesByParameterType
 , calcite do think decimal(bigdecimal in java)  can transfer to double and 
vice versa(see 

SqlTypeAssignmentRules.java
{code}
) 
however in function 
{code:java}
filterRoutinesByTypePrecedence
{code}
, according to number type precedence list in 
{code:java}
SqlTypeExplicitPrecedentList.java
{code}
,  decimal value can to cast to decimal and double and double value can only be 
cast to double, this is why this problem exist.
My points to solve the problem are as follows:
1. we can change function  
{code:java}
containsType 
{code}
in class 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, When containsType return false, containsType directly return a positive 
values which means  the second parameter does't precedent to the first one, 
thus best match parameter is still the former.
2. we can also change the precedent list in 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, what puzzle me is that how to choose the sequence of Decimal and Double ? now 
decimal is in front of double, double value can't cast to decimal, if put 
decimal after double then decimal, decimal value can't cast to double.

What's your opinion about this problem, suggestions are  welcome [~julianhyde], 
thanks


was (Author: yuqi):
The problem is that  in function 
{quote}filterRoutinesByParameterType{quote}

 , calcite do think decimal(bigdecimal in java)  can transfer to double and 
vice versa(see 
{code:java}
SqlTypeAssignmentRules.java
{code}
) 
however in function 
{code:java}
filterRoutinesByTypePrecedence
{code}
, according to number type precedence list in 
{code:java}
SqlTypeExplicitPrecedentList.java
{code}
,  decimal value can to cast to decimal and double and double value can only be 
cast to double, this is why this problem exist.
My points to solve the problem are as follows:
1. we can change function  
{code:java}
containsType 
{code}
in class 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, When containsType return false, containsType directly return a positive 
values which means  the second parameter does't precedent to the first one, 
thus best match parameter is still the former.
2. we can also change the precedent list in 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, what puzzle me is that how to choose the sequence of Decimal and Double ? now 
decimal is in front of double, double value can't cast to decimal, if put 
decimal after double then decimal, decimal value can't cast to double.

What's your opinion about this problem, suggestions are  welcome [~julianhyde], 
thanks

> Overloaded user-defined functions that have Double and BigDecimal arguments 
> will goes wrong
> ---
>
> Key: CALCITE-2053
> URL: https://issues.apache.org/jira/browse/CALCITE-2053
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.13.0
>Reporter: yuqi
>Assignee: Julian Hyde
> Fix For: 1.14.0
>
>
> We define a udf function class have two function as follows 
> {code:java}
> public double toDouble(Double var) {
>   return var;
> }
> 
>  public double toDouble(BigDecimal var) {
>   return var.doubleValue();
> }
> {code}
> when use it in sql like:
> {code:sql}
> select sum(price) from tb;
> {code}
> where price is a double value in table tb, exception occurs:
> {code:java}
> java.lang.AssertionError: DECIMAL(19, 0)
>   at 
> org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
>   at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626)
>   at 
> org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592)
>   at 
> org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446)
>   at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371)
>   at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245)
>   at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5371)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5358)
>   at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1592)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1577)
>   at 

[jira] [Comment Edited] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2017-11-15 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16253170#comment-16253170
 ] 

yuqi edited comment on CALCITE-2053 at 11/15/17 9:25 AM:
-

The problem is that  in function 
{quote}filterRoutinesByParameterType{quote}

 , calcite do think decimal(bigdecimal in java)  can transfer to double and 
vice versa(see 
{code:java}
SqlTypeAssignmentRules.java
{code}
) 
however in function 
{code:java}
filterRoutinesByTypePrecedence
{code}
, according to number type precedence list in 
{code:java}
SqlTypeExplicitPrecedentList.java
{code}
,  decimal value can to cast to decimal and double and double value can only be 
cast to double, this is why this problem exist.
My points to solve the problem are as follows:
1. we can change function  
{code:java}
containsType 
{code}
in class 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, When containsType return false, containsType directly return a positive 
values which means  the second parameter does't precedent to the first one, 
thus best match parameter is still the former.
2. we can also change the precedent list in 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, what puzzle me is that how to choose the sequence of Decimal and Double ? now 
decimal is in front of double, double value can't cast to decimal, if put 
decimal after double then decimal, decimal value can't cast to double.

What's your opinion about this problem, suggestions are  welcome [~julianhyde], 
thanks


was (Author: yuqi):
The problem is that  in function {quote}quoted text{quote}
filterRoutinesByParameterType

 , calcite do think decimal(bigdecimal in java)  can transfer to double and 
vice versa(see 
{code:java}
SqlTypeAssignmentRules.java
{code}
) 
however in function 
{code:java}
filterRoutinesByTypePrecedence
{code}
, according to number type precedence list in 
{code:java}
SqlTypeExplicitPrecedentList.java
{code}
,  decimal value can to cast to decimal and double and double value can only be 
cast to double, this is why this problem exist.
My points to solve the problem are as follows:
1. we can change function  
{code:java}
containsType 
{code}
in class 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, When containsType return false, containsType directly return a positive 
values which means  the second parameter does't precedent to the first one, 
thus best match parameter is still the former.
2. we can also change the precedent list in 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, what puzzle me is that how to choose the sequence of Decimal and Double ? now 
decimal is in front of double, double value can't cast to decimal, if put 
decimal after double then decimal, decimal value can't cast to double.

What's your opinion about this problem, suggestions are  welcome [~julianhyde], 
thanks

> Overloaded user-defined functions that have Double and BigDecimal arguments 
> will goes wrong
> ---
>
> Key: CALCITE-2053
> URL: https://issues.apache.org/jira/browse/CALCITE-2053
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.13.0
>Reporter: yuqi
>Assignee: Julian Hyde
> Fix For: 1.14.0
>
>
> We define a udf function class have two function as follows 
> {code:java}
> public double toDouble(Double var) {
>   return var;
> }
> 
>  public double toDouble(BigDecimal var) {
>   return var.doubleValue();
> }
> {code}
> when use it in sql like:
> {code:sql}
> select sum(price) from tb;
> {code}
> where price is a double value in table tb, exception occurs:
> {code:java}
> java.lang.AssertionError: DECIMAL(19, 0)
>   at 
> org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
>   at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626)
>   at 
> org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592)
>   at 
> org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446)
>   at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371)
>   at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245)
>   at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5371)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5358)
>   at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1592)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1577)
>   at 

[jira] [Comment Edited] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2017-11-15 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16253170#comment-16253170
 ] 

yuqi edited comment on CALCITE-2053 at 11/15/17 9:24 AM:
-

The problem is that  in function {quote}quoted text{quote}
filterRoutinesByParameterType

 , calcite do think decimal(bigdecimal in java)  can transfer to double and 
vice versa(see 
{code:java}
SqlTypeAssignmentRules.java
{code}
) 
however in function 
{code:java}
filterRoutinesByTypePrecedence
{code}
, according to number type precedence list in 
{code:java}
SqlTypeExplicitPrecedentList.java
{code}
,  decimal value can to cast to decimal and double and double value can only be 
cast to double, this is why this problem exist.
My points to solve the problem are as follows:
1. we can change function  
{code:java}
containsType 
{code}
in class 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, When containsType return false, containsType directly return a positive 
values which means  the second parameter does't precedent to the first one, 
thus best match parameter is still the former.
2. we can also change the precedent list in 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, what puzzle me is that how to choose the sequence of Decimal and Double ? now 
decimal is in front of double, double value can't cast to decimal, if put 
decimal after double then decimal, decimal value can't cast to double.

What's your opinion about this problem, suggestions are  welcome [~julianhyde], 
thanks


was (Author: yuqi):
The problem is that  in function 


{noformat}
*no* further _formatting_ is done here
{noformat}
filterRoutinesByParameterType

 , calcite do think decimal(bigdecimal in java)  can transfer to double and 
vice versa(see 
{code:java}
SqlTypeAssignmentRules.java
{code}
) 
however in function 
{code:java}
filterRoutinesByTypePrecedence
{code}
, according to number type precedence list in 
{code:java}
SqlTypeExplicitPrecedentList.java
{code}
,  decimal value can to cast to decimal and double and double value can only be 
cast to double, this is why this problem exist.
My points to solve the problem are as follows:
1. we can change function  
{code:java}
containsType 
{code}
in class 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, When containsType return false, containsType directly return a positive 
values which means  the second parameter does't precedent to the first one, 
thus best match parameter is still the former.
2. we can also change the precedent list in 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, what puzzle me is that how to choose the sequence of Decimal and Double ? now 
decimal is in front of double, double value can't cast to decimal, if put 
decimal after double then decimal, decimal value can't cast to double.

What's your opinion about this problem, suggestions are  welcome [~julianhyde], 
thanks

> Overloaded user-defined functions that have Double and BigDecimal arguments 
> will goes wrong
> ---
>
> Key: CALCITE-2053
> URL: https://issues.apache.org/jira/browse/CALCITE-2053
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.13.0
>Reporter: yuqi
>Assignee: Julian Hyde
> Fix For: 1.14.0
>
>
> We define a udf function class have two function as follows 
> {code:java}
> public double toDouble(Double var) {
>   return var;
> }
> 
>  public double toDouble(BigDecimal var) {
>   return var.doubleValue();
> }
> {code}
> when use it in sql like:
> {code:sql}
> select sum(price) from tb;
> {code}
> where price is a double value in table tb, exception occurs:
> {code:java}
> java.lang.AssertionError: DECIMAL(19, 0)
>   at 
> org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
>   at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626)
>   at 
> org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592)
>   at 
> org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446)
>   at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371)
>   at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245)
>   at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5371)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5358)
>   at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1592)
>   at 
> 

[jira] [Comment Edited] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2017-11-15 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16253170#comment-16253170
 ] 

yuqi edited comment on CALCITE-2053 at 11/15/17 9:23 AM:
-

The problem is that  in function 


{noformat}
*no* further _formatting_ is done here
{noformat}
filterRoutinesByParameterType

 , calcite do think decimal(bigdecimal in java)  can transfer to double and 
vice versa(see 
{code:java}
SqlTypeAssignmentRules.java
{code}
) 
however in function 
{code:java}
filterRoutinesByTypePrecedence
{code}
, according to number type precedence list in 
{code:java}
SqlTypeExplicitPrecedentList.java
{code}
,  decimal value can to cast to decimal and double and double value can only be 
cast to double, this is why this problem exist.
My points to solve the problem are as follows:
1. we can change function  
{code:java}
containsType 
{code}
in class 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, When containsType return false, containsType directly return a positive 
values which means  the second parameter does't precedent to the first one, 
thus best match parameter is still the former.
2. we can also change the precedent list in 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, what puzzle me is that how to choose the sequence of Decimal and Double ? now 
decimal is in front of double, double value can't cast to decimal, if put 
decimal after double then decimal, decimal value can't cast to double.

What's your opinion about this problem, suggestions are  welcome [~julianhyde], 
thanks


was (Author: yuqi):
The problem is that  in function 

??filterRoutinesByParameterType??

 , calcite do think decimal(bigdecimal in java)  can transfer to double and 
vice versa(see 
{code:java}
SqlTypeAssignmentRules.java
{code}
) 
however in function 
{code:java}
filterRoutinesByTypePrecedence
{code}
, according to number type precedence list in 
{code:java}
SqlTypeExplicitPrecedentList.java
{code}
,  decimal value can to cast to decimal and double and double value can only be 
cast to double, this is why this problem exist.
My points to solve the problem are as follows:
1. we can change function  
{code:java}
containsType 
{code}
in class 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, When containsType return false, containsType directly return a positive 
values which means  the second parameter does't precedent to the first one, 
thus best match parameter is still the former.
2. we can also change the precedent list in 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, what puzzle me is that how to choose the sequence of Decimal and Double ? now 
decimal is in front of double, double value can't cast to decimal, if put 
decimal after double then decimal, decimal value can't cast to double.

What's your opinion about this problem, suggestions are  welcome [~julianhyde], 
thanks

> Overloaded user-defined functions that have Double and BigDecimal arguments 
> will goes wrong
> ---
>
> Key: CALCITE-2053
> URL: https://issues.apache.org/jira/browse/CALCITE-2053
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.13.0
>Reporter: yuqi
>Assignee: Julian Hyde
> Fix For: 1.14.0
>
>
> We define a udf function class have two function as follows 
> {code:java}
> public double toDouble(Double var) {
>   return var;
> }
> 
>  public double toDouble(BigDecimal var) {
>   return var.doubleValue();
> }
> {code}
> when use it in sql like:
> {code:sql}
> select sum(price) from tb;
> {code}
> where price is a double value in table tb, exception occurs:
> {code:java}
> java.lang.AssertionError: DECIMAL(19, 0)
>   at 
> org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
>   at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626)
>   at 
> org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592)
>   at 
> org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446)
>   at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371)
>   at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245)
>   at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5371)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5358)
>   at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1592)
>   at 
> 

[jira] [Comment Edited] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2017-11-15 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16253170#comment-16253170
 ] 

yuqi edited comment on CALCITE-2053 at 11/15/17 9:23 AM:
-

The problem is that  in function 

??filterRoutinesByParameterType??

 , calcite do think decimal(bigdecimal in java)  can transfer to double and 
vice versa(see 
{code:java}
SqlTypeAssignmentRules.java
{code}
) 
however in function 
{code:java}
filterRoutinesByTypePrecedence
{code}
, according to number type precedence list in 
{code:java}
SqlTypeExplicitPrecedentList.java
{code}
,  decimal value can to cast to decimal and double and double value can only be 
cast to double, this is why this problem exist.
My points to solve the problem are as follows:
1. we can change function  
{code:java}
containsType 
{code}
in class 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, When containsType return false, containsType directly return a positive 
values which means  the second parameter does't precedent to the first one, 
thus best match parameter is still the former.
2. we can also change the precedent list in 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, what puzzle me is that how to choose the sequence of Decimal and Double ? now 
decimal is in front of double, double value can't cast to decimal, if put 
decimal after double then decimal, decimal value can't cast to double.

What's your opinion about this problem, suggestions are  welcome [~julianhyde], 
thanks


was (Author: yuqi):
The problem is that  in function 
`
filterRoutinesByParameterType
`
 , calcite do think decimal(bigdecimal in java)  can transfer to double and 
vice versa(see 
{code:java}
SqlTypeAssignmentRules.java
{code}
) 
however in function 
{code:java}
filterRoutinesByTypePrecedence
{code}
, according to number type precedence list in 
{code:java}
SqlTypeExplicitPrecedentList.java
{code}
,  decimal value can to cast to decimal and double and double value can only be 
cast to double, this is why this problem exist.
My points to solve the problem are as follows:
1. we can change function  
{code:java}
containsType 
{code}
in class 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, When containsType return false, containsType directly return a positive 
values which means  the second parameter does't precedent to the first one, 
thus best match parameter is still the former.
2. we can also change the precedent list in 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, what puzzle me is that how to choose the sequence of Decimal and Double ? now 
decimal is in front of double, double value can't cast to decimal, if put 
decimal after double then decimal, decimal value can't cast to double.

What's your opinion about this problem, suggestions are  welcome [~julianhyde], 
thanks

> Overloaded user-defined functions that have Double and BigDecimal arguments 
> will goes wrong
> ---
>
> Key: CALCITE-2053
> URL: https://issues.apache.org/jira/browse/CALCITE-2053
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.13.0
>Reporter: yuqi
>Assignee: Julian Hyde
> Fix For: 1.14.0
>
>
> We define a udf function class have two function as follows 
> {code:java}
> public double toDouble(Double var) {
>   return var;
> }
> 
>  public double toDouble(BigDecimal var) {
>   return var.doubleValue();
> }
> {code}
> when use it in sql like:
> {code:sql}
> select sum(price) from tb;
> {code}
> where price is a double value in table tb, exception occurs:
> {code:java}
> java.lang.AssertionError: DECIMAL(19, 0)
>   at 
> org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
>   at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626)
>   at 
> org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592)
>   at 
> org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446)
>   at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371)
>   at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245)
>   at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5371)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5358)
>   at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1592)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1577)
>   at 

[jira] [Commented] (CALCITE-2053) Overloaded user-defined functions that have Double and BigDecimal arguments will goes wrong

2017-11-15 Thread yuqi (JIRA)

[ 
https://issues.apache.org/jira/browse/CALCITE-2053?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16253170#comment-16253170
 ] 

yuqi commented on CALCITE-2053:
---

The problem is that  in function 

{code:java}
filterRoutinesByParameterType
{code}
 , calcite do think decimal(bigdecimal in java)  can transfer to double and 
vice versa(see 
{code:java}
SqlTypeAssignmentRules.java
{code}
) 
however in function 
{code:java}
filterRoutinesByTypePrecedence
{code}
, according to number type precedence list in 
{code:java}
SqlTypeExplicitPrecedentList.java
{code}
,  decimal value can to cast to decimal and double and double value can only be 
cast to double, this is why this problem exist.
My points to solve the problem are as follows:
1. we can change function  
{code:java}
containsType 
{code}
in class 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, When containsType return false, containsType directly return a positive 
values which means  the second parameter does't precedent to the first one, 
thus best match parameter is still the former.
2. we can also change the precedent list in 
{code:java}
SqlTypeExplicitPrecedentList
{code}
, what puzzle me is that how to choose the sequence of Decimal and Double ? now 
decimal is in front of double, double value can't cast to decimal, if put 
decimal after double then decimal, decimal value can't cast to double.

What's your opinion about this problem, suggestions are  welcome [~julianhyde], 
thanks

> Overloaded user-defined functions that have Double and BigDecimal arguments 
> will goes wrong
> ---
>
> Key: CALCITE-2053
> URL: https://issues.apache.org/jira/browse/CALCITE-2053
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.13.0
>Reporter: yuqi
>Assignee: Julian Hyde
> Fix For: 1.14.0
>
>
> We define a udf function class have two function as follows 
> {code:java}
> public double toDouble(Double var) {
>   return var;
> }
> 
>  public double toDouble(BigDecimal var) {
>   return var.doubleValue();
> }
> {code}
> when use it in sql like:
> {code:sql}
> select sum(price) from tb;
> {code}
> where price is a double value in table tb, exception occurs:
> {code:java}
> java.lang.AssertionError: DECIMAL(19, 0)
>   at 
> org.apache.calcite.sql.type.SqlTypeExplicitPrecedenceList.compareTypePrecedence(SqlTypeExplicitPrecedenceList.java:154)
>   at org.apache.calcite.sql.SqlUtil.bestMatch(SqlUtil.java:626)
>   at 
> org.apache.calcite.sql.SqlUtil.filterRoutinesByTypePrecedence(SqlUtil.java:592)
>   at 
> org.apache.calcite.sql.SqlUtil.lookupSubjectRoutines(SqlUtil.java:446)
>   at org.apache.calcite.sql.SqlUtil.lookupRoutine(SqlUtil.java:371)
>   at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:245)
>   at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5371)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:5358)
>   at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:138)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1592)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1577)
>   at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:236)
>   at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5081)
>   at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115)
>   at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:235)
>   at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:407)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:5081)
>   at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:115)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:901)
>   at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:611)
>   at 
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:551)
>   at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:263)
>   at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:229)
>   at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:786)
>   at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:640)
>   at 
> 

  1   2   >