Skip to content

Commit

Permalink
Fix kotlin warnings (apache#10976)
Browse files Browse the repository at this point in the history
Fix kotlin warnings
Signed-off-by: harshit <[email protected]>
  • Loading branch information
harshithdwivedi authored Feb 26, 2020
1 parent cf3ca68 commit bb63260
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 698 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ object BigQueryTornadoes {
@ProcessElement
fun processElement(c: ProcessContext) {
val row = TableRow()
.set("month", c.element().getKey())
.set("tornado_count", c.element().getValue())
.set("month", c.element().key)
.set("tornado_count", c.element().value)
c.output(row)
}
}
Expand Down Expand Up @@ -157,16 +157,12 @@ object BigQueryTornadoes {
val rowsFromBigQuery: PCollection<TableRow>

if (options.readMethod == Method.DIRECT_READ) {
// Build the read options proto for the read operation.
val tableReadOptions = TableReadOptions.newBuilder()
.addAllSelectedFields(Lists.newArrayList("month", "tornado"))
.build()

rowsFromBigQuery = p.apply(
BigQueryIO.readTableRows()
.from(options.input)
.withMethod(Method.DIRECT_READ)
.withReadOptions(tableReadOptions))
.withSelectedFields(Lists.newArrayList("month", "tornado")))
} else {
rowsFromBigQuery = p.apply(
BigQueryIO.readTableRows()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ import org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO
import org.apache.beam.sdk.io.gcp.bigquery.WriteResult
import org.apache.beam.sdk.options.*
import org.apache.beam.sdk.transforms.*
import org.apache.beam.sdk.transforms.DoFn.ProcessElement
import org.apache.beam.sdk.values.PCollection
import org.apache.beam.sdk.values.PCollectionView

import java.util.ArrayList
import java.util.logging.Logger

/**
Expand Down Expand Up @@ -109,7 +105,7 @@ object FilterExamples {
* Examines each row in the input table. Outputs only rows from the month monthFilter, which is
* passed in as a parameter during construction of this DoFn.
*/
internal class FilterSingleMonthDataFn(var monthFilter: Int?) : DoFn<TableRow, TableRow>() {
internal class FilterSingleMonthDataFn(private var monthFilter: Int?) : DoFn<TableRow, TableRow>() {

@ProcessElement
fun processElement(c: ProcessContext) {
Expand Down Expand Up @@ -138,7 +134,7 @@ object FilterExamples {
* Finds the global mean of the mean_temp for each day/record, and outputs only data that has a
* mean temp larger than this global mean.
*/
internal class BelowGlobalMean(var monthFilter: Int?) : PTransform<PCollection<TableRow>, PCollection<TableRow>>() {
internal class BelowGlobalMean(private var monthFilter: Int?) : PTransform<PCollection<TableRow>, PCollection<TableRow>>() {

override fun expand(rows: PCollection<TableRow>): PCollection<TableRow> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("UNUSED_VARIABLE")

package org.apache.beam.examples.kotlin.snippets

import com.google.api.services.bigquery.model.*
Expand All @@ -37,8 +39,30 @@ import org.apache.beam.sdk.transforms.join.KeyedPCollectionTuple
import org.apache.beam.sdk.values.*

/** Code snippets used in webdocs. */
@Suppress("unused")
object Snippets {

val tableSchema: TableSchema by lazy {
TableSchema().setFields(
ImmutableList.of(
TableFieldSchema()
.setName("year")
.setType("INTEGER")
.setMode("REQUIRED"),
TableFieldSchema()
.setName("month")
.setType("INTEGER")
.setMode("REQUIRED"),
TableFieldSchema()
.setName("day")
.setType("INTEGER")
.setMode("REQUIRED"),
TableFieldSchema()
.setName("maxTemp")
.setType("FLOAT")
.setMode("NULLABLE")))
}

@DefaultCoder(AvroCoder::class)
internal class Quote(
val source: String = "",
Expand Down Expand Up @@ -259,25 +283,7 @@ object Snippets {
}

override fun getSchema(destination: Long?): TableSchema {
return TableSchema()
.setFields(
ImmutableList.of(
TableFieldSchema()
.setName("year")
.setType("INTEGER")
.setMode("REQUIRED"),
TableFieldSchema()
.setName("month")
.setType("INTEGER")
.setMode("REQUIRED"),
TableFieldSchema()
.setName("day")
.setType("INTEGER")
.setMode("REQUIRED"),
TableFieldSchema()
.setName("maxTemp")
.setType("FLOAT")
.setMode("NULLABLE")))
return tableSchema
}
})
.withFormatFunction {
Expand All @@ -296,20 +302,6 @@ object Snippets {
tableSpec = "$writeProject:$writeDataset.${writeTable}_partitioning"
}

val tableSchema = TableSchema()
.setFields(
ImmutableList.of(
TableFieldSchema().setName("year").setType("INTEGER").setMode("REQUIRED"),
TableFieldSchema()
.setName("month")
.setType("INTEGER")
.setMode("REQUIRED"),
TableFieldSchema().setName("day").setType("INTEGER").setMode("REQUIRED"),
TableFieldSchema()
.setName("maxTemp")
.setType("FLOAT")
.setMode("NULLABLE")))

// [START BigQueryTimePartitioning]
weatherData.apply<WriteResult>(
BigQueryIO.write<WeatherData>()
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit bb63260

Please sign in to comment.