refactor json block.
@@ -26,21 +26,16 @@ use serde_json::Value as JsonValue;
#[derive(Debug, Clone)]
pub struct JsonBlock {
- data: Vec<Vec<JsonValue>>,
- schema: DataSchemaRef,
+ pub(crate) data: Vec<Vec<JsonValue>>,
+ pub(crate) schema: DataSchemaRef,
}
pub type JsonBlockRef = Arc<JsonBlock>;
-impl JsonBlock {
- pub fn empty() -> Self {
- Self {
- data: vec![],
- schema: Arc::new(DataSchema::empty()),
- }
- }
-
- pub fn new(block: &DataBlock, format: &FormatSettings) -> Result<Self> {
+pub fn block_to_json_value_columns(
+ block: &DataBlock,
+ format: &FormatSettings,
+) -> Result<Vec<Vec<JsonValue>>> {
let mut col_table = Vec::new();
let columns_size = block.columns().len();
for col_index in 0..columns_size {
@@ -57,9 +52,28 @@ impl JsonBlock {
))
})?);
}
+ Ok(col_table)
+}
+pub fn block_to_json_value(
+ block: &DataBlock,
+ format: &FormatSettings,
+) -> Result<Vec<Vec<JsonValue>>> {
+ let cols = block_to_json_value_columns(block, format)?;
+ Ok(transpose(cols))
+}
+
+impl JsonBlock {
+ pub fn empty() -> Self {
+ Self {
+ data: vec![],
+ schema: Arc::new(DataSchema::empty()),
+ }
+ }
+
+ pub fn new(block: &DataBlock, format: &FormatSettings) -> Result<Self> {
Ok(JsonBlock {
- data: transpose(col_table),
+ data: block_to_json_value(block, format)?,
schema: block.schema().clone(),
})
}
