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

Dmitry Sysolyatin updated CALCITE-6494:
---------------------------------------
    Description: 
MongoAdapter throws an exception if any function unsupported by MongoProject is 
used

A simple example [1]:
{code}
@Test void testCalciteFunc() {
    assertModel(MODEL)
        .query("select CHAR_LENGTH(state) from zips")
        .runs();
  }
{code}
throws 
{code}
Unable to implement MongoToEnumerableConverter: rowcount = 100.0, cumulative 
cost = {30.0 rows, 30.1 cpu, 0.0 io}, id = 39
  MongoProject(EXPR$0=[CHAR_LENGTH(CAST(ITEM($0, 'state')):VARCHAR(2))]): 
rowcount = 100.0, cumulative cost = {20.0 rows, 20.1 cpu, 0.0 io}, id = 37
    MongoTableScan(table=[[mongo_raw, zips]]): rowcount = 100.0, cumulative 
cost = {10.0 rows, 10.100000000000001 cpu, 0.0 io}, id = 13
......
Suppressed: java.lang.IllegalArgumentException: Translation of 
CHAR_LENGTH(CAST(ITEM($0, 'state')):VARCHAR(2)) is not supported by MongoProject
{code}

The reason is that MongoProjectRule does not properly filter projects from 
LogicalProject.getNamedProjects that can be used. I think the proper 
implementation of this rule should be similar to DruidProjectRule [2]. It 
should extract input references from the project if it cannot be fully 
supported and add an additional Project on top of MongoProject.

[1] - 
https://github.com/dssysolyatin/calcite/commit/96cddae9c6516701e1aa44f7c75df5afdc497f8d
[2] - 
https://github.com/apache/calcite/blob/ea1a255fd071a518fe8d30e361efa0696164a037/druid/src/main/java/org/apache/calcite/adapter/druid/DruidRules.java#L353


  was:
MongoAdapter throws an exception if any function unsupported by MongoProject is 
used

A simple example [1]:
{code}
@Test void testCalciteFunc() {
    assertModel(MODEL)
        .query("select CHAR_LENGTH(state) from zips")
        .runs();
  }
{code}
throws 
{code}
Unable to implement MongoToEnumerableConverter: rowcount = 100.0, cumulative 
cost = {30.0 rows, 30.1 cpu, 0.0 io}, id = 39
  MongoProject(EXPR$0=[CHAR_LENGTH(CAST(ITEM($0, 'state')):VARCHAR(2))]): 
rowcount = 100.0, cumulative cost = {20.0 rows, 20.1 cpu, 0.0 io}, id = 37
    MongoTableScan(table=[[mongo_raw, zips]]): rowcount = 100.0, cumulative 
cost = {10.0 rows, 10.100000000000001 cpu, 0.0 io}, id = 13
......
Suppressed: java.lang.IllegalArgumentException: Translation of 
CHAR_LENGTH(CAST(ITEM($0, 'state')):VARCHAR(2)) is not supported by MongoProject
{code}

The reason is that MongoProjectRule does not properly filter projects from 
LogicalProjects.getNamedProjects that can be used. I think the proper 
implementation of this rule should be similar to DruidProjectRule [2]. It 
should extract input references from the project if it cannot be fully 
supported and add an additional Project on top of MongoProject.

[1] - 
https://github.com/dssysolyatin/calcite/commit/96cddae9c6516701e1aa44f7c75df5afdc497f8d
[2] - 
https://github.com/apache/calcite/blob/ea1a255fd071a518fe8d30e361efa0696164a037/druid/src/main/java/org/apache/calcite/adapter/druid/DruidRules.java#L353



> MongoAdapter throws an exception if any function unsupported by MongoProject 
> is used
> ------------------------------------------------------------------------------------
>
>                 Key: CALCITE-6494
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6494
>             Project: Calcite
>          Issue Type: Bug
>          Components: mongodb-adapter
>    Affects Versions: 1.37.0
>            Reporter: Dmitry Sysolyatin
>            Priority: Major
>
> MongoAdapter throws an exception if any function unsupported by MongoProject 
> is used
> A simple example [1]:
> {code}
> @Test void testCalciteFunc() {
>     assertModel(MODEL)
>         .query("select CHAR_LENGTH(state) from zips")
>         .runs();
>   }
> {code}
> throws 
> {code}
> Unable to implement MongoToEnumerableConverter: rowcount = 100.0, cumulative 
> cost = {30.0 rows, 30.1 cpu, 0.0 io}, id = 39
>   MongoProject(EXPR$0=[CHAR_LENGTH(CAST(ITEM($0, 'state')):VARCHAR(2))]): 
> rowcount = 100.0, cumulative cost = {20.0 rows, 20.1 cpu, 0.0 io}, id = 37
>     MongoTableScan(table=[[mongo_raw, zips]]): rowcount = 100.0, cumulative 
> cost = {10.0 rows, 10.100000000000001 cpu, 0.0 io}, id = 13
> ......
> Suppressed: java.lang.IllegalArgumentException: Translation of 
> CHAR_LENGTH(CAST(ITEM($0, 'state')):VARCHAR(2)) is not supported by 
> MongoProject
> {code}
> The reason is that MongoProjectRule does not properly filter projects from 
> LogicalProject.getNamedProjects that can be used. I think the proper 
> implementation of this rule should be similar to DruidProjectRule [2]. It 
> should extract input references from the project if it cannot be fully 
> supported and add an additional Project on top of MongoProject.
> [1] - 
> https://github.com/dssysolyatin/calcite/commit/96cddae9c6516701e1aa44f7c75df5afdc497f8d
> [2] - 
> https://github.com/apache/calcite/blob/ea1a255fd071a518fe8d30e361efa0696164a037/druid/src/main/java/org/apache/calcite/adapter/druid/DruidRules.java#L353



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to