我想从hdfs获取文件并保存到cassandra
public static class PrincipalExtensions
{
private static void Initialize(string userName)
{
var userRecord = //Get user information from DB;
var session = HttpContext.Current.Session;
if (session != null)
{
session.Add("UserID", userRecord.ID);
session.Add("UserEmail", userRecord.Email);
//And so on
}
}
public static long? GetUserID(this IPrincipal user)
{
var id = HttpContext.Current.Session["UserID"] as long?;
if (id == null)
Initialize();
return (long)HttpContext.Current.Session["UserID"];
}
}
但由于例外情况,我无法将其写入cassandra
我得到文件,因为files.foreach(x => println(x))有效
答案 0 :(得分:0)
据我所知,您可以进行以下更改
var wc1 = files.map(_.split("\\|")).map(r=>Row(r(0),r(1),r(2)))
implicit val rowWriter = SqlRowWriter.Factory
wc1.saveToCassandra("ks", "tb", SomeColumns("id", "time", "text"))
希望它有效!!! ...
答案 1 :(得分:0)
class randomString4File {
val x = util.Random
def create(size: Int) = {
var str = ""
while(str.length() < size) {
if (str.length() != 0) {
str += "\n" + x.nextInt().abs.toString() + " " + java.time.LocalDateTime.now() + " " + x.alphanumeric.take(20).mkString
}
else str += x.nextInt().abs.toString() + " " + java.time.LocalDateTime.now() + " " + x.alphanumeric.take(20).mkString + "\n"
}
str
}
}
我这样写文件