我找到了一种使用 python 将数据从列表复制/插入到弹性表(垂直)的方法:
对于列表
# for python list
tempList = list()
tempList.append('{ "_id" : "01011", "city" : "CHESTER-APL21", "loc" : [ -72.988761, 42.279421 ], "pop" : 1688, "state" : "MA" }')
tempList.append('{ "_id" : "01011", "city" : "CHESTER-APL21", "loc" : [ -72.988761, 42.279421 ], "pop" : 1688, "state" : "MA" }')
cur.copy( "COPY STG.unstruc_data FROM STDIN parser fjsonparser() ", ''.join(tempList))
connection.commit()
对于 JSON
# for json file
with open("D:/SampleCSVFile_2kb/tweets.json", "rb") as fs:
my_file = fs.read().decode('utf-8')
cur.copy( "COPY STG.unstruc_data FROM STDIN parser fjsonparser()", my_file)
connection.commit()
对于 CSV
# for csv file
with open("D:/SampleCSVFile_2kb/SampleCSVFile_2kb.csv", "rb") as fs:
my_file = fs.read().decode('utf-8','ignore')
cur.copy( "COPY STG.unstruc_data FROM STDIN PARSER FDELIMITEDPARSER (delimiter=',', header='false') ", my_file) # buffer_size=65536
connection.commit()