Requesting a review on a PR----[CALCITE-4486]:support UNIQUE predicate

2021-08-17 Thread xiong duan
Hi Follower, Please review this PR, So that we can make some improvements.
Thank you.

The PR:https://github.com/apache/calcite/pull/2495
The ISSUE:
 https://issues.apache.org/jira/projects/CALCITE/issues/CALCITE-4486



[jira] [Created] (CALCITE-4745) RelDataTypeSystemImpl.deriveAvgAggType typing error

2021-08-17 Thread keaton drebes (Jira)
keaton drebes created CALCITE-4745:
--

 Summary: RelDataTypeSystemImpl.deriveAvgAggType typing error
 Key: CALCITE-4745
 URL: https://issues.apache.org/jira/browse/CALCITE-4745
 Project: Calcite
  Issue Type: Bug
  Components: core
Affects Versions: 1.27.0
Reporter: keaton drebes
 Fix For: 1.27.0


Currently, RelDataTypeSystemImpl.deriveAvgAggType returns the type of the input 
argument.

This is obviously incorrect, AVG(A) where A has values [0, 1] should return .5, 
which is not an integer. This issue effects all SqlAggFunction's, since they 
ultimately use deriveAvgAggType for type inference.

PR here:



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


Looking for a committer to merge CALCITE-4665: Allow Aggregate.groupSet to contain columns not in any of the groupSets

2021-08-17 Thread xiong duan
I have a patch  that is ready
for review and to be committed.  I am looking for a committer to review and
merge it. Thanks.


[jira] [Created] (CALCITE-4744) Add

2021-08-17 Thread keaton drebes (Jira)
keaton drebes created CALCITE-4744:
--

 Summary: Add 
 Key: CALCITE-4744
 URL: https://issues.apache.org/jira/browse/CALCITE-4744
 Project: Calcite
  Issue Type: New Feature
  Components: core
Reporter: keaton drebes


I have a project that is working with windowed functions and we want to avoid 
the decomposition of certain aggregate functions (i.e. stddev) in the process 
of converting from an SqlNode to a RelNode. We have currently supported this by 
copying the entire  StandardConvertlet table, and removing the convertlets 
responsible for this. 

It seems reasonable to control this behavior with a configuration for the 
StandardConvertlet table. Is this something that people would accept being 
merged into Calcite?



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


[jira] [Created] (CALCITE-4742) AssertionError in SubQueryRemoveRule.rewriteSome while rewriting ANY subquery

2021-08-17 Thread Ivan Daschinsky (Jira)
Ivan Daschinsky created CALCITE-4742:


 Summary: AssertionError in SubQueryRemoveRule.rewriteSome while 
rewriting ANY subquery
 Key: CALCITE-4742
 URL: https://issues.apache.org/jira/browse/CALCITE-4742
 Project: Calcite
  Issue Type: Bug
Reporter: Ivan Daschinsky


When executing
{code}
select * from "scott".emp where empno <> any (select 10);
{code}
with assertions, got assertion error 
{code}
---
> java.lang.AssertionError
>   at 
> org.apache.calcite.rel.rules.SubQueryRemoveRule.rewriteSome(SubQueryRemoveRule.java:170)
>   at 
> org.apache.calcite.rel.rules.SubQueryRemoveRule.apply(SubQueryRemoveRule.java:92)
>   at 
> org.apache.calcite.rel.rules.SubQueryRemoveRule.matchFilter(SubQueryRemoveRule.java:637)
>   at 
> org.apache.calcite.rel.rules.SubQueryRemoveRule.access$100(SubQueryRemoveRule.java:71)
>   at 
> org.apache.calcite.rel.rules.SubQueryRemoveRule$Config.lambda$static$3(SubQueryRemoveRule.java:701)
>   at 
> org.apache.calcite.rel.rules.SubQueryRemoveRule.onMatch(SubQueryRemoveRule.java:82)
>   at 
> org.apache.calcite.plan.AbstractRelOptPlanner.fireRule(AbstractRelOptPlanner.java:341)
>   at org.apache.calcite.plan.hep.HepPlanner.applyRule(HepPlanner.java:565)
>   at 
> org.apache.calcite.plan.hep.HepPlanner.applyRules(HepPlanner.java:428)
>   at 
> org.apache.calcite.plan.hep.HepPlanner.executeInstruction(HepPlanner.java:282)
>   at 
> org.apache.calcite.plan.hep.HepInstruction$RuleCollection.execute(HepInstruction.java:77)
>   at 
> org.apache.calcite.plan.hep.HepPlanner.executeProgram(HepPlanner.java:208)
>   at 
> org.apache.calcite.plan.hep.HepPlanner.findBestExp(HepPlanner.java:195)
>   at org.apache.calcite.tools.Programs.lambda$of$0(Programs.java:176)
>   at 
> org.apache.calcite.tools.Programs$SequenceProgram.run(Programs.java:335)
>   at org.apache.calcite.prepare.Prepare.optimize(Prepare.java:172)
>   at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:306)
>   at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:215)
>   at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:647)
>   at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:513)
>   at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:483)
>   at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:249)
>   at 
> org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:623)
{code}

This query cannot be rewritten as IN query, so it goes to  
`SubQueryRemoveRule.rewriteSome`. Current logic in this method doesn't work on 
this case and produce wrong plan. 

This query should be rewritten to something like this:
{code}
select distinct(e.*)  from "scott".emp as e left join
(select 10 as deptno) as q
on e.deptno <> q.deptno;
{code}



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


[jira] [Created] (CALCITE-4741) AbstractRelNode#getId can overflow into a negative value causing CompileException in certain Enumerable implement methods

2021-08-17 Thread Ruben Q L (Jira)
Ruben Q L created CALCITE-4741:
--

 Summary: AbstractRelNode#getId can overflow into a negative value 
causing CompileException in certain Enumerable implement methods
 Key: CALCITE-4741
 URL: https://issues.apache.org/jira/browse/CALCITE-4741
 Project: Calcite
  Issue Type: Bug
  Components: core
Affects Versions: 1.27.0
Reporter: Ruben Q L
 Fix For: 1.28.0


{{AbstractRelNode#getId}} can overflow into a negative value.
 This id is used by certain in the {{implement}} method of several Enumerable 
operators ({{EnumerableBatchNestedLoopJoin}} and {{EnumerableMergeUnion}}) to 
guarantee a unique variable name in the dynamic code, e.g.:
{code:java}
final ParameterExpression corrArgList =
Expressions.parameter(Modifier.FINAL,
List.class, "corrList" + this.getId());
{code}
However, if the id is negative, this variable name will have a "-", causing a 
{{CompileException}}:
{noformat}
...
final org.apache.calcite.linq4j.Enumerable _inputEnumerable1 = 
org.apache.calcite.linq4j.EnumerableDefaults.correlateBatchJoin(org.apache.calcite.linq4j.JoinType.LEFT,
 left0, new org.apache.calcite.linq4j.function.Function1() {
public org.apache.calcite.linq4j.AbstractEnumerable apply(final 
java.util.List corrList-1794407755) {
  {
...
Caused by: java.util.concurrent.ExecutionException: 
org.codehaus.commons.compiler.CompileException: Line 134, Column 103: One of ', 
)' expected instead of '-'
{noformat}



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


Re: Runtime Exception while using SqlParse.

2021-08-17 Thread Thomas Rebele
Hi Jariv,

are you sure you want to join two columns of Purchase: *Purchase.Product_ID
= Purchase.ID*?
If that's the cause of the exception, the error message could be improved.

Cordialement / Best Regards,
*Thomas Rebele, PhD* | R Developer | Germany | www.tibco.com


On Mon, Aug 16, 2021 at 10:58 PM Jariv Narup 
wrote:

> Hi Team,
>I am getting the following exception while trying to parse a SQL
> statement into its tokens. Is this expected behavior? If not, what would
> you suggest to work around this problem. The particulars are given below:
>
> *Issue:*
> *Method threw 'java.lang.RuntimeException' exception. Cannot evaluate
> org.apache.calcite.sql.SqlJoin.toString().*
>
> *Where:*
> This happens when I use the following API (it is visible on the "from"
> value):
>
> SqlParser.Config parserConfig = SqlParser.config();
> parserConfig
> .withCaseSensitive(false)
> .withLex(Lex.ORACLE);
> SqlParser parser = SqlParser.create(sqlString, parserConfig);
> >>> [Line with the issue]*SqlNode sqlNode = parser.parseStmt();*
>
>
> *Debugger Image:*
> [image: image.png]
> *Version In Use:*
> I am using the following maven GAVs
> -org.apache.calcite:calcite-babel:1.27.0, so my assumption is that I am at
> the latest.
>
> *SQL Statement with the issue:*
>
> *SELECT Purchase.Purchase_Date, Products.Product_Name FROM Purchase JOIN
> Products ON Purchase.Product_ID = Purchase.ID WHERE Purchase.Quantity > 10*
>
> I would appreciate any help on this.
>
> Thanks - Jariv
>


Re: Analyzing SQL queries with default catalog/database names

2021-08-17 Thread Julian Hyde
A key step in validation is to fully-quality table names. Thus in your example, 
mytable would become the string array [“hive”, “my_database”, “mytable”]. Any 
my_database2.mytable2 would become [“hive”, “my_database2”, “mytable2”]. But 
foo would remain foo, because it is in the query and is not a table.

The validator’s context is a path, which looks something like [[], [“hive”], 
[“hive”, “my_database”]]. Fully-, partially- and non-qualified table names are 
all looked up within that path.

Julian


> On Aug 17, 2021, at 12:02 AM, Zheng Shao  wrote:
> 
> Hi Calcite Dev,
> 
> What is the recommended way to analyze SQL queries with default
> catalog/database names?
> 
> For example, for query like "SELECT * FROM foo" where foo maps to a table
> in hive.my_database.
> 
> In Project Coral
> ,
> the code tries to add catalog/database names right after the parsing stage,
> but that would not work for cases like "WITH foo AS (SELECT * FROM mytable)
> SELECT * from foo" in which case there is no need to prepend.
> 
> -- 
> Zheng