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

refactor(handler): use FieldEncoder to encode data. #8733

Merged
merged 6 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions src/query/datavalues/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,3 @@ harness = false
[[bench]]
name = "data_type"
harness = false

[[bench]]
name = "output_format"
harness = false
119 changes: 0 additions & 119 deletions src/query/datavalues/benches/output_format.rs

This file was deleted.

64 changes: 0 additions & 64 deletions src/query/datavalues/src/types/serializations/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ use common_io::prelude::FormatSettings;
use serde_json::Value;

use crate::prelude::*;
use crate::serializations::write_csv_string;
use crate::serializations::write_json_string;

#[derive(Clone)]
pub struct ArraySerializer<'a> {
Expand All @@ -38,68 +36,6 @@ impl<'a> ArraySerializer<'a> {
}

impl<'a> TypeSerializer<'a> for ArraySerializer<'a> {
fn write_field_values(
&self,
row_index: usize,
buf: &mut Vec<u8>,
format: &FormatSettings,
_in_nested: bool,
) {
let start = self.offsets[row_index] as usize;
let end = self.offsets[row_index + 1] as usize;
buf.push(b'[');
let inner = &self.inner;
for i in start..end {
if i != start {
buf.extend_from_slice(b", ");
}
inner.write_field_values(i, buf, format, true);
}
buf.push(b']');
}

fn write_field_tsv(
&self,
row_index: usize,
buf: &mut Vec<u8>,
format: &FormatSettings,
_in_nested: bool,
) {
let start = self.offsets[row_index] as usize;
let end = self.offsets[row_index + 1] as usize;
buf.push(b'[');
let inner = &self.inner;
for i in start..end {
if i != start {
buf.extend_from_slice(b", ");
}
inner.write_field_tsv(i, buf, format, true);
}
buf.push(b']');
}

fn write_field_csv(&self, row_index: usize, buf: &mut Vec<u8>, format: &FormatSettings) {
let v = self.to_vec_values(row_index, format);
write_csv_string(&v, buf, format.quote_char);
}

fn write_field_json(
&self,
row_index: usize,
buf: &mut Vec<u8>,
format: &FormatSettings,
quote: bool,
) {
let v = self.to_vec_values(row_index, format);
if quote {
buf.push(b'\"');
}
write_json_string(&v, buf, format);
if quote {
buf.push(b'\"');
}
}

fn serialize_json_values(&self, format: &FormatSettings) -> Result<Vec<Value>> {
let size = self.offsets.len() - 1;
let mut result = Vec::with_capacity(size);
Expand Down
49 changes: 0 additions & 49 deletions src/query/datavalues/src/types/serializations/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,58 +30,9 @@ impl BooleanSerializer {
let values = col.values().clone();
Ok(Self { values })
}

#[inline]
fn write_field_outer(&self, row_index: usize, buf: &mut Vec<u8>, format: &FormatSettings) {
let v = if self.values.get_bit(row_index) {
&format.true_bytes
} else {
&format.false_bytes
};
buf.extend_from_slice(v);
}
}

impl<'a> TypeSerializer<'a> for BooleanSerializer {
fn write_field_values(
&self,
row_index: usize,
buf: &mut Vec<u8>,
format: &FormatSettings,
_in_nested: bool,
) {
let v = if self.values.get_bit(row_index) {
&format.nested.true_bytes
} else {
&format.nested.false_bytes
};
buf.extend_from_slice(v);
}

fn write_field_tsv(
&self,
row_index: usize,
buf: &mut Vec<u8>,
format: &FormatSettings,
_in_nested: bool,
) {
self.write_field_outer(row_index, buf, format)
}

fn write_field_csv(&self, row_index: usize, buf: &mut Vec<u8>, format: &FormatSettings) {
self.write_field_outer(row_index, buf, format)
}

fn write_field_json(
&self,
row_index: usize,
buf: &mut Vec<u8>,
format: &FormatSettings,
_quote: bool,
) {
self.write_field_outer(row_index, buf, format)
}

fn serialize_json_values(&self, _format: &FormatSettings) -> Result<Vec<Value>> {
let result: Vec<Value> = self
.values
Expand Down
34 changes: 0 additions & 34 deletions src/query/datavalues/src/types/serializations/const_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,6 @@ impl<'a> ConstSerializer<'a> {
}
}
impl<'a> TypeSerializer<'a> for ConstSerializer<'a> {
fn write_field_values(
&self,
_row_index: usize,
buf: &mut Vec<u8>,
format: &FormatSettings,
in_nested: bool,
) {
self.inner.write_field_values(0, buf, format, in_nested)
}

fn write_field_tsv(
&self,
_row_index: usize,
buf: &mut Vec<u8>,
format: &FormatSettings,
in_nested: bool,
) {
self.inner.write_field_tsv(0, buf, format, in_nested)
}

fn write_field_csv(&self, _row_index: usize, buf: &mut Vec<u8>, format: &FormatSettings) {
self.inner.write_field_csv(0, buf, format)
}

fn write_field_json(
&self,
_row_index: usize,
buf: &mut Vec<u8>,
format: &FormatSettings,
quote: bool,
) {
self.inner.write_field_json(0, buf, format, quote)
}

fn serialize_json_values(&self, format: &FormatSettings) -> Result<Vec<Value>> {
Ok(self.repeat(self.inner.serialize_json_values(format)?))
}
Expand Down
59 changes: 0 additions & 59 deletions src/query/datavalues/src/types/serializations/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ use lexical_core::ToLexical;
use num::cast::AsPrimitive;
use serde_json::Value;

use crate::serializations::write_csv_string;
use crate::serializations::write_escaped_string;
use crate::serializations::write_json_string;
use crate::serializations::TypeSerializer;
use crate::ColumnRef;
use crate::PrimitiveColumn;
Expand Down Expand Up @@ -61,62 +58,6 @@ impl<'a, T: PrimitiveType + AsPrimitive<i64> + ToLexical> DateSerializer<'a, T>
impl<'a, T: PrimitiveType + AsPrimitive<i64> + ToLexical> TypeSerializer<'a>
for DateSerializer<'a, T>
{
fn write_field_values(
&self,
row_index: usize,
buf: &mut Vec<u8>,
format: &FormatSettings,
in_nested: bool,
) {
let s = self.fmt(row_index);
if in_nested {
buf.push(format.nested.quote_char);
}
write_escaped_string(s.as_bytes(), buf, format.nested.quote_char);
if in_nested {
buf.push(format.nested.quote_char);
}
}

fn write_field_tsv(
&self,
row_index: usize,
buf: &mut Vec<u8>,
format: &FormatSettings,
in_nested: bool,
) {
if in_nested {
buf.push(format.quote_char);
}
let s = self.fmt(row_index);
write_escaped_string(s.as_bytes(), buf, format.quote_char);
if in_nested {
buf.push(format.quote_char);
}
}

fn write_field_csv(&self, row_index: usize, buf: &mut Vec<u8>, format: &FormatSettings) {
let s = self.fmt(row_index);
write_csv_string(s.as_bytes(), buf, format.quote_char);
}

fn write_field_json(
&self,
row_index: usize,
buf: &mut Vec<u8>,
format: &FormatSettings,
quote: bool,
) {
let s = self.fmt(row_index);
if quote {
buf.push(b'\"');
}
write_json_string(s.as_bytes(), buf, format);
if quote {
buf.push(b'\"');
}
}

fn serialize_json_values(&self, _format: &FormatSettings) -> Result<Vec<Value>> {
let result: Vec<Value> = (0..self.values.len())
.map(|row_index| {
Expand Down
Loading