Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-34876

Non-nullable aggregates can return NULL in a correlated subquery

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.7, 3.0.2, 3.1.1, 3.2.0
    • Fix Version/s: 2.4.8, 3.0.3, 3.1.2, 3.2.0
    • Component/s: SQL
    • Labels:
      None

      Description

      Test case in scalar-subquery-select.sql:

      query
      SELECT t1a,
          (SELECT count(t2d) FROM t2 WHERE t2a = t1a) count_t2,
          (SELECT count_if(t2d > 0) FROM t2 WHERE t2a = t1a) count_if_t2,
          (SELECT approx_count_distinct(t2d) FROM t2 WHERE t2a = t1a) approx_count_distinct_t2,
          (SELECT collect_list(t2d) FROM t2 WHERE t2a = t1a) collect_list_t2,
          (SELECT collect_set(t2d) FROM t2 WHERE t2a = t1a) collect_set_t2,
          (SELECT hex(count_min_sketch(t2d, 0.5d, 0.5d, 1)) FROM t2 WHERE t2a = t1a) collect_set_t2
      FROM t1;
      
      Result
      val1a	0	0	NULL	NULL	NULL	NULL
      val1a	0	0	NULL	NULL	NULL	NULL
      val1a	0	0	NULL	NULL	NULL	NULL
      val1a	0	0	NULL	NULL	NULL	NULL
      val1b	6	6	3	[19,119,319,19,19,19]	[19,119,319]	0000000100000000000000060000000100000004000000005D8D6AB90000000000000000000000000000000400000000000000010000000000000001
      val1c	2	2	2	[219,19]	[219,19]	0000000100000000000000020000000100000004000000005D8D6AB90000000000000000000000000000000100000000000000000000000000000001
      val1d	0	0	NULL	NULL	NULL	NULL
      val1d	0	0	NULL	NULL	NULL	NULL
      val1d	0	0	NULL	NULL	NULL	NULL
      val1e	1	1	1	[19]	[19]	0000000100000000000000010000000100000004000000005D8D6AB90000000000000000000000000000000100000000000000000000000000000000
      val1e	1	1	1	[19]	[19]	0000000100000000000000010000000100000004000000005D8D6AB90000000000000000000000000000000100000000000000000000000000000000
      val1e	1	1	1	[19]	[19]	0000000100000000000000010000000100000004000000005D8D6AB90000000000000000000000000000000100000000000000000000000000000000
      

        Attachments

          Activity

            People

            • Assignee:
              tanelk Tanel Kiis
              Reporter:
              tanelk Tanel Kiis
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: