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

SNOW-1739603: Implement toml config file parsing #836

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

sfc-gh-ext-simba-nl
Copy link
Collaborator

@sfc-gh-ext-simba-nl sfc-gh-ext-simba-nl commented Feb 28, 2025

SNOW-1739603: Implement toml config file parsing in libsnowflakeclient to be used in other connectors.
Added toml_config_parser file with load_toml_config, returns a key=value; style string with parsed parameters.
Behaviour: If SNOWFLAKE_HOME exists, searches for toml config file there, otherwise defaults to ~/.snowflake.
Within toml config file, if SNOWFLAKE_DEFAULT_CONNECTION_NAME defined, use that as configuration name, otherwise defaults to default.

@sfc-gh-ext-simba-nl sfc-gh-ext-simba-nl requested a review from a team as a code owner February 28, 2025 00:43
@sfc-gh-ext-simba-nl
Copy link
Collaborator Author

sfc-gh-ext-simba-nl commented Mar 3, 2025

Hi,
For some reason, build_tomlplusplus.sh isn't updating to the latest commit. Even if I remove the file and add it back, it's still running the version I first committed. Can someone help me look into why it's doing that? @sfc-gh-jszczerbinski
Thanks

Copy link
Collaborator

@sfc-gh-jszczerbinski sfc-gh-jszczerbinski left a comment

Choose a reason for hiding this comment

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

Changed permissions for build scripts on linux and now they fail: please fix it.
I have some issues with general design of this feature - passing the parameters as connection string, I will re-review the code after the changes

* Load toml configuration file.
* @param connectionParams The connection parameters parsed from the toml configuration file in k=v; format
*/
void load_toml_config(char** connectionParams);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should expose the parameters via C++ API, for example sth like this?
std::map<std::string, std::string> loadTomlConfig()

@@ -0,0 +1,109 @@
/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need for copyright

#include "snowflake/TomlConfigParser.hpp"
#include "../logger/SFLogger.hpp"
#include "memory.h"
#include <toml++/toml.hpp>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use #define TOML_EXCEPTIONS 0
https://marzer.github.io/tomlplusplus/#mainpage-example-parsing-without-exceptions

We want to move towards exception free code

char tomlConfig[] = "[default]\nkey1 = \"value1\"\nkey2 = \"value2\"";
char tomlFilePath[] = "./connections.toml";
FILE* file;
file = fopen(tomlFilePath, "w");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use c++ fstream API instead. Same for other tests


char envbuf[MAX_PATH + 1];
char* snowflakeHome = sf_getenv_s("SNOWFLAKE_HOME", envbuf, sizeof(envbuf));
sf_setenv("SNOWFLAKE_HOME", "./");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please extract EnvOverride class from test_unit_secure_storage.cpp to a new file tests/utils/EnvOverride.hpp. It will make sure we cleanup env after test finishes without being too verbose. Same for other tests

cmocka_unit_test(test_missing_toml_file),
cmocka_unit_test(test_invalid_toml_file),
cmocka_unit_test(test_client_config_log_invalid_config_name),
#if (!defined(_WIN32) && !defined(_DEBUG)) || defined(_WIN64)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need this ifdef?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

on 32-bit windows debug build, the toml::parse_file call causes a "(_osfile(fh) & FOPEN)" debug assertion causing test cases to hang indefinitely. It gets bypassed with the ifdef in load_toml_config, but the rest of the test case is irrelevant anyways because of that. So I can either ifdef each test case separately to check for nothing or just not run it entirely since it doesn't actually test for anything

void test_valid_toml_file(void** unused) {
SF_UNUSED(unused);
// Create toml file
char tomlConfig[] = "[default]\nkey1 = \"value1\"\nkey2 = \"value2\"";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer std::string over char[], same in other tests

@@ -12,6 +12,7 @@
#include "../logger/SFLogger.hpp"
#include <chrono>
#include "SnowflakeCommon.hpp"
#include <chrono>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove the include, it's not needed. The same file is included in 13th line of this file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants