Advertisement
Guest User

Untitled

a guest
Mar 1st, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. tablename= employee
  2. hivedatabase=testing
  3.  
  4. df = sqlContext.read.format("jdbc").option("url", "jdbc:mysql://xxxxx/history").option("driver", "com.mysql.jdbc.Driver").option("dbtable", "employee").option("user", "xxxxx").option("password", "xxxx").load()
  5.  
  6. df1 = sqlContext.sql('select max(id) from {}.{}'.format(hivedatabase,tablename))
  7.  
  8. df1.show()
  9.  
  10. +------+
  11. | _c0|
  12. +------+
  13. | 1000|
  14. +------+
  15.  
  16. df3 = sqlContext.read.format("jdbc").option("url", "jdbc:mysql://xxxxx/history").option("driver", "com.mysql.jdbc.Driver").option("dbtable", "(select * from employee where id >= 1000) as testing").option("user", "xxxxx").option("password", "xxxx").load()
  17.  
  18. data.write.saveAsTable('testing.%s' %tablename, mode = 'append')
  19.  
  20. select * from employee
  21.  
  22. 1001
  23. 1002
  24. 1003
  25. and so on
  26. 1
  27. 2
  28. 3
  29.  
  30. 1
  31. 2
  32. 3
  33. ....
  34. 1000
  35. 1001
  36. 1002
  37. .....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement