fix(bq_driver): Fix encoding for SAP HANA#1506
Conversation
735d19f to
873b9da
Compare
311c71e to
814c1fb
Compare
511f04e to
7b8b154
Compare
f9232a2 to
9ce5ad1
Compare
07fe46c to
c350b18
Compare
| std::regex named_pattern(R"([:@]\w+)"); | ||
|
|
||
| // Check for positional parameters | ||
| if (std::regex_search(query, positional_pattern)) { |
There was a problem hiding this comment.
Let's deep dive into the reason this was crashing.
Let's print query and positional_pattern. Let's write a small c++ application to verify that it crashes independently.
There was a problem hiding this comment.
Have verified and independently it works, issue is due to SAP HANA interfering with std::regex ABI , using re2 regex instead
3ae14c6 to
79a7205
Compare
| for (auto const& procedure_field : bq_procedure.schema.fields) { | ||
| std::regex column_pattern = BuildRegex(bq_procedure_column, metadata_id); | ||
| if (std::regex_match(procedure_field.name, column_pattern)) { | ||
| auto column_pattern = BuildRegex(bq_procedure_column, metadata_id); |
There was a problem hiding this comment.
We avoid using auto for better readability.
efcec36 to
83ddd86
Compare
83ddd86 to
337cd07
Compare
|
@sachinpro please check the PR |
| return false; | ||
| #else | ||
| if (sizeof(SQLWCHAR) != 4) return false; | ||
| return g_utf16le_wire_latched.load(std::memory_order_relaxed); |
There was a problem hiding this comment.
Please check what is the value returned here and sizeof(SQLWCHAR).
There was a problem hiding this comment.
IsRuntimeWireUtf16Le returns true here for SAP HANA and prints sizeof(SQLWCHAR) as 4 as the driver is built with iodbc where sizeof(SQLWCHAR) is 4 , and that's why we can't directly use sizeof(SQLWCHAR) as on SAP HANA system
| // later call (including the ambiguous ones from SQLTables(catalog="%")) | ||
| // honors the latch via IsRuntimeWireUtf16Le(). | ||
| if (sizeof(SQLWCHAR) == 4) { | ||
| bool use_utf16le = g_utf16le_wire_latched.load(std::memory_order_relaxed); |
There was a problem hiding this comment.
Let's read DriverManagerEncoding from googlebigqueryodbc.ini to read the encoding and WireWcharSize should use it.
| std::memset(outConnectionString, '\0', | ||
| outConnectionStringBufferLen * sizeof(SQLWCHAR)); | ||
| std::memcpy((SQLWCHAR*)outConnectionString, | ||
| ToSqlWChar(utf16_out_conn_str->data()), |
There was a problem hiding this comment.
Lets do the bit manipulation inside ToSqlWChar consitionally for HANA, without changing the signature of that function. We just need to return the 4 bytes of SQLWCHAR in a way that final memcpy writes them correctly in chunks of utf-16 characters.
There was a problem hiding this comment.
ToSqlWChar was making the logic overly complicated and not reusable at other places where we were utilising SQLWchar directly to write to the buffer, have refactored and simplified the logic to not do unnecessary copying and reuse WriteWideToWireBuffer function everywhere, Have tested on both SAP Hana and on Tableau, PowerBi to verify things.
d2d02c2 to
31136af
Compare
2054549 to
0a47525
Compare
0a47525 to
2b1c9d0
Compare
2b1c9d0 to
2c8bd1a
Compare
Fixed the encoding which was causing the issue on SAP HANA and had a different size of SQLWCHAR that the one it was built with . Another issue was the usage of std::regex crashing the driver due conflicting ABI with SAP HANA and moved to use RE2 regex now. PR size is bigger as had to change the usage of SQLWCHAR vector wherever we were creating earlier. Windows and linux checks are run here. Have verified on windows third party tools , seems working fine