google / zetasql

ZetaSQL - Analyzer Framework for SQL
Apache License 2.0
2.32k stars 219 forks source link

[java] analyzer does not identify implicit return type for functions with ANY TYPE arguments #66

Open vglocus opened 3 years ago

vglocus commented 3 years ago

CREATE TEMP FUNCTION test(x INT64) AS (x+1) correctly identifies implicit signature (INT64 x) -> INT64.

CREATE TEMP FUNCTION test(x INT64) AS ('hello world') correctly identifies implicit signature (INT64 x) -> STRING.

CREATE TEMP FUNCTION test(x ANY TYPE) AS ('hello world') incorrectly identifies implicit signature (ANY TYPE x) -> ANY TYPE where I would expect (ANY TYPE x) -> STRING.

CREATE TEMP FUNCTION test(x ANY TYPE) RETURNS STRING AS ('hello world') correctly identifies explicit signature (ANY TYPE x) -> STRING.

I am running using java api and zeta version 2020.10.1

jshute111 commented 3 years ago

It was assumed that if the input arguments are templated, the signature is templated and we need to know the argument types to figure out a return type. For the special case where the return type in a templated function does not depend on the input argument types, it may be possible to figure out the concrete return type, but this is challenging because we can't actually analyze the body expression without knowing the types. We'd need something that can prove the output type is always X, for any input type, and we don't have something like that currently.

Special casing for when all templated args are unreferenced in the body is possible, but I don't know if that's common enough to be worth doing.

On Fri, Mar 19, 2021 at 11:13 AM Viktor Gerdin @.***> wrote:

CREATE TEMP FUNCTION test(x INT64) AS (x+1) correctly identifies implicit signature (INT64 x) -> INT64.

CREATE TEMP FUNCTION test(x INT64) AS ('hello world') correctly identifies implicit signature (INT64 x) -> STRING.

CREATE TEMP FUNCTION test(x ANY TYPE) AS ('hello world') incorrectly identifies implicit signature (ANY TYPE x) -> ANY TYPE where I would expect (ANY TYPE x) -> STRING.

I am running using java api and zeta version 2020.10.1

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/google/zetasql/issues/66, or unsubscribe https://github.com/notifications/unsubscribe-auth/AL44HXSEPNWPRN2GAVGUC3TTEOH4VANCNFSM4ZPITQRQ .