Skip to content

Commit 0e1c99c

Browse files
SNOW-1342953: read lob size from server parameters (#735)
1 parent e826d24 commit 0e1c99c

8 files changed

+58
-18
lines changed

include/snowflake/client.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ extern "C" {
5959
/**
6060
* The maximum object size
6161
*/
62-
#define SF_MAX_OBJECT_SIZE 16777216
62+
#define SF_MAX_OBJECT_SIZE SF_MACRO_DEPRECATED_WARNING("SF_MAX_OBJECT_SIZE is deprecated, please use snowflake_get_attribute() instead to retrieve the max LOB size.") 16777216
6363

6464
/**
6565
* Login timeout in seconds
@@ -259,6 +259,9 @@ typedef enum SF_ATTRIBUTE {
259259
SF_CON_INCLUDE_RETRY_REASON,
260260
SF_CON_RETRY_TIMEOUT,
261261
SF_CON_MAX_RETRY,
262+
SF_CON_MAX_VARCHAR_SIZE,
263+
SF_CON_MAX_BINARY_SIZE,
264+
SF_CON_MAX_VARIANT_SIZE,
262265
SF_DIR_QUERY_URL,
263266
SF_DIR_QUERY_URL_PARAM,
264267
SF_DIR_QUERY_TOKEN,
@@ -385,6 +388,11 @@ typedef struct SF_CONNECT {
385388

386389
// Error
387390
SF_ERROR_STRUCT error;
391+
392+
// max lob size
393+
uint64 max_varchar_size;
394+
uint64 max_binary_size;
395+
uint64 max_variant_size;
388396
} SF_CONNECT;
389397

390398
/**

lib/client.c

+20
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ static SF_STATUS STDCALL _reset_connection_parameters(
175175
sf->qcc_capacity = snowflake_cJSON_GetUint64Value(value);
176176
qcc_set_capacity(sf, sf->qcc_capacity);
177177
}
178+
else if (strcmp(name->valuestring, "VARCHAR_AND_BINARY_MAX_SIZE_IN_RESULT") == 0) {
179+
sf->max_varchar_size = snowflake_cJSON_GetUint64Value(value);
180+
sf->max_binary_size = sf->max_varchar_size / 2;
181+
}
182+
else if (strcmp(name->valuestring, "VARIANT_MAX_SIZE_IN_RESULT") == 0) {
183+
sf->max_variant_size = snowflake_cJSON_GetUint64Value(value);
184+
}
178185
}
179186
}
180187
SF_STATUS ret = SF_STATUS_ERROR_GENERAL;
@@ -712,6 +719,10 @@ SF_CONNECT *STDCALL snowflake_init() {
712719
sf->qcc_capacity = SF_QCC_CAPACITY_DEF;
713720
sf->qcc_disable = SF_BOOLEAN_FALSE;
714721
sf->qcc = NULL;
722+
723+
sf->max_varchar_size = SF_DEFAULT_MAX_OBJECT_SIZE;
724+
sf->max_binary_size = SF_DEFAULT_MAX_OBJECT_SIZE / 2;
725+
sf->max_variant_size = SF_DEFAULT_MAX_OBJECT_SIZE;
715726
}
716727

717728
return sf;
@@ -1263,6 +1274,15 @@ SF_STATUS STDCALL snowflake_get_attribute(
12631274
case SF_CON_INCLUDE_RETRY_REASON:
12641275
*value = &sf->include_retry_reason;
12651276
break;
1277+
case SF_CON_MAX_VARCHAR_SIZE:
1278+
*value = &sf->max_varchar_size;
1279+
break;
1280+
case SF_CON_MAX_BINARY_SIZE:
1281+
*value = &sf->max_binary_size;
1282+
break;
1283+
case SF_CON_MAX_VARIANT_SIZE:
1284+
*value = &sf->max_variant_size;
1285+
break;
12661286
default:
12671287
SET_SNOWFLAKE_ERROR(&sf->error, SF_STATUS_ERROR_BAD_ATTRIBUTE_TYPE,
12681288
"Invalid attribute type",

lib/client_int.h

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#define DEFAULT_SNOWFLAKE_REQUEST_TIMEOUT 60
2525

26+
#define SF_DEFAULT_MAX_OBJECT_SIZE 16777216
27+
2628
#define SESSION_URL "/session/v1/login-request"
2729
#define QUERY_URL "/queries/v1/query-request"
2830
#define RENEW_SESSION_URL "/session/token-request"

tests/test_crud.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ void _fetch_data(SF_STMT *sfstmt, int64 expected_sum) {
1616
assert_int_equal(num_fields, 2);
1717

1818
SF_COLUMN_DESC *descs = snowflake_desc(sfstmt);
19+
uint64* max_varchar_size_p = NULL;
20+
snowflake_get_attribute(sfstmt->connection, SF_CON_MAX_VARCHAR_SIZE, (void**)&max_varchar_size_p);
1921
int i;
2022
for (i = 0; i < num_fields; ++i) {
2123
switch (i) {
@@ -35,8 +37,8 @@ void _fetch_data(SF_STMT *sfstmt, int64 expected_sum) {
3537
assert_int_equal(descs[i].idx, 2);
3638
assert_int_equal(descs[i].type, SF_DB_TYPE_TEXT);
3739
assert_int_equal(descs[i].c_type, SF_C_TYPE_STRING);
38-
assert_int_equal(descs[i].byte_size, 16777216);
39-
assert_int_equal(descs[i].internal_size, 16777216);
40+
assert_int_equal(descs[i].byte_size, *max_varchar_size_p);
41+
assert_int_equal(descs[i].internal_size, *max_varchar_size_p);
4042
assert_int_equal(descs[i].precision, 0);
4143
assert_int_equal(descs[i].scale, 0);
4244
assert_int_equal(descs[i].null_ok, 1);

tests/test_unit_file_metadata_init.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
#include <FileMetadataInitializer.hpp>
77
#include "FileMetadata.hpp"
88
#include "FileCompressionType.hpp"
9-
#include "utils/test_setup.h"
10-
#include "utils/TestSetup.hpp"
119
#include "snowflake/platform.h"
1210
#include <unordered_set>
1311
#include <iostream>
@@ -16,6 +14,8 @@
1614
#include <memory>
1715
#include "snowflake/IStatementPutGet.hpp"
1816
#include "StatementPutGet.hpp"
17+
#include "utils/test_setup.h"
18+
#include "utils/TestSetup.hpp"
1919

2020
#define FILES_IN_DIR "file1.csv", "file2.csv", "file3.csv", "file4.csv", "file1.gz"
2121

tests/test_unit_jwt.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
* Copyright (c) 2018-2019 Snowflake Computing, Inc. All rights reserved.
33
*/
44

5-
#include "utils/TestSetup.hpp"
6-
#include "utils/test_setup.h"
7-
#include <jwt/Jwt.hpp>
85
#include "openssl/rsa.h"
96
#include <openssl/pem.h>
7+
#include <jwt/Jwt.hpp>
8+
#include "utils/TestSetup.hpp"
9+
#include "utils/test_setup.h"
1010

1111
using Snowflake::Client::Jwt::IHeader;
1212
using Snowflake::Client::Jwt::IClaimSet;

tests/test_unit_set_get_attributes.cpp

+16-8
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
#include <cassert>
66
#include <string>
7-
#include "utils/test_setup.h"
8-
#include "utils/TestSetup.hpp"
97
#include "memory.h"
8+
#include "../lib/client_int.h"
109
#include <vector>
10+
#include "utils/test_setup.h"
11+
#include "utils/TestSetup.hpp"
1112

1213
typedef struct sf_string_attributes {
1314
SF_ATTRIBUTE type;
@@ -72,13 +73,15 @@ std::vector<sf_int_attributes> intAttributes = {
7273
{ SF_CON_MAX_RETRY, 6 },
7374
{ SF_CON_RETRY_TIMEOUT, 0 },
7475
{ SF_CON_MAX_RETRY, 0 },
76+
{ SF_CON_MAX_VARCHAR_SIZE, SF_DEFAULT_MAX_OBJECT_SIZE },
77+
{ SF_CON_MAX_BINARY_SIZE, SF_DEFAULT_MAX_OBJECT_SIZE / 2 },
78+
{ SF_CON_MAX_VARIANT_SIZE, SF_DEFAULT_MAX_OBJECT_SIZE },
7579
};
7680

7781
// unit test for snowflake_set_attribute and snowflake_get_attribute for all SF_ATTRIBUTE
7882
void test_set_get_all_attributes(void **unused)
7983
{
80-
SF_CONNECT *sf = (SF_CONNECT *)SF_CALLOC(1, sizeof(SF_CONNECT));
81-
memset(sf, 0, sizeof(SF_CONNECT));
84+
SF_CONNECT *sf = snowflake_init();
8285

8386
// Connection parameters that cannot be set by user
8487
sf->service_name = (char*)"test_service_name";
@@ -152,12 +155,17 @@ void test_set_get_all_attributes(void **unused)
152155
// set and get int attributes
153156
for (sf_int_attributes attr : intAttributes)
154157
{
155-
status = snowflake_set_attribute(sf, attr.type, &attr.value);
156-
if (status != SF_STATUS_SUCCESS)
158+
if ((attr.type != SF_CON_MAX_VARCHAR_SIZE) &&
159+
(attr.type != SF_CON_MAX_BINARY_SIZE) &&
160+
(attr.type != SF_CON_MAX_VARIANT_SIZE))
157161
{
158-
dump_error(&(sf->error));
162+
status = snowflake_set_attribute(sf, attr.type, &attr.value);
163+
if (status != SF_STATUS_SUCCESS)
164+
{
165+
dump_error(&(sf->error));
166+
}
167+
assert_int_equal(status, SF_STATUS_SUCCESS);
159168
}
160-
assert_int_equal(status, SF_STATUS_SUCCESS);
161169

162170
status = snowflake_get_attribute(sf, attr.type, &value);
163171
if (status != SF_STATUS_SUCCESS)

tests/test_unit_snowflake_types_to_string.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
#include <cassert>
66
#include <string>
7-
#include "utils/test_setup.h"
8-
#include "utils/TestSetup.hpp"
97
#include "memory.h"
108
#include <vector>
9+
#include "utils/test_setup.h"
10+
#include "utils/TestSetup.hpp"
1111

1212
typedef struct sf_db_types {
1313
SF_DB_TYPE sf_dbType;

0 commit comments

Comments
 (0)