Uploaded image for project: 'IMPALA'
  1. IMPALA
  2. IMPALA-10838

Error when struct returned from WITH() and used in an ORDER BY

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • None
    • Frontend

    Description

      with sub as (
          select id, small_struct
          from functional_orc_def.complextypes_structs
          where length(small_struct.s) > 5)
      select sub.id, sub.small_struct from sub order by sub.small_struct.i desc;
      

      The above query results an error when trying to run SlotRef.toThrift()

      ERROR: IllegalStateException: Illegal reference to non-materialized tuple: debugname=InlineViewRef sub alias=sub tid=2
      

      If I rewrite the query a bit to return the member of the struct from the inline view (WITH()) and use this in the ORDER by then the query succeeds as expected:

      with sub as (
          select id, small_struct, small_struct.i as si
          from functional_orc_def.complextypes_structs where small_struct.i > 19200)
      select sub.id, sub.small_struct from sub order by sub.si desc;
      

      In SortNode.toThrift() I checked what the sort exprs and the resolved tuple exprs are and I see a difference that could be the cause.
      In the problematic case:

      - sort exprs in SortNode:
        SlotRef{label=small_struct.i, type=INT, id=15}
      - resolved exprs in SortNode: 
        SlotRef{label=id, path=id, type=INT, id=0} 
        SlotRef{label=small_struct, path=small_struct, type=STRUCT<i:INT,s:STRING>, id=1} 
        *SlotRef{label=sub.small_struct.i, path=sub.small_struct.i, type=INT, id=10}*
      

      In the successful case:

      - sort exprs in SortNode: 
        SlotRef{label=si, type=INT, id=14}
      - resolved exprs in SortNode: 
        SlotRef{label=id, path=id, type=INT, id=0} 
        SlotRef{label=small_struct, path=small_struct, type=STRUCT<i:INT,s:STRING>, id=1} 
        *SlotRef{label=small_struct.i, path=small_struct.i, type=INT, id=4}*
      

      Attachments

        Issue Links

          Activity

            People

              daniel.becker Daniel Becker
              gaborkaszab Gabor Kaszab
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: