zoukankan      html  css  js  c++  java
  • Spark-Cassandra-Connector 插入数据函数saveToCassandra

    在spark-shell中将数据保存到cassandra:

    var data = normalfill.map(line => line.split("u0005"))
    
    data.map(
     line => (line(0), line(1), line(2))) 
    ).saveToCassandra(
     "cui", 
     "oper_ios",
     SomeColumns("user_no", "cust_id", "oper_code","oper_time")
    )

     saveToCassandra方法 当字段类型是counter的时候,默认行为是计数 

    CREATE TABLE cui.incr(
     name text,
     count counter,
     PRIMARY KEY (name)
    )

    scala> var rdd = sc.parallelize(Array(("cui", 100 )))
    rdd: org.apache.spark.rdd.RDD[(String, Int)] = ParallelCollectionRDD[820] at parallelize at <console>:42

    scala>  rdd.saveToCassandra("cui","incr", SomeColumns("name","count"))
    16/01/21 16:55:35 INFO core.Cluster: New Cassandra host /172.25.1.158:9042 added
    ……

    // name     count

    // cui          100

    scala> var rdd = sc.parallelize(Array(("cui", 100 )))
    rdd: org.apache.spark.rdd.RDD[(String, Int)] = ParallelCollectionRDD[821] at parallelize at <console>:42

    scala>  rdd.saveToCassandra("cui","incr", SomeColumns("name","count"))

    // name     count

    // cui          200

  • 相关阅读:
    PHP生成pdf文档
    PHP将数据库数据批量生成word文档
    三个常用的PHP图表类库
    Javascript——(1)
    python学习HTML之CSS(2)
    python学习HTML之CSS
    python学习之HTML
    python学习之rabbitmq
    第10周15/16/17
    多进程
  • 原文地址:https://www.cnblogs.com/tugeler/p/5148909.html
Copyright © 2011-2022 走看看