def mysqlExe(sql): conn = MySQLdb.connect (host = "10.10.111.111", user = "user", passwd = "password", db = "database") cursor = conn.cursor () cursor.execute (sql) cursor.close () conn.close () def hiveExeUpdate(sql,db,tableName,column,date): try: transport = TSocket.TSocket('10.20.134.199', 10000) transport = TTransport.TBufferedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = ThriftHive.Client(protocol) transport.open() client.execute(sql) update_sql= " update " + tableName + " set " + column + " = " + client.fetchOne() + " where id = '" + date + "'" mysqlExe(update_sql) //执行一条SQL语句 transport.close() except Thrift.TException, tx: print '%s' % (tx.message)
利用Python将Hive查询结果保存到MySQL
内容版权声明:除非注明,否则皆为本站原创文章。