SparkSql读取HDFS


public class SparkSqlBathLog {
public static void main(String[] args) {
SparkConf conf = new SparkConf();
conf.setMaster("local[2]").setAppName("jsonfile");
// spark 上下文
SparkContext sc = new SparkContext(conf);
//创建sqlContext获取sqlcontext
SQLContext sqlContext = new SQLContext(sc);
//加载txt文件 从hdfs
//RDD<String> stringRDD = sc.textFile("hdfs://192.168.48.11:9000/aaa/ssooo.txt");

DataFrame df = sqlContext.read().json("hdfs://node1:9000/aaa/ssooo.txt ");
df.show(30);
//
// DataFrame dfa = sqlContext.read().load("hdfs://192.168.48.11:9000/aaa/ssooo.txt");
// dfa.show(30);
// sqlContext.sql("use hive");
// df.show(20);
DataFrame df1 = sqlContext.read().format("json").load("./test.txt");
df1.show(30);

// df1.coalesce(1).write().format("String").save("hive 路径");


// DataFrame corrupt_record = df.drop("_corrupt_record");
// corrupt_record.show(20);
// DataFrame table = corrupt_record.select("table");
// table.na().drop("all").show(20);
// JavaRDD<Row> rowJavaRDD = table.toJavaRDD();
// df1.show(20);
// df.show();
sc.stop();
}
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM