forked from databendlabs/databend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(query): load ndjson support ts with diff units. (databendlabs#17203
) * feat(query): load ndjson/csv/tsv support ts with diff units. * fix * refactor * refactor * fix clippy
- Loading branch information
1 parent
fa209f4
commit 069bdbb
Showing
13 changed files
with
121 additions
and
82 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2021 Datafuse Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::io::Cursor; | ||
|
||
use bstr::ByteSlice; | ||
use databend_common_exception::ErrorCode; | ||
use databend_common_exception::Result; | ||
use databend_common_expression::types::timestamp::clamp_timestamp; | ||
use databend_common_io::cursor_ext::read_num_text_exact; | ||
use databend_common_io::cursor_ext::BufferReadDateTimeExt; | ||
use databend_common_io::cursor_ext::DateTimeResType; | ||
use databend_common_io::cursor_ext::ReadBytesExt; | ||
use databend_functions_scalar_datetime::datetime::int64_to_timestamp; | ||
|
||
use crate::InputCommonSettings; | ||
|
||
pub(crate) fn read_timestamp( | ||
column: &mut Vec<i64>, | ||
data: &[u8], | ||
settings: &InputCommonSettings, | ||
) -> Result<()> { | ||
let ts = if !data.contains(&b'-') { | ||
int64_to_timestamp(read_num_text_exact(data)?) | ||
} else { | ||
let mut buffer_readr = Cursor::new(&data); | ||
let t = buffer_readr.read_timestamp_text(&settings.jiff_timezone)?; | ||
match t { | ||
DateTimeResType::Datetime(t) => { | ||
if !buffer_readr.eof() { | ||
let data = data.to_str().unwrap_or("not utf8"); | ||
let msg = format!( | ||
"fail to deserialize timestamp, unexpected end at pos {} of {}", | ||
buffer_readr.position(), | ||
data | ||
); | ||
return Err(ErrorCode::BadBytes(msg)); | ||
} | ||
let mut ts = t.timestamp().as_microsecond(); | ||
clamp_timestamp(&mut ts); | ||
ts | ||
} | ||
_ => unreachable!(), | ||
} | ||
}; | ||
column.push(ts); | ||
Ok(()) | ||
} |
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
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
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
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,8 @@ | ||
1736305864,('1736305864') | ||
1736305865000,('1736305865000') | ||
1736305866000000,('1736305866000000') | ||
1,('1') | ||
1970-01-01 00:00:01,('1970-01-01 00:00:01') | ||
1970-01-01 00:00:00.001,('1970-01-01 00:00:00.001') | ||
1970-01-01 00:00:00.000001,('1970-01-01 00:00:00.000001') | ||
1970-01-01 00:00:00.000000,('1970-01-01 00:00:00.000000') |
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,3 @@ | ||
{"t":1736305864} | ||
{"t":1736305865000} | ||
{"t":1736305866000000} |
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