-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* logs all * logs all * write straight to buffered writer * write straight to buffered writer * tests * csvWriter * csvWriter * csvWriter * naming * fix write * fix csv writing * fix csv writing * fix csv writing * fix
- Loading branch information
Showing
10 changed files
with
356 additions
and
185 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
61 changes: 61 additions & 0 deletions
61
connector/src/main/scala/com/microsoft/kusto/spark/datasink/CountingCsvWriter.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,61 @@ | ||
package com.microsoft.kusto.spark.datasink | ||
|
||
import java.io.Writer | ||
|
||
case class CountingCsvWriter(out: Writer) { | ||
val newLineSep: String = java.security.AccessController.doPrivileged( | ||
new sun.security.action.GetPropertyAction("line.separator")) | ||
val newLineSepLength: Int = newLineSep.length | ||
var bytsCounter: Long = 0L | ||
|
||
def newLine(): Unit = { | ||
out.write(newLineSep) | ||
bytsCounter += newLineSepLength | ||
} | ||
|
||
def write(c: Char): Unit ={ | ||
out.write(c) | ||
bytsCounter += 1 | ||
} | ||
def write(str: String): Unit = { | ||
out.write(str) | ||
bytsCounter += str.length | ||
} | ||
|
||
def writeStringField(str: String, nested: Boolean) { | ||
if (str.length > 0) { | ||
|
||
out.write('"') | ||
if(nested){ | ||
out.write('"') | ||
bytsCounter += 2 | ||
} | ||
|
||
bytsCounter += 2 | ||
|
||
for (c <- str) { | ||
if (c == '"') { | ||
out.write("\"\"") | ||
bytsCounter += 1 | ||
} | ||
else { | ||
out.write(c) | ||
} | ||
} | ||
|
||
out.write('"') | ||
if(nested){ | ||
out.write('"') | ||
} | ||
|
||
bytsCounter += str.length | ||
} | ||
} | ||
|
||
def getCounter: Long = bytsCounter | ||
|
||
def resetCounter(): Unit = { | ||
bytsCounter = 0 | ||
} | ||
|
||
} |
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.