Skip to content

Commit

Permalink
query format with tz
Browse files Browse the repository at this point in the history
Signed-off-by: Veeupup <code@tanweime.com>
  • Loading branch information
Veeupup committed May 2, 2022
1 parent a197c5d commit db78d7a
Show file tree
Hide file tree
Showing 28 changed files with 144 additions and 114 deletions.
14 changes: 7 additions & 7 deletions common/datavalues/src/types/serializations/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::sync::Arc;


use common_exception::ErrorCode;
use common_exception::Result;
Expand All @@ -28,7 +28,7 @@ pub struct ArraySerializer {
}

impl TypeSerializer for ArraySerializer {
fn serialize_value(&self, value: &DataValue, format: Arc<FormatSettings>) -> Result<String> {
fn serialize_value(&self, value: &DataValue, format: &FormatSettings) -> Result<String> {
if let DataValue::Array(vals) = value {
let mut res = String::new();
res.push('[');
Expand All @@ -40,7 +40,7 @@ impl TypeSerializer for ArraySerializer {
}
first = false;

let s = self.inner.serialize_value(val, format.clone())?;
let s = self.inner.serialize_value(val, format)?;
if quoted {
res.push_str(&format!("'{}'", s));
} else {
Expand All @@ -57,13 +57,13 @@ impl TypeSerializer for ArraySerializer {
fn serialize_column(
&self,
column: &ColumnRef,
format: Arc<FormatSettings>,
format: &FormatSettings,
) -> Result<Vec<String>> {
let column: &ArrayColumn = Series::check_get(column)?;
let mut result = Vec::with_capacity(column.len());
for i in 0..column.len() {
let val = column.get(i);
let s = self.serialize_value(&val, format.clone())?;
let s = self.serialize_value(&val, format)?;
result.push(s);
}
Ok(result)
Expand All @@ -72,15 +72,15 @@ impl TypeSerializer for ArraySerializer {
fn serialize_json(
&self,
_column: &ColumnRef,
_format: Arc<FormatSettings>,
_format: &FormatSettings,
) -> Result<Vec<Value>> {
todo!()
}

fn serialize_clickhouse_format(
&self,
_column: &ColumnRef,
_format: Arc<FormatSettings>,
_format: &FormatSettings,
) -> Result<opensrv_clickhouse::types::column::ArcColumnData> {
todo!()
}
Expand Down
14 changes: 7 additions & 7 deletions common/datavalues/src/types/serializations/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::sync::Arc;


use common_arrow::arrow::bitmap::Bitmap;
use common_exception::ErrorCode;
Expand All @@ -31,7 +31,7 @@ const TRUE_STR: &str = "1";
const FALSE_STR: &str = "0";

impl TypeSerializer for BooleanSerializer {
fn serialize_value(&self, value: &DataValue, _format: Arc<FormatSettings>) -> Result<String> {
fn serialize_value(&self, value: &DataValue, _format: &FormatSettings) -> Result<String> {
if let DataValue::Boolean(x) = value {
if *x {
Ok(TRUE_STR.to_owned())
Expand All @@ -46,7 +46,7 @@ impl TypeSerializer for BooleanSerializer {
fn serialize_column(
&self,
column: &ColumnRef,
_format: Arc<FormatSettings>,
_format: &FormatSettings,
) -> Result<Vec<String>> {
let array: &BooleanColumn = Series::check_get(column)?;

Expand All @@ -66,7 +66,7 @@ impl TypeSerializer for BooleanSerializer {
fn serialize_json(
&self,
column: &ColumnRef,
_format: Arc<FormatSettings>,
_format: &FormatSettings,
) -> Result<Vec<Value>> {
let array: &BooleanColumn = Series::check_get(column)?;
let result: Vec<Value> = array
Expand All @@ -79,7 +79,7 @@ impl TypeSerializer for BooleanSerializer {
fn serialize_clickhouse_format(
&self,
column: &ColumnRef,
_format: Arc<FormatSettings>,
_format: &FormatSettings,
) -> Result<opensrv_clickhouse::types::column::ArcColumnData> {
let col: &BooleanColumn = Series::check_get(column)?;
let values: Vec<u8> = col.iter().map(|c| c as u8).collect();
Expand All @@ -90,15 +90,15 @@ impl TypeSerializer for BooleanSerializer {
&self,
column: &ColumnRef,
_valids: Option<&Bitmap>,
format: Arc<FormatSettings>,
format: &FormatSettings,
) -> Result<Vec<Value>> {
self.serialize_json(column, format)
}

fn serialize_json_object_suppress_error(
&self,
column: &ColumnRef,
_format: Arc<FormatSettings>,
_format: &FormatSettings,
) -> Result<Vec<Option<Value>>> {
let column: &BooleanColumn = Series::check_get(column)?;
let result: Vec<Option<Value>> = column
Expand Down
10 changes: 5 additions & 5 deletions common/datavalues/src/types/serializations/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
use std::marker::PhantomData;
use std::ops::AddAssign;
use std::sync::Arc;


use chrono::Date;
use chrono::Duration;
Expand Down Expand Up @@ -44,7 +44,7 @@ impl<T: PrimitiveType + AsPrimitive<i64>> Default for DateSerializer<T> {
const DATE_FMT: &str = "%Y-%m-%d";

impl<T: PrimitiveType + AsPrimitive<i64>> TypeSerializer for DateSerializer<T> {
fn serialize_value(&self, value: &DataValue, _format: Arc<FormatSettings>) -> Result<String> {
fn serialize_value(&self, value: &DataValue, _format: &FormatSettings) -> Result<String> {
let mut date = NaiveDate::from_ymd(1970, 1, 1);
let d = Duration::days(value.as_i64()?);
date.add_assign(d);
Expand All @@ -54,7 +54,7 @@ impl<T: PrimitiveType + AsPrimitive<i64>> TypeSerializer for DateSerializer<T> {
fn serialize_column(
&self,
column: &ColumnRef,
_format: Arc<FormatSettings>,
_format: &FormatSettings,
) -> Result<Vec<String>> {
let column: &PrimitiveColumn<T> = Series::check_get(column)?;

Expand All @@ -73,7 +73,7 @@ impl<T: PrimitiveType + AsPrimitive<i64>> TypeSerializer for DateSerializer<T> {
fn serialize_json(
&self,
column: &ColumnRef,
_format: Arc<FormatSettings>,
_format: &FormatSettings,
) -> Result<Vec<Value>> {
let array: &PrimitiveColumn<T> = Series::check_get(column)?;
let result: Vec<Value> = array
Expand All @@ -92,7 +92,7 @@ impl<T: PrimitiveType + AsPrimitive<i64>> TypeSerializer for DateSerializer<T> {
fn serialize_clickhouse_format(
&self,
column: &ColumnRef,
_format: Arc<FormatSettings>,
_format: &FormatSettings,
) -> Result<opensrv_clickhouse::types::column::ArcColumnData> {
let array: &PrimitiveColumn<T> = Series::check_get(column)?;
let tz: Tz = "UTC".parse().unwrap();
Expand Down
14 changes: 7 additions & 7 deletions common/datavalues/src/types/serializations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::sync::Arc;


use common_arrow::arrow::bitmap::Bitmap;
use common_exception::ErrorCode;
Expand Down Expand Up @@ -47,25 +47,25 @@ pub use variant::*;

#[enum_dispatch]
pub trait TypeSerializer: Send + Sync {
fn serialize_value(&self, value: &DataValue, format: Arc<FormatSettings>) -> Result<String>;
fn serialize_json(&self, column: &ColumnRef, format: Arc<FormatSettings>)
fn serialize_value(&self, value: &DataValue, format: &FormatSettings) -> Result<String>;
fn serialize_json(&self, column: &ColumnRef, format: &FormatSettings)
-> Result<Vec<Value>>;
fn serialize_column(
&self,
column: &ColumnRef,
format: Arc<FormatSettings>,
format: &FormatSettings,
) -> Result<Vec<String>>;
fn serialize_clickhouse_format(
&self,
column: &ColumnRef,
_format: Arc<FormatSettings>,
_format: &FormatSettings,
) -> Result<ArcColumnData>;

fn serialize_json_object(
&self,
_column: &ColumnRef,
_valids: Option<&Bitmap>,
_format: Arc<FormatSettings>,
_format: &FormatSettings,
) -> Result<Vec<Value>> {
Err(ErrorCode::BadDataValueType(
"Error parsing JSON: unsupported data type",
Expand All @@ -75,7 +75,7 @@ pub trait TypeSerializer: Send + Sync {
fn serialize_json_object_suppress_error(
&self,
_column: &ColumnRef,
_format: Arc<FormatSettings>,
_format: &FormatSettings,
) -> Result<Vec<Option<Value>>> {
Err(ErrorCode::BadDataValueType(
"Error parsing JSON: unsupported data type",
Expand Down
8 changes: 4 additions & 4 deletions common/datavalues/src/types/serializations/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ pub struct NullSerializer {}
const NULL_STR: &str = "NULL";

impl TypeSerializer for NullSerializer {
fn serialize_value(&self, _value: &DataValue, _format: Arc<FormatSettings>) -> Result<String> {
fn serialize_value(&self, _value: &DataValue, _format: &FormatSettings) -> Result<String> {
Ok(NULL_STR.to_owned())
}

fn serialize_column(
&self,
column: &ColumnRef,
_format: Arc<FormatSettings>,
_format: &FormatSettings,
) -> Result<Vec<String>> {
let result: Vec<String> = vec![NULL_STR.to_owned(); column.len()];
Ok(result)
Expand All @@ -47,7 +47,7 @@ impl TypeSerializer for NullSerializer {
fn serialize_json(
&self,
column: &ColumnRef,
_format: Arc<FormatSettings>,
_format: &FormatSettings,
) -> Result<Vec<Value>> {
let null = Value::Null;
let result: Vec<Value> = vec![null; column.len()];
Expand All @@ -57,7 +57,7 @@ impl TypeSerializer for NullSerializer {
fn serialize_clickhouse_format(
&self,
column: &ColumnRef,
_format: Arc<FormatSettings>,
_format: &FormatSettings,
) -> Result<opensrv_clickhouse::types::column::ArcColumnData> {
let nulls = vec![1u8; column.len()];
let inner = Vec::column_from::<ArcColumnWrapper>(vec![1u8; column.len()]);
Expand Down
8 changes: 4 additions & 4 deletions common/datavalues/src/types/serializations/nullable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct NullableSerializer {
}

impl TypeSerializer for NullableSerializer {
fn serialize_value(&self, value: &DataValue, format: Arc<FormatSettings>) -> Result<String> {
fn serialize_value(&self, value: &DataValue, format: &FormatSettings) -> Result<String> {
if value.is_null() {
Ok("NULL".to_owned())
} else {
Expand All @@ -44,7 +44,7 @@ impl TypeSerializer for NullableSerializer {
fn serialize_column(
&self,
column: &ColumnRef,
format: Arc<FormatSettings>,
format: &FormatSettings,
) -> Result<Vec<String>> {
let column: &NullableColumn = Series::check_get(column)?;
let rows = column.len();
Expand All @@ -61,7 +61,7 @@ impl TypeSerializer for NullableSerializer {
fn serialize_json(
&self,
column: &ColumnRef,
format: Arc<FormatSettings>,
format: &FormatSettings,
) -> Result<Vec<Value>> {
let column: &NullableColumn = Series::check_get(column)?;
let rows = column.len();
Expand All @@ -78,7 +78,7 @@ impl TypeSerializer for NullableSerializer {
fn serialize_clickhouse_format(
&self,
column: &ColumnRef,
format: Arc<FormatSettings>,
format: &FormatSettings,
) -> Result<opensrv_clickhouse::types::column::ArcColumnData> {
let column: &NullableColumn = Series::check_get(column)?;
let inner = self
Expand Down
14 changes: 7 additions & 7 deletions common/datavalues/src/types/serializations/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

use std::marker::PhantomData;
use std::sync::Arc;


use common_arrow::arrow::bitmap::Bitmap;
use common_exception::Result;
Expand Down Expand Up @@ -51,14 +51,14 @@ where T: PrimitiveType
+ opensrv_clickhouse::io::Marshal
+ opensrv_clickhouse::io::Unmarshal<T>
{
fn serialize_value(&self, value: &DataValue, _format: Arc<FormatSettings>) -> Result<String> {
fn serialize_value(&self, value: &DataValue, _format: &FormatSettings) -> Result<String> {
Ok(format!("{:?}", value))
}

fn serialize_column(
&self,
column: &ColumnRef,
_format: Arc<FormatSettings>,
_format: &FormatSettings,
) -> Result<Vec<String>> {
let column: &PrimitiveColumn<T> = Series::check_get(column)?;
let result: Vec<String> = column.iter().map(|x| format!("{}", x)).collect();
Expand All @@ -68,7 +68,7 @@ where T: PrimitiveType
fn serialize_json(
&self,
column: &ColumnRef,
_format: Arc<FormatSettings>,
_format: &FormatSettings,
) -> Result<Vec<Value>> {
let column: &PrimitiveColumn<T> = Series::check_get(column)?;
let result: Vec<Value> = column
Expand All @@ -81,7 +81,7 @@ where T: PrimitiveType
fn serialize_clickhouse_format(
&self,
column: &ColumnRef,
_format: Arc<FormatSettings>,
_format: &FormatSettings,
) -> Result<opensrv_clickhouse::types::column::ArcColumnData> {
let col: &PrimitiveColumn<T> = Series::check_get(column)?;
let values: Vec<T> = col.iter().map(|c| c.to_owned()).collect();
Expand All @@ -92,15 +92,15 @@ where T: PrimitiveType
&self,
column: &ColumnRef,
_valids: Option<&Bitmap>,
format: Arc<FormatSettings>,
format: &FormatSettings,
) -> Result<Vec<Value>> {
self.serialize_json(column, format)
}

fn serialize_json_object_suppress_error(
&self,
column: &ColumnRef,
_format: Arc<FormatSettings>,
_format: &FormatSettings,
) -> Result<Vec<Option<Value>>> {
let column: &PrimitiveColumn<T> = Series::check_get(column)?;
let result: Vec<Option<Value>> = column
Expand Down
Loading

0 comments on commit db78d7a

Please sign in to comment.