-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RD-15131: CRUD support in SqlCompilerService (#537)
- Loading branch information
Showing
6 changed files
with
325 additions
and
27 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
57 changes: 57 additions & 0 deletions
57
sql-compiler/src/main/scala/com/rawlabs/sql/compiler/writers/StatusCsvWriter.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,57 @@ | ||
/* | ||
* Copyright 2023 RAW Labs S.A. | ||
* | ||
* Use of this software is governed by the Business Source License | ||
* included in the file licenses/BSL.txt. | ||
* | ||
* As of the Change Date specified in that file, in accordance with | ||
* the Business Source License, use of this software will be governed | ||
* by the Apache License, Version 2.0, included in the file | ||
* licenses/APL.txt. | ||
*/ | ||
|
||
package com.rawlabs.sql.compiler.writers | ||
|
||
import com.fasterxml.jackson.core.{JsonEncoding, JsonParser} | ||
import com.fasterxml.jackson.dataformat.csv.CsvGenerator.Feature.STRICT_CHECK_FOR_QUOTING | ||
import com.fasterxml.jackson.dataformat.csv.{CsvFactory, CsvSchema} | ||
|
||
import java.io.{Closeable, IOException, OutputStream} | ||
|
||
class StatusCsvWriter(os: OutputStream, lineSeparator: String) extends Closeable { | ||
|
||
final private val gen = | ||
try { | ||
val factory = new CsvFactory | ||
factory.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE) // Don't close file descriptors automatically | ||
factory.createGenerator(os, JsonEncoding.UTF8) | ||
} catch { | ||
case e: IOException => throw new RuntimeException(e) | ||
} | ||
|
||
private val schemaBuilder = CsvSchema.builder() | ||
schemaBuilder.setColumnSeparator(',') | ||
schemaBuilder.setUseHeader(true) | ||
schemaBuilder.setLineSeparator(lineSeparator) | ||
schemaBuilder.setQuoteChar('"') | ||
schemaBuilder.setNullValue("") | ||
schemaBuilder.addColumn("update_count") | ||
gen.setSchema(schemaBuilder.build) | ||
gen.enable(STRICT_CHECK_FOR_QUOTING) | ||
|
||
@throws[IOException] | ||
def write(count: Int): Unit = { | ||
gen.writeStartObject() | ||
gen.writeFieldName("update_count") | ||
gen.writeNumber(count) | ||
gen.writeEndObject() | ||
} | ||
|
||
def flush(): Unit = { | ||
gen.flush() | ||
} | ||
|
||
override def close(): Unit = { | ||
gen.close() | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
sql-compiler/src/main/scala/com/rawlabs/sql/compiler/writers/StatusJsonWriter.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,43 @@ | ||
/* | ||
* Copyright 2024 RAW Labs S.A. | ||
* | ||
* Use of this software is governed by the Business Source License | ||
* included in the file licenses/BSL.txt. | ||
* | ||
* As of the Change Date specified in that file, in accordance with | ||
* the Business Source License, use of this software will be governed | ||
* by the Apache License, Version 2.0, included in the file | ||
* licenses/APL.txt. | ||
*/ | ||
|
||
package com.rawlabs.sql.compiler.writers | ||
|
||
import com.fasterxml.jackson.core.{JsonEncoding, JsonFactory, JsonParser} | ||
|
||
import java.io.{IOException, OutputStream} | ||
|
||
class StatusJsonWriter(os: OutputStream) { | ||
|
||
final private val gen = | ||
try { | ||
val factory = new JsonFactory | ||
factory.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE) // Don't close file descriptors automatically | ||
factory.createGenerator(os, JsonEncoding.UTF8) | ||
} catch { | ||
case e: IOException => throw new RuntimeException(e) | ||
} | ||
|
||
@throws[IOException] | ||
def write(count: Int): Unit = { | ||
gen.writeStartArray() | ||
gen.writeStartObject() | ||
gen.writeFieldName("update_count") | ||
gen.writeNumber(count) | ||
gen.writeEndObject() | ||
gen.writeEndArray() | ||
} | ||
|
||
def close(): Unit = { | ||
gen.close() | ||
} | ||
} |
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.