-
Notifications
You must be signed in to change notification settings - Fork 172
Support TIMESTAMP_NS, TIMESTAMP_MS & TIMESTAMP_S #534
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bc88d9c
insert timestamp_ms & timestamp_ns into duckdb from pg working
destrex271 62c517f
timestamp_ms, timestamp_s converted accordingly when received from du…
destrex271 461c01f
timestamp_ms, timestamp_s converted accordingly when received from du…
destrex271 9b9f809
Merge branch 'main' into feature/ts_ns
destrex271 4679d7a
Merge branch 'main' into feature/ts_ns
destrex271 c10f6c4
added default case to silence CI
destrex271 7ba27b3
added default case to silence CI
destrex271 f3f569d
added default case to silence CI
destrex271 121a5d7
added default case to silence CI
destrex271 f249272
Added expected output for timestamp_ns, timestamp_ms and timestamp_s
destrex271 173607e
fixed format
destrex271 eaf37aa
Fix date format
JelteF File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -221,8 +221,25 @@ ConvertDateDatum(const duckdb::Value &value) { | |
|
|
||
| inline Datum | ||
| ConvertTimestampDatum(const duckdb::Value &value) { | ||
| duckdb::timestamp_t timestamp = value.GetValue<duckdb::timestamp_t>(); | ||
| return timestamp.value - pgduckdb::PGDUCKDB_DUCK_TIMESTAMP_OFFSET; | ||
| // Extract raw int64_t value of timestamp | ||
| int64_t rawValue = value.GetValue<int64_t>(); | ||
|
|
||
| // Handle specific Timestamp unit(sec, ms, ns) types | ||
| switch(value.type().id()){ | ||
| case duckdb::LogicalType::TIMESTAMP_MS: | ||
| // 1 ms = 10^3 micro-sec | ||
| rawValue *= 1000; | ||
| break; | ||
| case duckdb::LogicalType::TIMESTAMP_NS: | ||
|
||
| // 1 ns = 10^-3 micro-sec | ||
| rawValue /= 1000; | ||
| break; | ||
| case duckdb::LogicalType::TIMESTAMP_S: | ||
| // 1 s = 10^6 micro-sec | ||
| rawValue *= 1000000; | ||
| break; | ||
| } | ||
| return rawValue - pgduckdb::PGDUCKDB_DUCK_TIMESTAMP_OFFSET; | ||
| } | ||
|
|
||
| inline Datum | ||
|
|
@@ -1002,6 +1019,9 @@ GetPostgresDuckDBType(const duckdb::LogicalType &type) { | |
| case duckdb::LogicalTypeId::DATE: | ||
| return DATEOID; | ||
| case duckdb::LogicalTypeId::TIMESTAMP: | ||
| case duckdb::LogicalTypeId::TIMESTAMP_SEC: | ||
| case duckdb::LogicalTypeId::TIMESTAMP_MS: | ||
| case duckdb::LogicalTypeId::TIMESTAMP_NS: | ||
| return TIMESTAMPOID; | ||
| case duckdb::LogicalTypeId::TIMESTAMP_TZ: | ||
| return TIMESTAMPTZOID; | ||
|
|
@@ -1223,6 +1243,10 @@ ConvertPostgresToDuckValue(Oid attr_type, Datum value, duckdb::Vector &result, i | |
| case duckdb::LogicalTypeId::DATE: | ||
| Append<duckdb::date_t>(result, duckdb::date_t(static_cast<int32_t>(value + PGDUCKDB_DUCK_DATE_OFFSET)), offset); | ||
| break; | ||
|
|
||
| case duckdb::LogicalTypeId::TIMESTAMP_SEC: | ||
| case duckdb::LogicalTypeId::TIMESTAMP_MS: | ||
| case duckdb::LogicalTypeId::TIMESTAMP_NS: | ||
| case duckdb::LogicalTypeId::TIMESTAMP: | ||
| Append<duckdb::timestamp_t>( | ||
| result, duckdb::timestamp_t(static_cast<int64_t>(value + PGDUCKDB_DUCK_TIMESTAMP_OFFSET)), offset); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs a
defaultcase to silence the compiler warning