[jira] [Created] (CALCITE-5834) Rel to Sql wrong output for correlated subqueries using the same table

2023-07-10 Thread Francesco Gini (Jira)
Francesco Gini created CALCITE-5834:
---

 Summary: Rel to Sql wrong output for correlated subqueries using 
the same table
 Key: CALCITE-5834
 URL: https://issues.apache.org/jira/browse/CALCITE-5834
 Project: Calcite
  Issue Type: Bug
  Components: core
Affects Versions: 1.34.0
Reporter: Francesco Gini
 Attachments: test-patch.patch

A correlated query with a filter on a table that is also in the outer scope is 
converted into a sql that would produce the wrong results.

Below is a test for RelToSqlConverterTest that reproduces the problem (also 
attached as patch: test-patch.patch) 
{code:java}
@Test void testSubQueryInWhereAlias() {
  String query = "select s1.\"customer_id\", s1.\"unit_sales\"\n"
  + "from \"sales_fact_1997\" s1\n"
  + "where s1.\"store_sales\" in\n"
  + "(select max(\"store_sales\") from \"sales_fact_1997\" s2 where 
s2.\"customer_id\" = s1.\"customer_id\"\n"
  + ")";
  final String wrong = "SELECT \"customer_id\", \"unit_sales\"\n"
  + "FROM \"foodmart\".\"sales_fact_1997\"\n"
  + "WHERE \"store_sales\" IN (SELECT MAX(\"store_sales\")\n"
  + "FROM \"foodmart\".\"sales_fact_1997\"\n"
  + "WHERE \"customer_id\" = \"sales_fact_1997\".\"customer_id\")";

  sql(query).ok(wrong);
}{code}
The sql produced has a filter
{code:java}
WHERE \"customer_id\" = \"sales_fact_1997\".\"customer_id\" {code}
whose columns both refer to the subquery table, whereas the right hand side of 
the filter should refer to the table in the outer query



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


[jira] [Created] (CALCITE-4932) Deprecate JdbcCalc and JdbcCalcRule

2021-12-11 Thread Francesco Gini (Jira)
Francesco Gini created CALCITE-4932:
---

 Summary: Deprecate JdbcCalc and JdbcCalcRule
 Key: CALCITE-4932
 URL: https://issues.apache.org/jira/browse/CALCITE-4932
 Project: Calcite
  Issue Type: Task
  Components: jdbc-adapter
Affects Versions: 1.28.0
Reporter: Francesco Gini


The jdbc adapter includes a node and rule for {{Calc}} ( {{{}JdbcCal{}}}c a 
{{JdbcCalcRule}} ). {{Calc}} is an operation that is introduced only later in 
the planner to optimise certain code generation and it is not needed for the 
jdbc adapter.

As it stands the rule {{JdbcCalcRule}} is never triggered because the {{Jdbc}} 
convention rules are applied before the {{Calc}} node is introduced in the 
plan. However, if a user try to use a custom rule set they might end up with a 
{{JdbcCalc}} which introduces problems like the one described in 
https://issues.apache.org/jira/browse/CALCITE-4905 .

Because {{JdbcCalc}} is not an optimisation needed for jdbc anyway we should 
deprecate {{JdbcCalc}} and its respective rule {{{}JdbcCalcRule{}}}. The rule 
should also be removed from {{JdbcRules.rules}}

See ticket https://issues.apache.org/jira/browse/CALCITE-4905  for a discussion 
around deprecating {{JdbcCalc}}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)


[jira] [Created] (CALCITE-4907) JdbcJoin does not convert Join with alwayt true/false RexNode

2021-11-28 Thread Francesco Gini (Jira)
Francesco Gini created CALCITE-4907:
---

 Summary: JdbcJoin does not convert Join with alwayt true/false 
RexNode
 Key: CALCITE-4907
 URL: https://issues.apache.org/jira/browse/CALCITE-4907
 Project: Calcite
  Issue Type: Bug
  Components: jdbc-adapter
Affects Versions: 1.28.0
Reporter: Francesco Gini
Assignee: Francesco Gini


JdbcJoin does not handle cases where the condtion is a RexNode that it is 
always true or false. However, SqlImplementor is coded to handle those 
conditions (see SqlImplementor.convertConditionToSqlNode).

Specifically a cross join is internally represented as a LogicalJoin with 
condition true which is not pushed down into the db.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)


[jira] [Created] (CALCITE-4905) JdbcCalc does not implement Calc

2021-11-28 Thread Francesco Gini (Jira)
Francesco Gini created CALCITE-4905:
---

 Summary: JdbcCalc does not implement Calc
 Key: CALCITE-4905
 URL: https://issues.apache.org/jira/browse/CALCITE-4905
 Project: Calcite
  Issue Type: Bug
Reporter: Francesco Gini


`JdbcCalc` class does not implement Calc. Failing to do that means that `

RelToSqlConverter` cannot translate a plan with `JdbcCalc` into sql because 
`RelToSqlConverter` expects

```

{color:#cc7832}public {color}Result {color:#ffc66d}visit{color}(Calc e)

```



--
This message was sent by Atlassian Jira
(v8.20.1#820001)