如何在HIVE中将几列聚合到JSON文件中并避免为空

时间:2018-11-12 22:32:11

标签: arrays json hive

user_id reservation_id  nights  price 
--------------------------------------
AAA     10001             1     100
AAA     10002             1     120
BBB     20003             7     350
ccc     10005                   150
DDD     10007             3
CCC     10006             5      

user_id    reservation_details
AAA        [{"nights":"1", "price":"100"}, {"nights":"1","price":"120"}]
BBB        [{"nights":"7", "price":"350"}]
CCC        [{"price":"150"}, {"nights":"3"}]
DDD        [{"nights":"5"}]

我的查询是

select user_id
       ,concat(" 
               {",concat_ws(',',collect_list(concat(string(reservation_id),": 

              {'nights':",string(nights),",'price':",string(price),"}"))),"}")  as 
      reservation_details 
from  mytable
group by user_id    

我想消除具有空值的列,并将单引号转换为看起来像JSON的双引号。

1 个答案:

答案 0 :(得分:0)

使用内置数据类型from scipy import mat, matrix, integrate from scipy.integrate import quad import numpy as np from numpy import linalg as la import os from matplotlib import pyplot as plt # Defining variables and functions MP=float(9.10938356e-31) #mass of electron in kg WL=float(1e-10) #length of well in meters CON=float(1.60218e-19) #constant height in joules Hb = float(1.054571726e-34) #reduced planck's constant in J s NB=int(input("Number of basis functions ")) #define number of basis sets to be used #####Potential energy of initial state##### PE=[] for j in range(1,NB+1): alist=[] for k in range(1,NB+1): F1=integrate.quad(lambda x:((2/WL)*np.sin((k*np.pi*x)/WL)* ((-CON)*np.sin(np.pi*x/WL))*np.sin((j*np.pi*x)/WL)),0,WL)[0] if F1 < -1e-25: F1=F1 elif F1 > 1e-25: F1=F1 else: F1=0 alist.append(F1) PE.append(alist) PEarray=np.asarray(PE) #####Kinetic Energy of initial state##### KE=[] for j in range(1,NB+1): blist=[] for k in range(1,NB+1): F2=integrate.quad(lambda x:(((((Hb**2)*(j**2)*(np.pi**2))/(MP*(WL**3)))* ((np.sin(j*np.pi*x/WL))*(np.sin(k*np.pi*x/WL))))),0,WL)[0] if F2 < -1e-25: F2=F2 elif F2 > 1e-25: F2=F2 else: F2=0 blist.append(F2) KE.append(blist) KEarray=np.asarray(KE) #####Adding PE and KE to give the full hamiltonian of the initial state##### #####Then convert the list to a numpy array##### sum=[0]*NB for i in range(NB): sum[i]=[0]*NB for y in range(len(PEarray)): for z in range(len(PEarray[0])): sum[y][z]=PEarray[y][z]+KEarray[y][z] npsum=np.asarray(sum) EVal, EVec=la.eigh(npsum) wavefxns=[] for j in range(1,NB+1): clist=[] for k in range(1,NB+1): F3 = (lambda x: ((EVec.item(k-1, j-1))* (np.sin((((k+1)*np.pi)/WL)*x)))) clist.append(F3) wavefxns.append(clist) npwavefxns=np.asarray(wavefxns) EQS=[] for j in range(0,NB): F4=np.sum(npwavefxns.item(j)) EQS.append(F4) npEQS=np.asarray(EQS) for j in range(0,NB): wfxn1=(lambda x: ((npEQS.item(j))(x))) plt.xlabel("Box length") plt.ylabel("energy") x = np.linspace(0,WL,500) plt.plot(x, wfxn1(x), '--m') plt.show() map以及array表达式来处理case

null