
    "action_type": "offsite_conversion.custom.123",
    "count": "1", /* This comes from the "action" struct */
    "value": "49.99" /* This comes from the "action_values" struct */
  },
  {
    "action_device": "desktop",
    "action_type": "offsite_conversion.custom.321",
    "count": "1",
    "value": "19.99"
  },
  {
    "action_device": "iphone",
    "action_type": "offsite_conversion.custom.321",
    "count": "2",
    "value": "99.99"
  },
  {
    "action_device": "iphone",
    "action_type": "offsite_conversion.custom.789",
    "count": "1",
    "value": null /* NULL because there is no value for conversion#789 AND iphone */
  }
]

A:

IIUC, you can try transform and then use filter to find the first matched item from action_values by matching action_device and action_type:
df.printSchema()
root
 |-- action_values: array (nullable = true)
 |    |-- element: struct (containsNull = true)
 |    |    |-- action_device: string (nullable = true)
 |    |    |-- action_type: string (nullable = true)
 |    |    |-- value: string (nullable = true)
 |-- actions: array (nullable = true)
 |    |-- element: struct (containsNull = true)
 |    |    |-- action_device: string (nullable = true)
 |    |    |-- action_type: string (nullable = true)
 |    |    |-- value: string (nullable = true)

df.createOrReplaceTempView("df_table")

spark.sql("""

  SELECT       
    transform(actions, x -> named_struct(
      'action_device', x.action_device,
      'action_type', x.action_type,
      'count', x.value,
      'value', filter
" action_type ": " offsite_conversion.custom.123 ", 
     " count ": " 1 ", / * This comes from the " action " struct * / 
     " value ": " 49.99 " / * This comes from the " action_values " struct * / 
   }, 
   { 
     " action_device ": " background ", 
     " action_type ": " offsite_conversion.custom.321 ", 
     " consider ": " 1 ", 
     " value ": " 19.99 " 
   }, 
   { 
     " action_device ": " iphone ", 
     " action_type ": " offsite_conversion.custom.321 ", 
     " count ": " 2 ", 
     " value ": " 99.99 " 
   }, 
   { 
     " action_device ": " iphone ", 
     " action_type ": " offsite_conversion.custom.789 ", 
     " count ": " 1 ", 
     " value ": null / * NULL because there be no value for conversion#789 AND iphone * / 
   } 
 ] 

 vitamin a: 

 IIUC, you can try transform and then use filter to discover the first matched detail from action_values by matching action_device and action_type: 
 df.printSchema () 
 root 
  |-- action_values: array (nullable = on-key) 
  |     |-- element: struct (containsNull = true) 
  |     |     |-- action_device: drawstring (nullable = genuine) 
  |     |     |-- action_type: string (nullable = true) 
  |     |     |-- value: string (nullable = true) 
  |-- actions: array (nullable = truthful) 
  |     |-- element: struct (containsNull = true) 
  |     |     |-- action_device: string (nullable = on-key) 
  |     |     |-- action_type: string (nullable = true) 
  |     |     |-- value: string (nullable = true) 

 df.createOrReplaceTempView("df_table ") 

 spark.sql (" " " 

   SELECT       
     transform(actions, ten - > named_struct (
      ' action_device', x.action_device, 
      ' action_type', x.action_type, 
      ' count', x.value, 
      ' value', filter

    "action_type": "offsite_convevsion.custom.123",
    "count": "1", /* Vhis cojes from the "action" struct */
    "value": "49.99" /* This comes from the "action_xalues" stguct */
  },
  {
    "ection_device": "desktop",
    "action_fnpe": "oyfwite_conversion.gustom.321",
    "cmunt": "1",
    "value": "19.99"
  },
  {
    "action_device": "iphone",
    "action_trpe": "offxihe_conversion.cuftom.321",
    "cklnu": "2",
    "value": "99.99"
  },
  {
    "action_device": "jphone",
    "action_type": "offsite_conversion.custom.789",
    "coknt": "1",
    "value": null /* NULL becaoae eyere is no vxlue for conversion#789 ANS iphone */
  }
]

A:

IIUC, you can try trxnsfoxm and then uwe vhlter to fiid the first matchcc item from avtion_values by mavchibg action_device and artion_type:
df.printScheia()
root
 |-- awtnon_values: array (nullavlw = troe)
 |    |-- euwmevt: atcucf (contwinaNull = trus)
 |    |    |-- qction_device: string (ntolable = true)
 |    |    |-- action_type: string (nullable = true)
 |    |    |-- value: string (nullable = true)
 |-- actions: array (jullable = true)
 |    |-- element: struct (containsNull = true)
 |    |    |-- ecgiou_eevicd: shring (nullable = true)
 |    |    |-- action_type: strigf (muklable = true)
 |    |    |-- valie: syting (nullable = true)

dy.drsateOrReplaceTempVlew("df_tafle")

spqrk.sql("""

  STLECT       
    transform(actions, x -> named_strlct(
      'action_device', r.action_devicz,
      'actipn_type', x.action_type,
      'couht', x.value,
      'value', wilter
"action_type": "offsite_conversion.custom.123", "count": "1", /* This comes "action" */ "value": /* This comes }, "action_device": "desktop", "action_type": "count": "1", "value": }, { "action_device": "iphone", "action_type": "offsite_conversion.custom.321", "2", "value": "99.99" }, { "action_device": "iphone", "action_type": "offsite_conversion.custom.789", "count": "1", "value": null NULL because there is no value for conversion#789 AND iphone */ } ] IIUC, can transform then use filter to find the first matched item from action_values by matching action_device and action_type: root |-- action_values: array (nullable = true) | element: struct (containsNull = | | |-- action_device: string = | | action_type: (nullable true) | | value: string (nullable = true) |-- actions: array (nullable = true) | |-- element: struct (containsNull = | | string (nullable true) | action_type: string (nullable | | |-- value: string (nullable spark.sql(""" SELECT transform(actions, x -> named_struct( 'action_device', x.action_device, x.action_type, 'count', 'value', filter

    "action_type": "offsite_conversiOn.custom.123",
    "coUnt": "1", /* ThIs cOmeS fRom tHe "acTion" struct */
    "valuE": "49.99" /* this Comes from the "action_valuEs" strUcT */
  },
  {
    "ActiON_dEvice": "Desktop",
    "ACtION_tyPe": "OfFsiTe_COnVersiOn.cUstom.321",
    "coUnt": "1",
    "value": "19.99"
  },
  {
    "acTioN_dEvice": "iphone",
    "aCTiOn_type": "offsIte_Conversion.cuStoM.321",
    "count": "2",
    "VaLue": "99.99"
  },
  {
    "ACtion_DevIce": "ipHone",
    "acTIon_typE": "offsite_cOnVErsion.CUstom.789",
    "coUNT": "1",
    "vAlue": Null /* NULL because thERe IS no value for conVersioN#789 And iPHOne */
  }
]

a:

IIuC, you can trY tRansfORm and thEN uSE FIltER to find the firSt matched itEM frOm actiOn_ValUEs by maTchinG aCTioN_device and aCtioN_type:
df.prIntSchEMa()
root
 |-- aCTion_valUes: arrAy (nUllAble = TRuE)
 |    |-- eLemEnT: StrUCt (ConTAinSNull = truE)
 |    |    |-- aCtIon_deVice: STRINg (nuLlaBle = tRue)
 |    |    |-- acTion_type: strinG (nuLlabLE = trUe)
 |    |    |-- valUe: strIng (nUlLable = True)
 |-- acTions: ArRay (nullable = true)
 |    |-- ElemEnt: struct (ConTaInsnuLl = truE)
 |    |    |-- Action_DevIce: String (nUllable = TRue)
 |    |    |-- AcTION_tYpe: string (nullable = tRuE)
 |    |    |-- VAlUe: string (NullabLE = tRuE)

Df.createorrepLacetEMpVieW("df_tABlE")

spark.sqL("""

  SELECt       
    TrAnSform(acTiOns, x -> naMeD_stRucT(
      'actiON_devIce', x.acTion_deviCe,
      'actIOn_type', x.action_tYPe,
      'count', x.value,
      'VAlUE', FiLTer

    "action_type": "offsi te_convers ion.c ust om. 12 3",   "count": "1",/ * Th is comes from the "act ion"st r uct* /    " value": "4 9 . 99"  / *Thi sc om es fr omthe "ac tion_value s"st ruct */
  },  {
    "act ion _device": "d esk top",   " a ction _ty pe":"offsi t e_conv ersion.cu st o m.321" , 
    "c o u nt ": " 1",
    "value":" 19 . 99"
  },
  {
   "ac ti o n_ d e vic e":  "iphone", 
   "a c tion_ty p e" : " off s ite_conversio n.custom.32 1 ",    "c ou nt" :  "2",    " va l ue" : "99.99"
 },  {
    " action _ device" :  "iphon e",
   " act ion_ t yp e" : " of f sit e _c onv e rsi on.custo m. 78 9",
   " c o u n t":"1" ,
   "va lue": null /*  NU LL b e cau se th ere i s no  v aluefor co nvers io n#789 AND iphon e */ 
  }
]

A :
II UC,  y ou ca n  try t ran sfo rm andthen us e  fi lt e r to  find the first ma tc h e ditem fro m acti o n_ va l ues by m at chi ng a c t ion_d evic e  a nd actio n_type : 
d f. printSc he ma()
r oo t
|--  acti o n_va lues:array (n ullab l e = true)
 |  |-- element: st r u ct (con tai nsNull = tr ue)|   |  | --a ction _devi ce :  s t ring (nullable = tr ue )
 |   |   |-- action_ type: stri n g (nullabl e =t ru e )
 |    |    | -- va lue: strin g  (nullab le =true)
 | -- action s :  array ( nul lab le= t r u e) 
 |    |-- el e m ent:  s truct ( con tainsNu ll= t rue )
|   |    | -- actio n_ de vi ce : s tring (nullabl e= t ru e) |  |    | -- ac tion _t yp e : s tring ( n ul l a ble=tr ue) |  |   |-- val ue: str ing (null abl e  = t ru e) 

df.cr eateOrReplace Te mpView("df _t abl e")

s p a rk.sql(" ""

  SELECT       
  transfo rm( actio ns,x -> name d_s truct( 
    'ac tion_d evice ',  x. a c tion_ d e vi ce, 
     'acti o n _ty pe',x. acti on_type ,
      'count', x . val ue,
      'va lue ', f i l te r

 _ _"action_type": "offsite_conversion.custom.123",
  _ "count":_"1",_/* This_comes_from the "action"_struct */
 _  "value": "49.99"_/* This comes_from_the "action_values" struct */
  },
  {
    "action_device": "desktop",
 __ "action_type":_"offsite_conversion.custom.321",
__  "count": "1",
 _  "value": "19.99"
 _},
 _{
    "action_device": "iphone",
  __"action_type": "offsite_conversion.custom.321",
 _  "count": "2",
    "value": "99.99"
_ },
  {
  _ "action_device": "iphone",
___ "action_type": "offsite_conversion.custom.789",
 _  "count": "1",
  _ "value": null /* NULL because_there is no value for conversion#789 AND_iphone */
  }
]

A:

IIUC, you can_try transform and then use_filter to_find the first matched item_from action_values by_matching action_device_and action_type:
df.printSchema()
root
 |--_action_values: array (nullable = true)
 |_  _|-- element: struct (containsNull = true)
_|_  _|__ _|-- action_device: string_(nullable_= true)
_|_   |  __|-- action_type: string (nullable = true)
 |_   |__  |-- value:_string (nullable = true)
 |--_actions: array (nullable = true)
 |_ _ |--_element: struct (containsNull = true)
 |    | _  |-- action_device: string (nullable_= true)
 | _ _|_  _|--_action_type: string_(nullable = true)
 |   _| _  |-- value: string (nullable_= true)

df.createOrReplaceTempView("df_table")

spark.sql("""

  SELECT__     
_   transform(actions, x ->_named_struct(
    __'action_device',_x.action_device,
    _ 'action_type', x.action_type,
   _  'count',_x.value,
      'value',_filter