Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tablename= employee
- hivedatabase=testing
- 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()
- df1 = sqlContext.sql('select max(id) from {}.{}'.format(hivedatabase,tablename))
- df1.show()
- +------+
- | _c0|
- +------+
- | 1000|
- +------+
- 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()
- data.write.saveAsTable('testing.%s' %tablename, mode = 'append')
- select * from employee
- 1001
- 1002
- 1003
- and so on
- 1
- 2
- 3
- 1
- 2
- 3
- ....
- 1000
- 1001
- 1002
- .....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement