我正在尝试使用sparksql将值插入到配置单元表中。我将值存储在列表中,并尝试使用字符串插入。
SparkSession spark = SparkSession
.builder()
.appName("Spark + Hive + sentiment Analyzer")
.master("local[*]")
.config("hive.metastore.uris","thrift://localhost:9083")
.enableHiveSupport()
.getOrCreate();
spark.sql("create table if not exists output (srno int, values_string string)");
for(String str: nameAndCity){
//System.out.println(str);
str = str.replaceAll("\"","'");
spark.sql("insert into output values(" + i +","+ "'"+ str+"'"+")");
i++;
}
我有包含 double quotes
, single quotes
,以及其他字符。我试着取消 double quote
但是现在用。
我得到以下错误:
Exception in thread "main" java.lang.NullPointerException
at spark.main(spark.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
17/03/04 16:55:50 INFO SparkContext: Invoking stop() from shutdown hook
17/03/04 16:55:50 INFO SparkUI: Stopped Spark web UI at http://10.0.0.15:4040
17/03/04 16:55:50 INFO MapOutputTrackerMasterEndpoint: MapOutputTrackerMasterEndpoint stopped!
17/03/04 16:55:50 INFO MemoryStore: MemoryStore cleared
请让我知道我应该做些什么来灵活地运行我的代码?请建议我。
输入如下:
Mary let you win.
"Pleasant day to play football"
Don't worry go home now.
We ---- Will have conversation with you for sure. Relax.
还有很多其他的
暂无答案!
目前还没有任何答案,快来回答吧!