Re: No match found for function signature IF

2021-07-26 Thread Yanjing Wang
Could you paste your code that shows how the SqlOperatorTable is
constructed?  the IF operator is defined in SqlLibraryOperators class and
you can get corresponding operator table through SqlOperatorTable opTab =
SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(EnumSet.of(SqlLibrary
sqlLibrary)), any of SqlLibrary.BIG_QUERY, SqlLibrary.HIVE,
SqlLibrary.SPARK will work. Another option may be
SqlValidator.Config.DEFAULT.withLenientOperatorLookup(true), which will be
lenient when encountering an unknown function.

wrstrs  于2021年7月26日周一 下午8:02写道:

> hi, all
>
> how to solve this problem?
>
>
>
>
> Caused by: org.apache.calcite.sql.validate.SqlValidatorException: No match
> found for function signature IF(
> 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)


[jira] [Created] (CALCITE-4703) getDistinctRowCount returns NULL for Converter and TableScan

2021-07-26 Thread Soumyakanti Das (Jira)
Soumyakanti Das created CALCITE-4703:


 Summary: getDistinctRowCount returns NULL for Converter and 
TableScan
 Key: CALCITE-4703
 URL: https://issues.apache.org/jira/browse/CALCITE-4703
 Project: Calcite
  Issue Type: Improvement
  Components: core
Affects Versions: 1.27.0
Reporter: Soumyakanti Das


The catch-all method 
[getDistinctRowCount|https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistinctRowCount.java#L76]
 returns NULL when the RelNode is a Converter or TableScan/JdbcTableScan. It 
would be nice to have overloaded methods to handle these types.

Currently in Hive, we get a NPE for the following query, while computing 
selectivity:
{code:java}
explain cbo
with t1 as (select fkey, ikey, sum(dkey) as dk_sum, sum(dkey2) as dk2_sum
from ext_simple_derby_table1 left join ext_simple_derby_table3
on ikey = ikey2
where fkey2 is null
group by fkey, ikey),
t2 as (select datekey, fkey, ikey, sum(dkey) as dk_sum2, sum(dkey2) as dk2_sum2
   from ext_simple_derby_table2 left join ext_simple_derby_table4
   on ikey = ikey2
   where fkey2 is null
   group by datekey, fkey, ikey)
select t1.fkey, t2.ikey, sum(t1.ikey)
from t1 left join t2
on t1.ikey = t2.ikey AND t1.fkey = t2.fkey
where t2.fkey is null
group by t2.datekey, t1.fkey, t2.ikey
{code}
Stacktrace:
{code:java}
java.lang.NullPointerException
at 
org.apache.hadoop.hive.ql.optimizer.calcite.stats.HiveRelMdSelectivity.getSelectivity(HiveRelMdSelectivity.java:78)
at GeneratedMetadataHandler_Selectivity.getSelectivity_$(Unknown Source)
at GeneratedMetadataHandler_Selectivity.getSelectivity(Unknown Source)
at GeneratedMetadataHandler_Selectivity.getSelectivity_$(Unknown Source)
at GeneratedMetadataHandler_Selectivity.getSelectivity(Unknown Source)
at 
org.apache.calcite.rel.metadata.RelMetadataQuery.getSelectivity(RelMetadataQuery.java:426)
at 
org.apache.calcite.rel.metadata.RelMdUtil.estimateFilteredRows(RelMdUtil.java:765)
at 
org.apache.calcite.rel.metadata.RelMdRowCount.getRowCount(RelMdRowCount.java:131)
at 
org.apache.hadoop.hive.ql.optimizer.calcite.stats.HiveRelMdRowCount.getRowCount(HiveRelMdRowCount.java:175)
at 
org.apache.hadoop.hive.ql.optimizer.calcite.stats.HiveRelMdRuntimeRowCount.getRowCount(HiveRelMdRuntimeRowCount.java:53)
at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source)
at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source)
at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source)
at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source)
at 
org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:212)
at 
org.apache.calcite.rel.metadata.RelMdRowCount.getRowCount(RelMdRowCount.java:205)
at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source)
at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source)
at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source)
at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source)
at 
org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:212)
at 
org.apache.calcite.rel.metadata.RelMdRowCount.getRowCount(RelMdRowCount.java:140)
at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source)
at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source)
at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source)
at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source)
at 
org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:212)
at 
org.apache.calcite.rel.metadata.RelMdUtil.getJoinRowCount(RelMdUtil.java:723)
at org.apache.calcite.rel.core.Join.estimateRowCount(Join.java:205)
at 
org.apache.hadoop.hive.ql.optimizer.calcite.stats.HiveRelMdRowCount.getRowCount(HiveRelMdRowCount.java:113)
at GeneratedMetadataHandler_RowCount.getRowCount_$(Unknown Source)
at GeneratedMetadataHandler_RowCount.getRowCount(Unknown Source)
at 
org.apache.calcite.rel.metadata.RelMetadataQuery.getRowCount(RelMetadataQuery.java:212)
at 
org.apache.hadoop.hive.ql.optimizer.calcite.stats.FilterSelectivityEstimator.(FilterSelectivityEstimator.java:62)
at 
org.apache.hadoop.hive.ql.optimizer.calcite.rules.HiveFilterSortPredicates$RexSortPredicatesShuttle.(HiveFilterSortPredicates.java:126)
at 
org.apache.hadoop.hive.ql.optimizer.calcite.rules.HiveFilterSortPredicates$RexSortPredicatesShuttle.(HiveFilterSortPredicates.java:120)
at 

[jira] [Created] (CALCITE-4702) Error when executing query with GROUP BY constant via JDBC adapter

2021-07-26 Thread Stamatis Zampetakis (Jira)
Stamatis Zampetakis created CALCITE-4702:


 Summary: Error when executing query with GROUP BY constant via 
JDBC adapter
 Key: CALCITE-4702
 URL: https://issues.apache.org/jira/browse/CALCITE-4702
 Project: Calcite
  Issue Type: Bug
  Components: core, jdbc-adapter
Affects Versions: 1.27.0
Reporter: Stamatis Zampetakis
Assignee: Stamatis Zampetakis


The following functionally equivalent SQL queries are accepted by Calcite and 
produce a valid plan 

{noformat}
select avg(salary) from employee group by true
select avg(salary) from employee group by 'a'
{noformat}

but they may fail if they are executed via the JDBC adapter since not all DBMS 
allow grouping by constants expressions. Moreover, what works for one may not 
work for the other. 

+Examples+
The {{GROUP BY TRUE}} query works in Postgres, and MySQL but fails in Redshift 
with the following exception:

{noformat}
com.amazon.redshift.util.RedshiftException: ERROR: non-integer constant in 
GROUP BY
{noformat}

The {{GROUP BY 'a'}} query works in MySQL but fails in Postgres with the 
following exception:

{noformat}
ERROR:  non-integer constant in GROUP BY
{noformat}

The {{GROUP BY}} constant essentially means {{GROUP BY}} nothing and there is a 
nice [blog 
post|https://blog.jooq.org/2018/05/25/how-to-group-by-nothing-in-sql/] listing 
some limitations of various DBMS. 



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


No match found for function signature IF

2021-07-26 Thread wrstrs
hi, all

how to solve this problem?




Caused by: org.apache.calcite.sql.validate.SqlValidatorException: No match 
found for function signature IF(

[jira] [Created] (CALCITE-4701) Implement and publish Gradle plugin for extending the parser

2021-07-26 Thread Vladimir Sitnikov (Jira)
Vladimir Sitnikov created CALCITE-4701:
--

 Summary: Implement and publish Gradle plugin for extending the 
parser
 Key: CALCITE-4701
 URL: https://issues.apache.org/jira/browse/CALCITE-4701
 Project: Calcite
  Issue Type: Improvement
  Components: core
Affects Versions: 1.27.0
Reporter: Vladimir Sitnikov


Currently, calcite-core.jar contains the relevant parser template files, 
however, the usage of the templates is not clear from the client perspective 
(especially when you are new to Calcite).

It would be nice if Calcite published a plugin that simplifies building a 
parser extension.

We could reuse the same plugin in calcite-babel module. Currently babel 
references $rootDir/core/... directrly rather than fetching the parser 
templates from core jar.

It might make sense to ship parser templates in its own jar file, however, I 
have no strong opinion here. Parser.jj consumes <1% of the compressed jar 
size(225K compresses to 44K), so it is not a big deal, yet having a meaningful 
artifact name for the parser templates looks like the right thing to do.



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