(
(let $1 '('key_mod (OptionalType (DataType 'Int32))))
(let $2 (DataType 'String))
(let $3 '('"subkey" $2))
(let $4 '('"value" $2))
(let $5 (StructType $1 $3 $4))
(let $6 '('('"_logical_id" '5426) '('"_id" '"5eaaba76-abd5ae5b-8b467255-1d8ac5f7") '('"_wide_channels" $5)))
(let $7 (DqPhyStage '() (lambda '() (block '(
  (let $19 '@@["StructType";[["key";["DataType";"String"]];["subkey";["DataType";"String"]];["value";["DataType";"String"]]]]@@)
  (let $20 (YqlRowSpec '('NativeYtTypeFlags '0) '('StrictSchema '1) '('UniqueKeys '0) '('Type $19)))
  (let $21 (YtMeta '('CanWrite '1) '('DoesExist '1) '('YqlCompatibleScheme '1) '('InferredScheme '0) '('IsDynamic '0) '('Attrs '('('"native_strict_schema" '"false")))))
  (let $22 (YtStat '('Id '"Input") '('RecordsCount '"4") '('DataSize '"166") '('ChunkCount '1) '('ModifyTime '0) '('Revision '0)))
  (let $23 (YtTable '"Input" $20 $21 $22 '() (Void) (Void) '"/Root/plato"))
  (let $24 '('"key" '"subkey" '"value"))
  (let $25 (YtReadTable! world (DataSource '"yt" '"/Root/plato") '((YtSection '((YtPath $23 $24 (Void) (Void))) '()))))
  (let $26 (lambda '($27 $28 $29) (% (SafeCast $27 (OptionalType (DataType 'Uint32))) (Int32 '"10")) $28 $29))
  (return (FromFlow (WideMap (DqReadWideWrap $25 '()) $26)))
))) $6))
(let $8 (DqCnHashShuffle (TDqOutput $7 '0) '('0) '0 '"HashV2"))
(let $9 (Bool 'true))
(let $10 (ListType $2))
(let $11 (StructType '('"column1" $10) '('"column2" $10) $1))
(let $12 '('('"_logical_id" '5900) '('"_id" '"111cde98-d4077dd8-f06a2b2-47cfd6f6") '('"_wide_channels" $11)))
(let $13 (DqPhyStage '($8) (lambda '($30) (block '(
  (let $31 (NarrowSqueezeToDict (ToFlow $30) (lambda '($34 $35 $36) $34) (lambda '($37 $38 $39) (AsStruct '('key_mod $37) '('"subkey" $38) '('"value" $39))) '('Auto 'Many)))
  (let $32 (Chopper (OrderedFlatMap $31 (lambda '($40) (OrderedFlatMap (DictPayloads $40) (lambda '($41) (Sort $41 $9 (lambda '($42) (Member $42 '"subkey"))))))) (lambda '($43) (Member $43 'key_mod)) (lambda '($44 $45) (AggrNotEquals $44 (Member $45 'key_mod))) (lambda '($46 $47) (block '(
    (let $48 (Chain1Map $47 (lambda '($53) (block '(
      (let $54 (Member $53 '"value"))
      (let $55 '('AggregateList0 (AsList $54)))
      (let $56 (Member $53 '"subkey"))
      (let $57 '('AggregateList1 (AsList $56)))
      (let $58 (AsStruct $55 $57 '('key_mod (Member $53 'key_mod)) '('"subkey" $56) '('"value" $54)))
      (return '($58 (AsStruct $55 $57)))
    ))) (lambda '($59 $60) (block '(
      (let $61 (Nth $60 '1))
      (let $62 (Member $59 '"value"))
      (let $63 '('AggregateList0 (Insert (Member $61 'AggregateList0) $62)))
      (let $64 (Member $59 '"subkey"))
      (let $65 '('AggregateList1 (Insert (Member $61 'AggregateList1) $64)))
      (let $66 (AsStruct $63 $65 '('key_mod (Member $59 'key_mod)) '('"subkey" $64) '('"value" $62)))
      (return '($66 (AsStruct $63 $65)))
    )))))
    (let $49 (StructType '('AggregateList0 $10) '('AggregateList1 $10) $1 $3 $4))
    (let $50 (ListType $49))
    (let $51 (VariantType (StructType '('group $50) '('singleRow $49))))
    (let $52 (Condense1 $48 (lambda '($67) (block '(
      (let $68 (Nth $67 '0))
      (let $69 (Variant $68 'singleRow $51))
      (return '((Member $68 '"subkey") $69))
    ))) (lambda '($70 $71) (AggrNotEquals (Member (Nth $70 '0) '"subkey") (Nth $71 '0))) (lambda '($72 $73) (block '(
      (let $74 (Nth $72 '0))
      (let $75 (Visit (Nth $73 '1) 'group (lambda '($76) (Variant (Insert $76 $74) 'group $51)) 'singleRow (lambda '($77) (Variant (AsList $77 $74) 'group $51))))
      (return '((Nth $73 '0) $75))
    )))))
    (return (OrderedFlatMap $52 (lambda '($78) (block '(
      (let $79 (Visit (Nth $78 '1) 'group (lambda '($80) (IfPresent (Last $80) (lambda '($81) (OrderedMap (Collect (Map $80 (lambda '($82) (AsStruct '('key_mod (Member $82 'key_mod)) '('"subkey" (Member $82 '"subkey")) '('"value" (Member $82 '"value")))))) (lambda '($83) (AsStruct '('AggregateList0 (Member $81 'AggregateList0)) '('AggregateList1 (Member $81 'AggregateList1)) '('key_mod (Member $83 'key_mod)) '('"subkey" (Member $83 '"subkey")) '('"value" (Member $83 '"value")))))) (List $50))) 'singleRow (lambda '($84) (AsList $84))))
      (return (Map $79 (lambda '($85) (AsStruct '('AggregateList0 (Member $85 'AggregateList0)) '('AggregateList1 (Member $85 'AggregateList1)) '('key_mod (Member $85 'key_mod))))))
    )))))
  )))))
  (let $33 (lambda '($86) (Member $86 'AggregateList0) (Member $86 'AggregateList1) (Member $86 'key_mod)))
  (return (FromFlow (ExpandMap $32 $33)))
))) $12))
(let $14 (DqCnUnionAll (TDqOutput $13 '0)))
(let $15 (DqPhyStage '($14) (lambda '($87) (FromFlow (NarrowMap (WideSort (ToFlow $87) '('('2 $9) '('0 $9))) (lambda '($88 $89 $90) (AsStruct '('"column1" $88) '('"column2" $89) '('key_mod $90)))))) '('('"_logical_id" '5944) '('"_id" '"dd895f5f-88b4a0d1-4fcc8649-25fd5d04"))))
(let $16 '($7 $13 $15))
(let $17 '('key_mod '"column1" '"column2"))
(let $18 (DqCnResult (TDqOutput $15 '0) $17))
(return (KqpPhysicalQuery '((KqpPhysicalTx $16 '($18) '() '('('"type" '"generic")))) '((KqpTxResultBinding (ListType $11) '0 '0)) '('('"type" '"query"))))
)
