Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. // Creates a DataFrame based on a table named "people"
  2. // stored in a MySQL database.
  3. String url =
  4. "jdbc:mysql://yourIP:yourPort/test?user=yourUsername;password=yourPassword";
  5. DataFrame df = sqlContext
  6. .read()
  7. .format("jdbc")
  8. .option("url", url)
  9. .option("dbtable", "people")
  10. .load();
  11.  
  12. // Looks the schema of this DataFrame.
  13. df.printSchema();
  14.  
  15. // Counts people by age
  16. DataFrame countsByAge = df.groupBy("age").count();
  17. countsByAge.show();
  18.  
  19. // Saves countsByAge to S3 in the JSON format.
  20. countsByAge.write().format("json").save("s3a://...");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement