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-692945: multiple statements support #727

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ set(SOURCE_FILES_CPP_WRAPPER
cpp/lib/ClientQueryContextCache.cpp
cpp/lib/ClientQueryContextCache.hpp
cpp/lib/result_set.cpp
cpp/lib/result_set_arrow.cpp
cpp/lib/result_set_json.cpp
cpp/lib/ResultSet.cpp
cpp/lib/ResultSet.hpp
cpp/lib/ResultSetArrow.cpp
Expand All @@ -246,8 +244,6 @@ set(SOURCE_FILES_CPP_WRAPPER
cpp/util/CurlDesc.cpp
cpp/util/CurlDescPool.cpp
lib/result_set.h
lib/result_set_arrow.h
lib/result_set_json.h
lib/query_context_cache.h
lib/curl_desc_pool.h
lib/authenticator.h)
Expand Down
9 changes: 6 additions & 3 deletions cpp/lib/ResultSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Snowflake
namespace Client
{

ResultSet::ResultSet() :
ResultSet::ResultSet(QueryResultFormat format) :
m_binaryOutputFormat("HEX"),
m_dateOutputFormat("YYYY-MM-DD"),
m_timeOutputFormat("HH24:MI:SS"),
Expand All @@ -28,14 +28,16 @@ ResultSet::ResultSet() :
m_currChunkIdx(0),
m_currChunkRowIdx(0),
m_currColumnIdx(0),
m_currRowIdx(0)
m_currRowIdx(0),
m_queryResultFormat(format)
{
;
}

ResultSet::ResultSet(
SF_COLUMN_DESC * metadata,
std::string tzString
std::string tzString,
QueryResultFormat format
) :
m_currChunkIdx(0),
m_currChunkRowIdx(0),
Expand All @@ -44,6 +46,7 @@ ResultSet::ResultSet(
m_totalChunkCount(0),
m_totalColumnCount(0),
m_metadata(metadata),
m_queryResultFormat(format),
m_isFirstChunk(true),
m_tzString(tzString),
m_error(SF_STATUS_SUCCESS)
Expand Down
26 changes: 15 additions & 11 deletions cpp/lib/ResultSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,13 @@
#include "cJSON.h"
#include "snowflake/basic_types.h"
#include "snowflake/client.h"
#include "result_set.h"

namespace Snowflake
{
namespace Client
{

/**
* Enumeration over valid query result formats.
*/
enum QueryResultFormat
{
ARROW,
JSON
};

/**
* The implementation of a base result set.
*
Expand All @@ -40,15 +32,15 @@ class ResultSet
/**
* Default constructor.
*/
ResultSet();
ResultSet(QueryResultFormat format);

/**
* Parameterized constructor.
*
* @param metadata The metadata of the result set.
* @param tzString The time zone.
*/
ResultSet(SF_COLUMN_DESC * metadata, std::string tzString);
ResultSet(SF_COLUMN_DESC * metadata, std::string tzString, QueryResultFormat format);

/**
* Destructor.
Expand Down Expand Up @@ -194,6 +186,13 @@ class ResultSet
*/
virtual SF_STATUS STDCALL isCellNull(size_t idx, sf_bool * out_data) = 0;

/**
* Gets the total number of rows in the current chunk being processed.
*
* @return the number of rows in the current chunk.
*/
virtual size_t getRowCountInChunk() = 0;

// Other member getters ========================================================================

SF_STATUS getError()
Expand All @@ -215,6 +214,11 @@ class ResultSet
}
}

QueryResultFormat getResultFormat()
{
return m_queryResultFormat;
}

protected:

// Protected members ===========================================================================
Expand Down
37 changes: 31 additions & 6 deletions cpp/lib/ResultSetArrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "../logger/SFLogger.hpp"
#include "ResultSetArrow.hpp"
#include "result_set_arrow.h"
#include "DataConversion.hpp"
#include "results.h"

Expand All @@ -22,20 +21,18 @@ namespace Client


ResultSetArrow::ResultSetArrow() :
Snowflake::Client::ResultSet()
Snowflake::Client::ResultSet(SF_ARROW_FORMAT)
{
m_queryResultFormat = QueryResultFormat::ARROW;
; // Do nothing
}

ResultSetArrow::ResultSetArrow(
arrow::BufferBuilder* initialChunk,
SF_COLUMN_DESC * metadata,
std::string tzString
) :
ResultSet(metadata, tzString)
ResultSet(metadata, tzString, SF_ARROW_FORMAT)
{
m_queryResultFormat = QueryResultFormat::ARROW;

this->appendChunk(initialChunk);

// Reset row indices so that they can be re-used by public API.
Expand All @@ -44,6 +41,34 @@ ResultSetArrow::ResultSetArrow(
m_currRowIdx = 0;
}

ResultSetArrow::ResultSetArrow(
cJSON * jsonRowset64,
SF_COLUMN_DESC * metadata,
std::string tzString
) :
ResultSet(metadata, tzString, SF_ARROW_FORMAT)
{
arrow::BufferBuilder* bufferBuilder = NULL;
if (jsonRowset64)
{
const char* base64RowsetStr = snowflake_cJSON_GetStringValue(jsonRowset64);
if (base64RowsetStr && strlen(base64RowsetStr) > 0)
{
// Decode Base64-encoded Arrow-format rowset of the chunk and build a buffer builder from it.
std::string decodedRowsetStr = arrow::util::base64_decode(std::string(base64RowsetStr));
bufferBuilder = new arrow::BufferBuilder();
(void)bufferBuilder->Append((void*)decodedRowsetStr.c_str(), decodedRowsetStr.length());
}
}

this->appendChunk(bufferBuilder);

// Reset row indices so that they can be re-used by public API.
m_currChunkIdx = 0;
m_currChunkRowIdx = 0;
m_currRowIdx = 0;
}

ResultSetArrow::~ResultSetArrow()
{
; // Do nothing.
Expand Down
14 changes: 14 additions & 0 deletions cpp/lib/ResultSetArrow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ class ResultSetArrow : public Snowflake::Client::ResultSet
*/
ResultSetArrow(arrow::BufferBuilder * initialChunk, SF_COLUMN_DESC * metadata, std::string tzString);


/**
* Parameterized constructor.
*
* This constructor will initialize m_records with the (partial) results
* contained in the initial chunk. It will also initialize m_metadata with
* the metadata in "metadata".
*
* @param jsonRowset64 A pointer to the rowset64 data in json result set.
* @param metadata An array of metadata objects for each column.
* @param tzString The time zone.
*/
ResultSetArrow(cJSON* jsonRowset64, SF_COLUMN_DESC* metadata, std::string tzString);

/**
* Destructor.
*/
Expand Down
7 changes: 3 additions & 4 deletions cpp/lib/ResultSetJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@ namespace Client


ResultSetJson::ResultSetJson() :
ResultSet()
ResultSet(SF_JSON_FORMAT)
{
m_queryResultFormat = QueryResultFormat::JSON;
; // Do nothing
}

ResultSetJson::ResultSetJson(
cJSON * rowset,
SF_COLUMN_DESC * metadata,
std::string tzString
) :
ResultSet(metadata, tzString)
ResultSet(metadata, tzString, SF_JSON_FORMAT)
{
m_queryResultFormat = QueryResultFormat::JSON;
m_chunk = nullptr;
appendChunk(rowset);
}
Expand Down
Loading
Loading