-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first migration * temp fix in build.sbt * migrated pekko kafka * package folders adjusted for core module (main) * package folders adjusted for tests/test * package folders adjusted for tests/it * package folders adjusted for tests/main * package folders adjusted for testkit (main) * package folders adjusted for benchmarks (it) * package folders adjusted for benchmarks (main) * package folders adjusted for cluster-sharding (main) * package folders adjusted for testkit java classes * Some more akka import adjustments in scala classes * Some more akka import adjustments in java classes * - Finally, replaced akka word with org.apache.pekko everywhere in .scala files - Added temporary copy & paste class from alpakka (till migration completes) * Finally, replaced akka word with org.apache.pekko everywhere in .java files * adjusted logback as well * PR comments * SCM and contributor data adjusted * formatted files * fixed the documentation build * fixed pekko discovery check * Fixed another unit test * one more test fix * Renamed package names in logback * Fixed all unit tests (build should be green) * Renamed Alpakka... -> PekkoConnectors... * Renamed Alpakka... -> PekkoConnectors... * Removed unnecessary TODO * Removed dependency on lightbend stream-alpakka-csv * - Using package configuration mapping instead of default scaladoc.base_url configuration - Adjusted pekko extref links * All doc links in build.sbt are adjusted
- Loading branch information
1 parent
52b0a4e
commit a98a7bd
Showing
203 changed files
with
2,144 additions
and
1,961 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
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
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
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
126 changes: 126 additions & 0 deletions
126
benchmarks/src/main/scala/org/apache/pekko/kafka/benchmarks/CsvFormatter.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,126 @@ | ||
/* | ||
* Copyright (C) 2014 - 2016 Softwaremill <https://softwaremill.com> | ||
* Copyright (C) 2016 - 2020 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package org.apache.pekko.kafka.benchmarks | ||
|
||
import org.apache.pekko.util.ByteString | ||
|
||
import java.nio.charset.{ Charset, StandardCharsets } | ||
import scala.collection.immutable | ||
|
||
private[benchmarks] sealed trait CsvQuotingStyle | ||
|
||
object CsvQuotingStyle { | ||
|
||
/** Quote only fields requiring quotes */ | ||
case object Required extends CsvQuotingStyle | ||
|
||
/** Quote all fields */ | ||
case object Always extends CsvQuotingStyle | ||
} | ||
|
||
// TODO: This needs to be deleted after migrating alpakka to pekko. | ||
// This is just temporary base to see everything compiles and tests will pass without any issue | ||
private[benchmarks] class CsvFormatter(delimiter: Char, | ||
quoteChar: Char, | ||
escapeChar: Char, | ||
endOfLine: String, | ||
quotingStyle: CsvQuotingStyle, | ||
charset: Charset = StandardCharsets.UTF_8) { | ||
|
||
private[this] val charsetName = charset.name() | ||
|
||
private[this] val delimiterBs = ByteString(String.valueOf(delimiter), charsetName) | ||
private[this] val quoteBs = ByteString(String.valueOf(quoteChar), charsetName) | ||
private[this] val duplicatedQuote = ByteString(String.valueOf(Array(quoteChar, quoteChar)), charsetName) | ||
private[this] val duplicatedEscape = ByteString(String.valueOf(Array(escapeChar, escapeChar)), charsetName) | ||
private[this] val endOfLineBs = ByteString(endOfLine, charsetName) | ||
|
||
def toCsv(fields: immutable.Iterable[Any]): ByteString = | ||
if (fields.nonEmpty) nonEmptyToCsv(fields) | ||
else endOfLineBs | ||
|
||
private def nonEmptyToCsv(fields: immutable.Iterable[Any]) = { | ||
val builder = ByteString.createBuilder | ||
|
||
def splitAndDuplicateQuotesAndEscapes(field: String, splitAt: Int) = { | ||
|
||
@inline def indexOfQuoteOrEscape(lastIndex: Int) = { | ||
var index = lastIndex | ||
var found = -1 | ||
while (index < field.length && found == -1) { | ||
val char = field(index) | ||
if (char == quoteChar || char == escapeChar) found = index | ||
index += 1 | ||
} | ||
found | ||
} | ||
|
||
var lastIndex = 0 | ||
var index = splitAt | ||
while (index > -1) { | ||
builder ++= ByteString.apply(field.substring(lastIndex, index), charsetName) | ||
val char = field.charAt(index) | ||
if (char == quoteChar) { | ||
builder ++= duplicatedQuote | ||
} else { | ||
builder ++= duplicatedEscape | ||
} | ||
lastIndex = index + 1 | ||
index = indexOfQuoteOrEscape(lastIndex) | ||
} | ||
if (lastIndex < field.length) { | ||
builder ++= ByteString(field.substring(lastIndex), charsetName) | ||
} | ||
} | ||
|
||
def append(field: String) = { | ||
val (quoteIt, splitAt) = requiresQuotesOrSplit(field) | ||
if (quoteIt || quotingStyle == CsvQuotingStyle.Always) { | ||
builder ++= quoteBs | ||
if (splitAt != -1) { | ||
splitAndDuplicateQuotesAndEscapes(field, splitAt) | ||
} else { | ||
builder ++= ByteString(field, charsetName) | ||
} | ||
builder ++= quoteBs | ||
} else { | ||
builder ++= ByteString(field, charsetName) | ||
} | ||
} | ||
|
||
val iterator = fields.iterator | ||
var hasNext = iterator.hasNext | ||
while (hasNext) { | ||
val next = iterator.next() | ||
if (next != null) { | ||
append(next.toString) | ||
} | ||
hasNext = iterator.hasNext | ||
if (hasNext) { | ||
builder ++= delimiterBs | ||
} | ||
} | ||
builder ++= endOfLineBs | ||
builder.result() | ||
} | ||
|
||
private def requiresQuotesOrSplit(field: String): (Boolean, Int) = { | ||
var quotes = CsvQuotingStyle.Always == quotingStyle | ||
var split = -1 | ||
var index = 0 | ||
while (index < field.length && !(quotes && split != -1)) { | ||
val char = field(index) | ||
if (char == `quoteChar` || char == `escapeChar`) { | ||
quotes = true | ||
split = index | ||
} else if (char == '\r' || char == '\n' || char == `delimiter`) { | ||
quotes = true | ||
} | ||
index += 1 | ||
} | ||
(quotes, split) | ||
} | ||
} |
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.