您的位置:首页 > 数据库

基于spark1.3.1的spark-sql实战-02

2015-06-01 14:02 489 查看
Hive Tables

将HIVE_HOME/conf/
hive-site.xml
 文件copy到SPARK_HOME/conf/下

 When not configured by the hive-site.xml, the context automatically creates 
metastore_db
 and 
warehouse
 in
the current directory.

// sc is an existing SparkContext.
val sqlContext = new org.apache.spark.sql.hive.HiveContext(sc)

sqlContext.sql("CREATE TABLE IF NOT EXISTS src (key INT, value STRING)")
sqlContext.sql("LOAD DATA LOCAL INPATH 'examples/src/main/resources/kv1.txt' INTO TABLE src")

// Queries are expressed in HiveQL
sqlContext.sql("FROM src SELECT key, value").collect().foreach(println)



JDBC To Other Databases



加载mysql数据库:test,表:t_user_new返回DataFrame



查询数据:




Performance Tuning



spark 程序操作JDBC:













未完待续~~~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息