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

fix: fix time display #585

Merged
merged 6 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 7 additions & 6 deletions .github/workflows/bindings.nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
node-version: "22"
- name: Corepack
working-directory: bindings/nodejs
run: corepack enable
run: npm i -g --force corepack && corepack enable
- name: Install dependencies
working-directory: bindings/nodejs
run: pnpm install
Expand All @@ -54,8 +54,9 @@ jobs:
- { target: aarch64-unknown-linux-gnu, runner: ubuntu-20.04 }
- { target: x86_64-unknown-linux-musl, runner: ubuntu-latest }
- { target: aarch64-unknown-linux-musl, runner: ubuntu-latest }
- { target: x86_64-pc-windows-msvc, runner: windows-latest }
- { target: aarch64-pc-windows-msvc, runner: windows-latest }
# resolve it after: https://github.com/actions/setup-node/issues/1222
# - { target: x86_64-pc-windows-msvc, runner: windows-latest }
# - { target: aarch64-pc-windows-msvc, runner: windows-latest }
- { target: x86_64-apple-darwin, runner: macos-latest }
- { target: aarch64-apple-darwin, runner: macos-latest }
steps:
Expand All @@ -76,7 +77,7 @@ jobs:
version: 0.11.0
- name: Corepack
working-directory: bindings/nodejs
run: corepack enable
run: npm i -g --force corepack && corepack enable
- name: Install dependencies
working-directory: bindings/nodejs
run: pnpm install
Expand Down Expand Up @@ -117,7 +118,7 @@ jobs:
node-version: ${{ matrix.ver }}
- name: Corepack
working-directory: bindings/nodejs
run: corepack enable
run: npm i -g --force corepack && corepack enable
- name: Install dependencies
working-directory: bindings/nodejs
run: pnpm install
Expand Down Expand Up @@ -146,7 +147,7 @@ jobs:
node-version: "22"
- name: Corepack
working-directory: bindings/nodejs
run: corepack enable
run: npm i -g --force corepack && corepack enable
- name: Install dependencies
working-directory: bindings/nodejs
run: pnpm install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
with:
node-version: "22"

- run: corepack enable
- run: npm i -g --force corepack && corepack enable

- name: Install dependencies
working-directory: frontend/
Expand Down
1 change: 1 addition & 0 deletions cli/tests/00-base.result
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ a 1 true [1,2]
1
2
3
1740-10-08 10:16:40.001000 1740-10-08 10:16:40.000000 1740-10-08 10:16:39.999000
[] {}
with comment
1
Expand Down
1 change: 1 addition & 0 deletions cli/tests/00-base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ insert into test select to_string(number), number, false, number from numbers(10
select min(a), max(b), max(d), count() from test;

select '1';select 2; select 1+2;
select TO_TIMESTAMP(-7233803000000+1), TO_TIMESTAMP(-7233803000000), TO_TIMESTAMP(-7233803000000-1);

select [], {};

Expand Down
6 changes: 3 additions & 3 deletions cli/tests/http/01-load_stdin.result
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Transaction Processing Jim Gray 1992 2020-01-01 11:11:11.345
Readings in Database Systems Michael Stonebraker 2004 2020-01-01 11:11:11
Three Body NULL-liucixin 2019 2019-07-04 00:00:00
Transaction Processing Jim Gray 1992 2020-01-01 11:11:11.345000
Readings in Database Systems Michael Stonebraker 2004 2020-01-01 11:11:11.000000
Three Body NULL-liucixin 2019 2019-07-04 00:00:00.000000
6 changes: 3 additions & 3 deletions cli/tests/http/02-load_file.result
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Transaction Processing Jim Gray 1992 2020-01-01 11:11:11.345
Readings in Database Systems Michael Stonebraker 2004 2020-01-01 11:11:11
Three Body NULL-liucixin 2019 2019-07-04 00:00:00
Transaction Processing Jim Gray 1992 2020-01-01 11:11:11.345000
Readings in Database Systems Michael Stonebraker 2004 2020-01-01 11:11:11.000000
Three Body NULL-liucixin 2019 2019-07-04 00:00:00.000000
16 changes: 10 additions & 6 deletions sql/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const DAYS_FROM_CE: i32 = 719_163;
const NULL_VALUE: &str = "NULL";
const TRUE_VALUE: &str = "1";
const FALSE_VALUE: &str = "0";
const TIMESTAMP_FORMAT: &str = "%Y-%m-%d %H:%M:%S%.6f";

#[cfg(feature = "flight-sql")]
use {
Expand Down Expand Up @@ -837,15 +838,18 @@ fn encode_value(f: &mut std::fmt::Formatter<'_>, val: &Value, raw: bool) -> std:
write!(f, "'{}'", s)
}
}
Value::Timestamp(i) => {
let secs = i / 1_000_000;
let nanos = ((i % 1_000_000) * 1000) as u32;
let t = DateTime::from_timestamp(secs, nanos).unwrap_or_default();
Value::Timestamp(micros) => {
let (mut secs, mut nanos) = (*micros / 1_000_000, (*micros % 1_000_000) * 1_000);
if nanos < 0 {
secs -= 1;
nanos += 1_000_000_000;
}
let t = DateTime::from_timestamp(secs, nanos as _).unwrap_or_default();
let t = t.naive_utc();
if raw {
write!(f, "{}", t)
write!(f, "{}", t.format(TIMESTAMP_FORMAT))
} else {
write!(f, "'{}'", t)
write!(f, "'{}'", t.format(TIMESTAMP_FORMAT))
}
}
Value::Date(i) => {
Expand Down
Loading