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

Data conversion: timing data types. Testing #7

Merged
merged 26 commits into from
Jun 4, 2018
Merged

Data conversion: timing data types. Testing #7

merged 26 commits into from
Jun 4, 2018

Conversation

bpintea
Copy link
Collaborator

@bpintea bpintea commented May 29, 2018

This PR continues the data conversion development item.

An application is allowed to specify what it wants written in the provided buffers, for each select column in a result set. The driver is then responsible to convert the data between what's been received from the data source (ES/SQL) to what buffer type the application bound to those columns.

In the potential conversion matrix, some conversions are explicitly unsupported (like float to timestamp). The driver reduces further the possibility set, by not supporting some data types (like GUID or interval types).

This PR adds conversions to: DATE, TIME and TIMESTAMP.
It also handles the interval types, by rejecting the conversion.

The PR also introduces Google Test as the testing framework; the four tests suites added relate to the above functionality.

bpintea added 18 commits May 16, 2018 11:27
the value stays the same, but this is the technical right way
ODBC excludes certain data conversions between SQL/DB tyeps and
application C buffers.
This commit adds a check done - and cached - at SQLFetch() time, that
compares the types received in result set columns to types assigned by
application to the bound buffers.
c/p err, used lenght buffer (`pcbCharAttr`) instead of character buffer
(`pCharAttr`).
- add gtest to the build system;
- replace environment vars with cmake options for external dependencies
  location (to eventually be fetched by cmake's ExternalProject);
- add a few new params to the bulid batch to better support the testing
  framework, symbols available in the DLL and platform detection.
The SQL_API marker was copied by mistake as function attribute.
Only queries deals with JSON code, move UJArraySize() functions there.
ujson4c exports one symbols with __declspec. mask it in the generated
.LIB and exported anonymously in the .DLL. This as alternative to
patching the library.
Data conversions make use of the SQL data types. Make sure that the
value reported by 'SYS TYPES' query corresponds to the name of the data
type, which is actually used as data key (since more types with
different names - and other various parameters - can share some SQL type).
this connection mode allows passing the ES/SQL data types to a
connection, w/o actually to connect to an Elasticsearch server.
Export into the output library some functions that allow attaching a
(faked) server answer. This allows for testing w/o an Elasticsearch
server.
- implement all allowed conversions to SQL_C_TYPE_TIMESTAMP.
- Break the loop when running individual tests;
- use less indentation on the help output.
- add the possible conversions to the respective time types
- also change the declaration of the values used for testing to minimize
duplication
...to include the data type tested.
- these are currently following ES/SQL lack of support and offer no
conversion support;
- added another check for convertability to pick out these unsupported
types (GUID, interval) once, at Fetch time, to allow for faster failure.
@bpintea bpintea requested review from droberts195 and edsavage May 29, 2018 15:19
@bpintea bpintea mentioned this pull request May 29, 2018
Closed
CMakeLists.txt Outdated
"'ODBC-Specification' export into local 'lib' dir.")
endif (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/ODBC-Specification)
endif (IS_DIRECTORY $ENV{ODBC_PATH_SRC})
# TODO: add this as a git submodule and/or as ExternalProject
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a git submodule will require extra work in release manager. A git subtree would not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. git subtree would indeed be a lighter option.

@@ -0,0 +1,140 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the test files have a copyright header.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Will added them. I guess I'll add the old license header and change it along with the migration to the new license (otherwise I'd have to add the top license file already).

driver/util.h Outdated
@@ -34,6 +34,14 @@
#include "sql.h"
#include "sqlext.h"

#ifndef NDEBUG
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's a good idea to couple whether assertions are enabled with whether the tests are being run. Even if it's only very rarely used I think it would be best to have the option to build a non-test library with assertions and also run the tests with assertions compiled out.

Copy link
Collaborator Author

@bpintea bpintea May 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not really, you're right. I initially started looking into identifying/controlling in CMake the build type (Debug/Release etc) when using the MSVC generators, but that took a bit longer than I wanted and default to this solution. But I'll resume that effort now and adjust this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decoupled them in f3f376e.

driver/util.h Outdated
@@ -34,6 +34,14 @@
#include "sql.h"
#include "sqlext.h"

#ifndef NDEBUG
/* export attribute for internal functions used for testing */
#define TEST_API __declspec(dllexport)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you ever have a need to include the headers that use TEST_API in a program that's using the driver DLL? If you do maybe you need some logic like we use in ML to define the macro to dllimport instead of dllexport in this case, for example see https://github.com/elastic/ml-cpp/blob/7e1528bbaa016a4bc0e97b4b3f005e84dc831b9b/include/maths/ImportExport.h#L23

Copy link
Collaborator Author

@bpintea bpintea May 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the unit testing executables would make use of the TEST_API exports.
(In no other case would those functions be used: the Driver Manager that loads the driver and dispatches the API calls would not know how to use any other exported symbol, except the ODBC spec ones.)
AFAIU however, even in this case the dllimport would help (generate "more efficient code", though for testing only in this case), so it looks like it'd be a good idea to add it anyways?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added it with a1b0596.

driver/util.c Outdated
@@ -80,7 +100,10 @@ BOOL wstr2long(wstr_st *val, long *out)
int ansi_w2c(const SQLWCHAR *src, char *dst, size_t chars)
{
int i = 0;


if (chars < 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you said before that you were aiming to always use braces with if statements. I guess the coding style is up to you, but just checking if you do want to adhere to that policy.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that's true. Fixed it, thanks.

string(REPLACE ".cxx" "" TBIN ${TSRC})
add_executable(${TBIN} ${TSRC} ${EXTRA_SRC})
set_target_properties(${TBIN} PROPERTIES COMPILE_FLAGS ${CMAKE_C_FLAGS})
target_link_libraries(${TBIN} ${GTEST_LD_PATH}/gtestd.lib)
Copy link
Collaborator

@edsavage edsavage May 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to consider providing a separate, common main routine and linking against that (or using the one provided by the gtest_main library) here instead. It will reduce the duplication of the common main routine in each of the test files and simplify the running of the entire test suite.

It could also be useful to generate test reports using the --gtest_output command line arg (or the corresponding environment variable). This could be useful when integrating with CI down the line...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to consider linking against the gtest_main library here instead. It will reduce the duplication of the common main routine in each of the test files and simplify the running of the entire test suite.

Linked against the main lib, thanks. (I've actually started like that, but removed it for some reason and then just copy&pasted with the main in).

It could also be useful to generate test reports using the --gtest_output command line arg (or the corresponding environment variable).

I would leave this to be controlled by the presence of the env vars, mainly b/c I'm not sure how to manage the generated files. But if you had something specific in mind, sure, I'll add it in.
(FWIW, currently, the build script will generate a report, both when invoking the RUN_TESTS target (test arg), as well as when executing the individual tests itself (suites arg) ).

Copy link
Collaborator

@edsavage edsavage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I've made a couple of suggestion regarding the test suite.

bpintea added 5 commits May 31, 2018 14:28
- take the main() out of the tests, use google test lib provided for
this.
- using the "previous" Elastic license for now.
The goal is be able to run the tests in both cases, when the asserts are
in the code or out.
This is now achieved by only defining TEST_API macro, when it's not
already done.
The Release and MinSizeRel build configs will define it,
so the test functions won't be exported anymore (i.e. tests can't be
run).
Debug and RelWithDebInfo will not define it, so tests will be possible.
- besides the (arbitrary) minor and major numbers and the unicode/ansi
indicators ('u'/'a'), the string now contains also the the commit/tag
and what build config it was used: 'd'(ebug), 'r'(elease) etc.
- the build.bat will take a new parameter, type=T, where T can be one of
Debug, Release, RelWithDebInfo or MinSizeRel
bpintea added 2 commits June 1, 2018 17:57
- as alternative to the dllexport one, when building the driver, used
with test calls
Copy link
Contributor

@droberts195 droberts195 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bpintea bpintea merged commit 0c68261 into elastic:master Jun 4, 2018
@bpintea bpintea deleted the feature/data_conversion branch June 4, 2018 10:19
bpintea added a commit that referenced this pull request Jun 4, 2018
Data conversion: timing data types. Testing
@bpintea bpintea added >feature Applicable to PRs adding new functionality v6.5.0 >test PRs targeting exclusively the testing framework labels May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>feature Applicable to PRs adding new functionality >test PRs targeting exclusively the testing framework v6.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants