Skip to content

Commit

Permalink
remove getFloat and getInt in RichTableRow #162
Browse files Browse the repository at this point in the history
  • Loading branch information
nevillelyh committed Jun 7, 2016
1 parent a0e6cc2 commit 78ade7a
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,8 @@ package object bigquery {

def getBoolean(name: AnyRef): Boolean = this.getValue(name, _.toString.toBoolean, false)

def getInt(name: AnyRef): Int = this.getValue(name, _.toString.toInt, 0)

def getLong(name: AnyRef): Long = this.getValue(name, _.toString.toLong, 0L)

def getFloat(name: AnyRef): Float = this.getValue(name, _.toString.toFloat, 0.0f)

def getDouble(name: AnyRef): Double = this.getValue(name, _.toString.toDouble, 0.0)

def getString(name: AnyRef): String = this.getValue(name, _.toString, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object TopWikipediaSessions {
sc
.tableRowJsonFile(args.getOrElse("input", ExampleData.EXPORTED_WIKI_TABLE))
.flatMap { row =>
try Seq((row.getString("contributor_username"), row.getInt("timestamp"))) catch {
try Seq((row.getString("contributor_username"), row.getLong("timestamp"))) catch {
case e: NullPointerException => None
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object BigQueryTornadoes {

sc
.bigQueryTable(args.getOrElse("input", ExampleData.WEATHER_SAMPLES_TABLE))
.flatMap(r => if (r.getBoolean("tornado")) Seq(r.getInt("month")) else Nil)
.flatMap(r => if (r.getBoolean("tornado")) Seq(r.getLong("month")) else Nil)
.countByValue
.map(kv => TableRow("month" -> kv._1, "tornado_count" -> kv._2))
.saveAsBigQuery(args("output"), schema, WRITE_TRUNCATE, CREATE_IF_NEEDED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.spotify.scio.examples.common.ExampleData

import scala.collection.JavaConverters._

case class Record(year: Int, month: Int, day: Int, meanTemp: Double)
case class Record(year: Long, month: Long, day: Long, meanTemp: Double)

/*
SBT
Expand All @@ -50,9 +50,9 @@ object FilterExamples {

val pipe = sc.bigQueryTable(args.getOrElse("input", ExampleData.WEATHER_SAMPLES_TABLE))
.map { row =>
val year = row.getInt("year")
val month = row.getInt("month")
val day = row.getInt("day")
val year = row.getLong("year")
val month = row.getLong("month")
val day = row.getLong("day")
val meanTemp = row.getDouble("mean_temp")
Record(year, month, day, meanTemp)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object MaxPerKeyExamples {

sc
.bigQueryTable(args.getOrElse("input", ExampleData.WEATHER_SAMPLES_TABLE))
.map(row => (row.getInt("month"), row.getDouble("mean_temp")))
.map(row => (row.getLong("month"), row.getDouble("mean_temp")))
.maxByKey
.map(kv => TableRow("month" -> kv._1, "max_mean_temp" -> kv._2))
.saveAsBigQuery(args("output"), schema, WRITE_TRUNCATE, CREATE_IF_NEEDED)
Expand Down

0 comments on commit 78ade7a

Please sign in to comment.