Вот схема, с которой я имею дело, вместе с образцами данных. Проблема, с которой я сталкиваюсь, заключается в том, что когда-то я получал все элементы в массиве, иногда я получал недостающие элементы, как видно из второго набора данных, и расположение элементовтакже изменилось, когда я вставляю данные, используя встроенную функцию, это портит данные и перемещает значения в разные столбцы.
root
|-- StoreID: string (nullable = true)
|-- StoreName: string (nullable = true)
|-- stock: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- StockLocation_x: double (nullable = true)
| | |-- StockLocation_y: double (nullable = true)
| | |-- StockLife: long (nullable = true)
| | |-- GoodPrior: double (nullable = true)
| | |-- SCN: double (nullable = true)
| | |-- temp: double (nullable = true)
| | |-- STime: long (nullable = true)
| | |-- StockType: string (nullable = true)
{
"storeID" : "LA_1234",
"storeName" : "LA Store",
"stocks" : [ {
"StockLocation_x" : [ 0.76, 0.75, 0.71 ],
"StockLocation_y" : [ 0.79, 0.03, 0.79 ],
"StockLife" : [ 1, 2, 5 ],
"GoodPrior" : [ 12345567, 12345432, 45678],
"SCN" : [ 423, 256, 654],
"temp" : [ 22, 18, 23 ],
"STime" : [ 1538128801336, 1538128810408, 1538128818420 ],
"StockType" : [ G, F, M]
},
{
"StockType" : [ G, F, M],
"SCN" : [ 423, 256, 654],
"StockLocation_x" : [ 0.76, 0.75, 0.71 ],
"StockLocation_y" : [ 0.79, 0.03, 0.79 ],
"StockLife" : [ 1, 2, 5 ],
"STime" : [ 1538128801336, 1538128810408, 1538128818420 ],
} ]
}
Я использую следующую инструкцию для создания и запроса моих данных
CREATE EXTERNAL TABLE IF NOT EXISTS LA_STORES(
StoreID string,
StoreName string,
stocks array<struct<
StockLocation_x: string,
StockLocation_y: string,
StockLife: string,
GoodPrior: string,
SCN: string,
temp: string,
StockType: string
>>
) row format serde 'org.openx.data.jsonserde.JsonSerDe'
location 'hdfs location'
CREATE EXTERNAL TABLE IF NOT EXISTS LA_STORES_INLINE(
StoreID string,
StoreName string,
StockLocation_x string,
StockLocation_y string,
StockLife string,
GoodPrior string,
SCN string,
temp string,
StockType string
)
PARTITIONED BY (year smallint, month smallint, day smallint)
STORED AS ORC
LOCATION '/data/inline'
TBLPROPERTIES ("orc.compress"="SNAPPY", "orc.create.index"="true",
"orc.stripe.size"="67108864","orc.row.index.stride"="90000");
Вставка данных в таблицу с использованием встроенной функции
INSERT INTO LA_STORES_INLINE PARTITION (year, month, day)
select
StoreID , StoreName , s.StockLocation_x, s.StockLocation_y, s.StockLife,
s.GoodPrior, s.SCN, s.temp , s.StockType
from LA_STORES
lateral view outer inline(stocks) s as StockLocation_x, StockLocation_y,
StockLife, GoodPrior, SCN, temp , StockType
where size(stocks) > 0