-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
141 additions
and
454 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...lytics/snowplow/rdbloader/transformer/stream/kafka/experimental/OutputDataRowReader.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.snowplowanalytics.snowplow.rdbloader.transformer.stream.kafka.experimental | ||
import cats.effect.IO | ||
import com.snowplowanalytics.snowplow.rdbloader.transformer.stream.common.ParquetUtils | ||
import com.snowplowanalytics.snowplow.rdbloader.transformer.stream.kafka.experimental.TransformerSpecification.{Blob, DataRow} | ||
import fs2.io.file.{Files, Path} | ||
import io.circe.parser | ||
|
||
import java.nio.charset.StandardCharsets | ||
|
||
object OutputDataRowReader { | ||
|
||
def fromJson(blob: Blob): IO[List[DataRow]] = | ||
fs2.Stream | ||
.emits[IO, Byte](blob) | ||
.through(fs2.text.decodeWithCharset(StandardCharsets.UTF_8)) | ||
.through(fs2.text.lines) | ||
.map(parser.parse(_).right.get) | ||
.compile | ||
.toList | ||
|
||
// For parquet we fetch all bytes from remote blob storage and store them in the temporary local output. | ||
// Then we use hadoop API (details in the `ParquetUtils`) to decode it and convert to human-readable JSON format. | ||
def fromParquet(blob: Blob): IO[List[DataRow]] = | ||
Files[IO].tempFile | ||
.use { tempOutput => | ||
for { | ||
_ <- saveParquetDataToTemporaryOutput(tempOutput, blob) | ||
outputParquetColumns = ParquetUtils.readFileColumns(tempOutput.toNioPath.toFile) | ||
parquetRows <- ParquetUtils.readParquetRowsAsJsonFrom(tempOutput, outputParquetColumns) | ||
} yield parquetRows | ||
} | ||
|
||
private def saveParquetDataToTemporaryOutput(outputPath: Path, blob: Blob): IO[Unit] = | ||
fs2.Stream | ||
.emits(blob) | ||
.through(Files[IO].writeAll(outputPath)) | ||
.compile | ||
.drain | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.