Repository navigation
fix treatIntegersAsDouble #75
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
Open
danovaro
wants to merge
1
commit into
develop
Choose a base branch
from
fix/treatIntegersAsDoubles
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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
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 |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| #include "eckit/io/FileHandle.h" | ||
| #include "eckit/testing/Test.h" | ||
|
|
||
| #include "odc/ODBAPISettings.h" | ||
| #include "odc/api/Odb.h" | ||
| #include "odc/api/odc.h" | ||
|
|
||
|
|
@@ -1283,6 +1284,80 @@ CASE("Test Span interface with and without treatIntegersAsDoubles") { | |
|
|
||
| // ------------------------------------------------------------------------------------------------------ | ||
|
|
||
| CASE("Test SQL filtering with and without treatIntegersAsDoubles") { | ||
|
|
||
| // The SQL engine evaluates everything as doubles, so the query results must not depend on whether integers | ||
| // are decoded as int64_t (where the integer 1 is the denormal bit pattern 0x1) or as doubles. | ||
|
|
||
| std::vector<int64_t> RESTRICTED{1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0}; | ||
| std::vector<int64_t> VALUES{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; | ||
|
|
||
| eckit::PathName path = "sql-filter-test-1"; | ||
|
|
||
| { | ||
| odc::api::Settings::treatIntegersAsDoubles(false); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here you set a global setting? |
||
|
|
||
| std::unique_ptr<eckit::DataHandle> dh(path.fileHandle()); | ||
| dh->openForWrite(0); | ||
| eckit::AutoClose closer(*dh); | ||
|
|
||
| std::vector<odc::api::ColumnInfo> columns{ | ||
| {"values@body", odc::api::ColumnType::INTEGER, sizeof(int64_t), {}}, | ||
| {"restricted@hdr", odc::api::ColumnType::INTEGER, sizeof(int64_t), {}}, | ||
| }; | ||
| std::vector<odc::api::ConstStridedData> strides{ | ||
| {&VALUES[0], VALUES.size(), sizeof(int64_t), sizeof(int64_t)}, | ||
| {&RESTRICTED[0], RESTRICTED.size(), sizeof(int64_t), sizeof(int64_t)}, | ||
| }; | ||
|
|
||
| odc::api::encode(*dh, columns, strides); | ||
| } | ||
|
|
||
| const std::set<long> RESTRICTED_VALUES{1, 2, 3, 4, 6, 9}; | ||
| const std::set<long> UNRESTRICTED_VALUES{5, 7, 8, 10, 11, 12}; | ||
|
|
||
| struct Query { | ||
| std::string sql; | ||
| std::set<long> expected; | ||
| }; | ||
| const std::vector<Query> queries{ | ||
| {"select * where restricted = 1", RESTRICTED_VALUES}, | ||
| {"select * where restricted = 0", UNRESTRICTED_VALUES}, | ||
| {"select * where restricted <> 1", UNRESTRICTED_VALUES}, | ||
| {"select * where restricted > 0", RESTRICTED_VALUES}, | ||
| {"select * where restricted = 0 or restricted is null", UNRESTRICTED_VALUES}, | ||
| }; | ||
|
|
||
| for (bool asDoubles : {false, true}) { | ||
| odc::api::Settings::treatIntegersAsDoubles(asDoubles); | ||
|
|
||
| std::unique_ptr<eckit::DataHandle> dh(path.fileHandle()); | ||
| dh->openForRead(); | ||
| eckit::AutoClose closer(*dh); | ||
|
|
||
| odc::api::Reader reader(*dh, /* aggregated */ true); | ||
| odc::api::Frame frame = reader.next(); | ||
| EXPECT(frame.rowCount() == RESTRICTED.size()); | ||
|
|
||
| for (const auto& query : queries) { | ||
| odc::api::Frame filtered = frame.filter(query.sql); | ||
|
|
||
| // The setting of the caller must be unaffected, and the filtered frame decodes accordingly | ||
| EXPECT(odc::ODBAPISettings::instance().integersAsDoubles() == asDoubles); | ||
|
|
||
| ASSERT(filtered); | ||
| EXPECT(filtered.rowCount() == query.expected.size()); | ||
|
|
||
| odc::api::Span s = filtered.span(std::vector<std::string>({"values", "restricted"}), /* onlyConst */ false); | ||
| EXPECT(s.getIntegerValues("values") == query.expected); | ||
| } | ||
|
|
||
| EXPECT(!reader.next()); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but it's never resetted? |
||
| } | ||
| } | ||
|
|
||
| // ------------------------------------------------------------------------------------------------------ | ||
|
|
||
| // CASE("Decode an entire ODB file") { | ||
| // | ||
| // odc::api::Odb o("../2000010106-reduced.odb"); | ||
|
|
||
Oops, something went wrong.
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.
Would this also apply to other places?
Seems like a general problem of the SQL interface?