我正在尝试将hive列的输出转换为键值对。
sqlContext = HiveContext(sc)
id1 = sqlContext.sql("select instance_id from temp_table")
pairs1 = id1.map(lambda s: (int(s), 'Configuration'))
我收到以下错误
TypeError: int() argument must be a string or a number, not 'Row'
我不确定如何将Hive Row对象强制转换为整数,以便我可以将map函数应用于该
例如,id1是一个数据帧,当我将collect()应用于它时,它返回
[Row(_c0=12616821)]
我需要从Row Object中提取值。如果有任何与此问题相关的解决方案,请告诉我
答案 0 :(得分:3)
我想出了一种从Row Object获取整数值的方法。最初我想过应用类型转换并将其转换为int和其他一些方法。但似乎我们可以通过应用索引来获得值,就像那样简单
>> id1 = sqlContext.sql("select int(id) as id from temp_table limit 1")
>> temp = df1.select('id').collect()
>> temp
[Row(id = 9331413)]
>> temp[0][0]
9331413