Skip to content

Commit 82fe3ec

Browse files
add date datatype for static schema, no change for dynamic
1 parent 0c0edac commit 82fe3ec

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/event/format/json.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use anyhow::anyhow;
2323
use arrow_array::RecordBatch;
2424
use arrow_json::reader::{infer_json_schema_from_iterator, ReaderBuilder};
2525
use arrow_schema::{DataType, Field, Fields, Schema};
26-
use chrono::{DateTime, NaiveDateTime, Utc};
26+
use chrono::{DateTime, NaiveDate, NaiveDateTime, Utc};
2727
use datafusion::arrow::util::bit_util::round_upto_multiple_of_64;
2828
use itertools::Itertools;
2929
use serde_json::Value;
@@ -293,6 +293,12 @@ fn valid_type(
293293
DataType::Struct(fields) => {
294294
validate_struct(fields, value, schema_version, static_schema_flag)
295295
}
296+
DataType::Date32 => {
297+
if let Value::String(s) = value {
298+
return NaiveDate::parse_from_str(s, "%Y-%m-%d").is_ok();
299+
}
300+
false
301+
}
296302
DataType::Timestamp(_, _) => value.is_string() || value.is_number(),
297303
_ => {
298304
error!(

src/query/stream_schema_provider.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,7 @@ fn cast_or_none(scalar: &ScalarValue) -> Option<CastRes<'_>> {
967967
ScalarValue::UInt32(val) => val.map(|val| CastRes::Int(val as i64)),
968968
ScalarValue::UInt64(val) => val.map(|val| CastRes::Int(val as i64)),
969969
ScalarValue::Utf8(val) => val.as_ref().map(|val| CastRes::String(val)),
970+
ScalarValue::Date32(val) => val.map(|val| CastRes::Int(val as i64)),
970971
ScalarValue::TimestampMillisecond(val, _) => val.map(CastRes::Int),
971972
_ => None,
972973
}

src/static_schema.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ pub fn convert_static_schema_to_arrow_schema(
111111
"boolean" => DataType::Boolean,
112112
"string" => DataType::Utf8,
113113
"datetime" => DataType::Timestamp(TimeUnit::Millisecond, None),
114+
"date" => DataType::Date32,
114115
"string_list" => {
115116
DataType::List(Arc::new(Field::new("item", DataType::Utf8, true)))
116117
}

0 commit comments

Comments
 (0)