aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/scala/parallelai/spyglass/jdbc/example/JdbcSourceExample.scala
blob: 0217204f95d3ea5adf8343b51d573f893889e88e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package parallelai.spyglass.jdbc.example

import com.twitter.scalding.{Tsv, Args}
import parallelai.spyglass.base.JobBase
import org.apache.log4j.{Level, Logger}
import parallelai.spyglass.jdbc.JDBCSource
import cascading.tuple.Fields

/**
 * Simple example of JDBCSource usage
 */
class JdbcSourceExample(args: Args) extends JobBase(args) {

  val isDebug: Boolean = args("debug").toBoolean

  if (isDebug) Logger.getRootLogger.setLevel(Level.DEBUG)

  val output = args("output")

  val hbs2 = new JDBCSource(
    "db_name",
    "com.mysql.jdbc.Driver",
    "jdbc:mysql://<hostname>:<port>/<db_name>?zeroDateTimeBehavior=convertToNull",
    "user",
    "password",
    List("KEY_ID", "COL1", "COL2", "COL3"),
    List("bigint(20)", "varchar(45)", "varchar(45)", "bigint(20)"),
    List("key_id"),
    new Fields("key_id", "col1", "col2", "col3")
  ).read
    .write(Tsv(output.format("get_list")))

}