我有一个cassandraSQLContext,我这样做:
cassandraSqlContext.setKeyspace("test");
因为如果我不这样做,就会抱怨我设置默认密钥空间。
现在我运行这段代码:
def insertIntoCassandra(siteMetaData: MetaData, dataFrame: DataFrame): Unit ={
System.out.println(dataFrame.show())
val tableName = siteMetaData.getTableName.toLowerCase()
dataFrame.registerTempTable("spark_"+ tableName)
System.out.println("Registered the spark table to spark_" + tableName)
val columns = columnMap.get(siteMetaData.getTableName)
val query = cassandraQueryBuilder.buildInsertQuery("test", tableName, columns)
System.out.println("Query: " + query);
cassandraSqlContext.sql(query)
System.out.println("Query executed")
}
它给了我这个错误日志:
Registered the spark table to spark_test
Query: INSERT INTO TABLE test.tablename SELECT **the columns here** FROM spark_tablename
17/02/28 04:15:53 ERROR JobScheduler: Error running job streaming job 1488255351000 ms.0
java.util.concurrent.ExecutionException: java.io.IOException: Couldn't find test.tablename or any similarly named keyspace and table pairs
我不明白为什么cassandraSQLContext不执行打印出来的查询,为什么它会将键空间附加到火花temptable上。
public String buildInsertQuery(String activeReplicaKeySpace, String tableName, String columns){
String sql = "INSERT INTO TABLE " + activeReplicaKeySpace + "." + tableName +
" SELECT " + columns + " FROM spark_" + tableName;
return sql;
}
答案 0 :(得分:0)
所以问题是我使用了两个不同的cassandraSQLContext实例。在其中一个方法中,我实例化了一个新的cassandraSQLContext,它与传递给insertIntoCassandra方法的cassandraSQLContext冲突。