Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Simplify deserializeStream #173

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class NodeClient(val nodeSpec: NodeSpec) extends AutoCloseable with Logging {
sql: String,
outputFormat: String,
outputCompressionType: ClickHouseCompression,
outputStreamDeserializer: Iterator[InputStream] => StreamOutput[OUT],
outputStreamDeserializer: InputStream => StreamOutput[OUT],
settings: Map[String, String]
): StreamOutput[OUT] = {
val queryId = nextQueryId()
Expand All @@ -184,7 +184,7 @@ class NodeClient(val nodeSpec: NodeSpec) extends AutoCloseable with Logging {
.format(ClickHouseFormat.valueOf(outputFormat)).asInstanceOf[ClickHouseRequest[_]]
settings.foreach { case (k, v) => req.set(k, v).asInstanceOf[ClickHouseRequest[_]] }
Try(req.executeAndWait()) match {
case Success(resp) => outputStreamDeserializer(Seq(resp.getInputStream).iterator)
case Success(resp) => outputStreamDeserializer(resp.getInputStream)
case Failure(ex: ClickHouseException) => throw CHServerException(ex.getErrorCode, ex.getMessage, Some(nodeSpec))
case Failure(ex) => throw CHClientException(ex.getMessage, Some(nodeSpec))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import xenon.clickhouse.exception.CHClientException
object JSONEachRowSimpleOutput {
def deserialize(input: InputStream): SimpleOutput[ObjectNode] = {
val records = om.readerFor[ObjectNode]
.readValues(input)
.readValues[ObjectNode](input)
.asScala.toSeq
new JSONEachRowSimpleOutput(records)
}
Expand Down Expand Up @@ -73,11 +73,9 @@ class JSONCompactEachRowWithNamesAndTypesSimpleOutput(
///////////////////////////////////////////////////////////////////////////////

object JSONCompactEachRowWithNamesAndTypesStreamOutput {
def deserializeStream(inputIterator: Iterator[InputStream]): StreamOutput[Array[JsonNode]] = {
val stream = inputIterator.flatMap { output =>
val jsonParser = om.getFactory.createParser(output)
om.readValues[Array[JsonNode]](jsonParser).asScala
}
def deserializeStream(input: InputStream): StreamOutput[Array[JsonNode]] = {
val jsonParser = om.getFactory.createParser(input)
val stream = om.readValues[Array[JsonNode]](jsonParser).asScala
new JSONCompactEachRowWithNamesAndTypesStreamOutput(stream)
}
}
Expand Down