Mihai Budiu created CALCITE-7347:
------------------------------------

             Summary: UNKNOWN type inferred for array element type
                 Key: CALCITE-7347
                 URL: https://issues.apache.org/jira/browse/CALCITE-7347
             Project: Calcite
          Issue Type: Bug
          Components: core
    Affects Versions: 1.41.0
            Reporter: Mihai Budiu


Consider this example:
{code:java}
SELECT DISTINCT
  t.f1,
  t.f2,
  CAST(t.f3 AS TEXT ARRAY) AS f3,
  t.f4
FROM (VALUES
  ('a', 1, ARRAY['by'], true),
  ('b', 1, ARRAY(), false)
) AS t (f1, f2, f3, f4) {code}
The plan produced is the following:
{code:java}
    [Logical plan]
    LogicalAggregate(group=[{0, 1, 2, 3}]), id = 80
      LogicalProject(f1=[$0], f2=[$1], f3=[CAST($2):VARCHAR CHARACTER SET 
"UTF-8" NOT NULL ARRAY NOT NULL], f4=[$3]), id = 79
        LogicalUnion(all=[true]), id = 78
          LogicalProject(EXPR$0=[_UTF-8'a'], EXPR$1=[1], 
EXPR$2=[CAST(ARRAY(_UTF-8'by')):UNKNOWN NOT NULL ARRAY NOT NULL], 
EXPR$3=[true]), id = 75
            LogicalValues(tuples=[[{ 0 }]]), id = 67
          LogicalProject(EXPR$0=[_UTF-8'b'], EXPR$1=[1], EXPR$2=[ARRAY()], 
EXPR$3=[false]), id = 77
            LogicalValues(tuples=[[{ 0 }]]), id = 69 {code}
Note that the array  ARRAY['a'] is cast to an UNKNOWN ARRAY using a project, 
then the union is cast to an VARCHAR ARRAY. I think that a much more logical 
choice would be to cast the empty array to a VARCHAR ARRAY instead.



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

Reply via email to