Code Monkey home page Code Monkey logo

net.jgp.books.spark.ch02's Introduction

Purpose

pure scala version of https://github.com/jgperrin/net.jgp.books.spark.ch02

Environment

  • Java 11
  • Scala 2.13.8
  • Spark 3.2.1
  • Mysql 5.7.16 MySQL Community Server (GPL)
  • Download mysql driver, like mysql-connector-java-8.0.29.jar. Save at /replace-this-with-your-real-path

Database

CREATE DATABASE spark_labs character set utf8mb4;

How to run

1, sbt package, in project root dir

When success, there a jar file at ./target/scala-2.13. The name is main-scala-ch2_2.13-1.0.jar (the same as name property in sbt file)

2, submit jar file, in project root dir

$ YOUR_SPARK_HOME/bin/spark-submit \
  --class net.jgp.books.spark.ch02.lab100_csv_to_db.CsvToRelationalDatabaseApp \
  --jars /replace-this-with-your-real-path/mysql-connector-java-8.0.29.jar
  --master local[4] \
  target/scala-2.13/main-scala-ch2_2.13-1.0.jar

3, print

+--------+--------------+------------------------+
|lname   |fname         |name                    |
+--------+--------------+------------------------+
|Pascal  |Blaise        |Pascal, Blaise          |
|Voltaire|François      |Voltaire, François      |
|Perrin  |Jean-Georges  |Perrin, Jean-Georges    |
|Maréchal|Pierre Sylvain|Maréchal, Pierre Sylvain|
|Karau   |Holden        |Karau, Holden           |
+--------+--------------+------------------------+

4, One more thing

    // to use $"property" syntax, impoirt implicits
    import spark.implicits._
    val dfWithName = df.withColumn(
      "name",
      concat($"lname", lit(", "), $"fname")
    )

net.jgp.books.spark.ch02's People

Contributors

changzhiwin avatar

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.