简体   繁体   中英

How do I select from an array of struct

I'm using HIVE for Hadoop. I want to select the price value from the price field in a struct. But the struct is part of an array of struct.

uid     string
timestamp       int
eventdate       string
products    array<struct
    <internalId:int,
    category:int,
    alternateId:string,
    price:double,
    quantity:int,
    externalId:string>>

I will be querying using an exectued .HQL file, not through the terminal window.

(ie hive -f blah.hql > blah.txt)

How do I select the price out of the product array of struct?

-- don't know which of these, if any work. getting weird or null output.

Select  
  table.products.price,  
  table.products[0].price,  
  table.products['price']
from table

Answer

produts[0].price

Since the struct is the ONLY element in the array, for a given row in the table. While this can allow for future elements in the products array, it would have nice to make that column JUST a struct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM