Giter Club home page Giter Club logo

spark_mysql's Introduction

spark_mysql

SparkSQL DataFrame与MySQL增加,删除,修改和查询那些事儿

1.Create(增加)
  case class CardMemberm_idStringcard_typeStringexpireTimestampdurationIntis_saleBooleandateDateuser:long,salaryFloatval memberSeq = SeqCardMember(“member_2”,“月卡”,新时间戳(System.currentTimeMillis()),31false,新日期(System.currentTimeMillis()),123223,0.32f),
      CardMember(“member_1” “,”季卡“,新的时间戳(System.currentTimeMillis()),93falsenew DateSystem.currentTimeMillis()),124224,0.362f)
    )
    val memberDF = memberSeq.toDF()
    //把DataFrame存入到MySQL的中,如果数据库中不存在此表的话就会自动创建
    MySQLUtils.saveDFtoDBCreateTableIfNotExist( “member_test”,memberDF
2.Retrieve(读取查询)
     //根据表名把MySQL中的数据表直接映射成DataFrame 
    MySQLUtils.getDFFromMysqlhiveContext,“member_test”,null
3.Update(更新)
    //根据主键更新指定字段,如果没有此主键数据则直接插入
    MySQLUtils.insertOrUpdateDFtoDBUsePool(“member_test”,memberDFArray(“user”,“salary”))
4.Delete(删除)
 //删除指定条件的数据
 MySQLUtils.deleteMysqlTablehiveContext,“member_test”,“m_id ='member_1'”); 
 //删除指定数据表
 MySQLUtils.dropMysqlTablehiveContext, “member_test”); 

spark_mysql's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.