language-extensions/R/test/src/RExtensionExecuteTests.cpp
//----------------------------------------------------------------------------------------------
// Name: ExecuteDifferentColumnsTest
//
// Description:
//  Tests Execute with default script using an InputDataSet of different column types.
//
ExecuteDifferentColumnsTest
Description:
Tests Execute with default script using an InputDataSet of different column types.
ExecuteDifferentColumnsTest Description : Tests Execute with default script using an InputDataSet of different column types .
TEST_F(RExtensionApiTests, ExecuteDifferentColumnsTest)
	{
		InitializeSession(3,  inputSchemaColumnsNumber
			m_scriptString);
		string integerColumnName = "IntegerColumn";
		InitializeColumn(0,  columnNumber
			integerColumnName,
			SQL_C_SLONG,
			m_IntSize,
			0,               decimalDigits
			SQL_NULLABLE);
		string doubleColumnName = "DoubleColumn";
		InitializeColumn(1,  columnNumber
			doubleColumnName,
			SQL_C_DOUBLE,
			m_DoubleSize,
			0,               decimalDigits
			SQL_NO_NULLS);
		string charColumnName = "CharColumn";
		InitializeColumn(2,  columnNumber
			charColumnName,
			SQL_C_CHAR,
			m_CharSize,
			0,               decimalDigits
			SQL_NULLABLE);
		SQLULEN rowsNumber = 5;
		vector<SQLINTEGER> intColData{ 2'147'483'647, -2'147'483'647, 0, -2'147'483'648, -1 };
		vector<SQLDOUBLE> doubleColData{ -1.79e301, 1.33, 83.98, 72.45, 1.79e30 };
		vector<const char*> charCol{ "Hello", "test", "data", "RExtension", "-123" };
		vector<SQLINTEGER> strLenOrIndCol1 = { 0, 0, SQL_NULL_DATA, SQL_NULL_DATA, 0 };
		vector<SQLINTEGER> strLenOrIndCol3 =
			{ static_cast<SQLINTEGER>(strlen(charCol[0])),
			  static_cast<SQLINTEGER>(strlen(charCol[1])),
			  static_cast<SQLINTEGER>(strlen(charCol[2])),
			  static_cast<SQLINTEGER>(strlen(charCol[3])),
			  static_cast<SQLINTEGER>(strlen(charCol[4])) };
		vector<SQLINTEGER*> strLen_or_Ind{
			strLenOrIndCol1.data(),
			 The second column doubleColData is not nullable,
			 so passing a non-null strLenOrInd should be ignored.
			strLenOrIndCol1.data(),
			strLenOrIndCol3.data()};
		vector<char> charColData = GenerateContiguousData<char>(charCol, strLenOrIndCol3.data());
		vector<void *> dataSet { intColData.data(), doubleColData.data(), charColData.data()};
		testing::internal::CaptureStdout();
		SQLUSMALLINT outputschemaColumnsNumber = 0;
		SQLRETURN result = (*sm_executeFuncPtr)(
			*m_sessionId,
			m_taskId,
			rowsNumber,
			dataSet.data(),
			strLen_or_Ind.data(),
			&outputschemaColumnsNumber);
		ASSERT_EQ(result, SQL_SUCCESS);
		 Test print message was printed correctly
		string output = testing::internal::GetCapturedStdout();
		cout << output;
		ASSERT_TRUE(output.find(m_printMessage) != string::npos);
		 Test InputDataSet
		Rcpp::DataFrame inputDataSet = m_globalEnvironment[m_inputDataNameString.c_str()];
		Rcpp::IntegerVector intColumn = inputDataSet[integerColumnName.c_str()];
		CheckRVectorColumnDataEquality<SQLINTEGER, Rcpp::IntegerVector, SQL_C_SLONG>(
			rowsNumber,
			intColumn,
			dataSet[0],
			strLen_or_Ind[0]);
		Rcpp::NumericVector numericColumn = inputDataSet[doubleColumnName.c_str()];
		CheckRVectorColumnDataEquality<SQLDOUBLE, Rcpp::NumericVector, SQL_C_DOUBLE>(
			rowsNumber,
			numericColumn,
			dataSet[1],
			strLen_or_Ind[1],
			SQL_NO_NULLS);
		Rcpp::CharacterVector charColumn = inputDataSet[charColumnName.c_str()];
		CheckRCharacterVectorColumnDataEquality<char>(
			rowsNumber,
			charColumn,
			dataSet[2],
			strLen_or_Ind[2]);
		 Test OutputDataSet
		Rcpp::DataFrame outputDataSet = m_globalEnvironment[m_outputDataNameString.c_str()];
		EXPECT_EQ(outputschemaColumnsNumber, outputDataSet.size());
		ASSERT_EQ(outputDataSet.size(), inputDataSet.size());
		CheckRVectorEquality<Rcpp::IntegerVector>(
			outputDataSet[0],
			inputDataSet[0]);
		CheckRVectorEquality<Rcpp::NumericVector>(
			outputDataSet[1],
			inputDataSet[1]);
		CheckRVectorEquality<Rcpp::CharacterVector>(
			outputDataSet[2],
			inputDataSet[2]);
	}
TEST_F ( RExtensionApiTests , ExecuteDifferentColumnsTest ) { InitializeSession ( 3 , m_scriptString ) ; string integerColumnName = " " ; InitializeColumn ( 0 , integerColumnName , SQL_C_SLONG , m_IntSize , 0 , SQL_NULLABLE ) ; string doubleColumnName = " " ; InitializeColumn ( 1 , doubleColumnName , SQL_C_DOUBLE , m_DoubleSize , 0 , SQL_NO_NULLS ) ; string charColumnName = " " ; InitializeColumn ( 2 , charColumnName , SQL_C_CHAR , m_CharSize , 0 , SQL_NULLABLE ) ; SQLULEN rowsNumber = 5 ; vector < SQLINTEGER > intColData { 2'147'483'647 , -2'147'483'647 , 0 , -2'147'483'648 , -1 } ; vector < SQLDOUBLE > doubleColData { -1.79e301 , 1.33 , 83.98 , 72.45 , 1.79e30 } ; vector < const char * > charCol { " " , " " , " " , " " , " " } ; vector < SQLINTEGER > strLenOrIndCol1 = { 0 , 0 , SQL_NULL_DATA , SQL_NULL_DATA , 0 } ; vector < SQLINTEGER > strLenOrIndCol3 = { static_cast < SQLINTEGER > ( strlen ( charCol [ 0 ] ) ) , static_cast < SQLINTEGER > ( strlen ( charCol [ 1 ] ) ) , static_cast < SQLINTEGER > ( strlen ( charCol [ 2 ] ) ) , static_cast < SQLINTEGER > ( strlen ( charCol [ 3 ] ) ) , static_cast < SQLINTEGER > ( strlen ( charCol [ 4 ] ) ) } ; vector < SQLINTEGER * > strLen_or_Ind { strLenOrIndCol1 . data ( ) , strLenOrIndCol1 . data ( ) , strLenOrIndCol3 . data ( ) } ; vector < char > charColData = GenerateContiguousData < char > ( charCol , strLenOrIndCol3 . data ( ) ) ; vector < void * > dataSet { intColData . data ( ) , doubleColData . data ( ) , charColData . data ( ) } ; testing :: internal :: CaptureStdout ( ) ; SQLUSMALLINT outputschemaColumnsNumber = 0 ; SQLRETURN result = ( * sm_executeFuncPtr ) ( * m_sessionId , m_taskId , rowsNumber , dataSet . data ( ) , strLen_or_Ind . data ( ) , & outputschemaColumnsNumber ) ; ASSERT_EQ ( result , SQL_SUCCESS ) ; string output = testing :: internal :: GetCapturedStdout ( ) ; cout << output ; ASSERT_TRUE ( output . find ( m_printMessage ) != string :: npos ) ; Rcpp :: DataFrame inputDataSet = m_globalEnvironment [ m_inputDataNameString . c_str ( ) ] ; Rcpp :: IntegerVector intColumn = inputDataSet [ integerColumnName . c_str ( ) ] ; CheckRVectorColumnDataEquality < SQLINTEGER , Rcpp :: IntegerVector , SQL_C_SLONG > ( rowsNumber , intColumn , dataSet [ 0 ] , strLen_or_Ind [ 0 ] ) ; Rcpp :: NumericVector numericColumn = inputDataSet [ doubleColumnName . c_str ( ) ] ; CheckRVectorColumnDataEquality < SQLDOUBLE , Rcpp :: NumericVector , SQL_C_DOUBLE > ( rowsNumber , numericColumn , dataSet [ 1 ] , strLen_or_Ind [ 1 ] , SQL_NO_NULLS ) ; Rcpp :: CharacterVector charColumn = inputDataSet [ charColumnName . c_str ( ) ] ; CheckRCharacterVectorColumnDataEquality < char > ( rowsNumber , charColumn , dataSet [ 2 ] , strLen_or_Ind [ 2 ] ) ; Rcpp :: DataFrame outputDataSet = m_globalEnvironment [ m_outputDataNameString . c_str ( ) ] ; EXPECT_EQ ( outputschemaColumnsNumber , outputDataSet . size ( ) ) ; ASSERT_EQ ( outputDataSet . size ( ) , inputDataSet . size ( ) ) ; CheckRVectorEquality < Rcpp :: IntegerVector > ( outputDataSet [ 0 ] , inputDataSet [ 0 ] ) ; CheckRVectorEquality < Rcpp :: NumericVector > ( outputDataSet [ 1 ] , inputDataSet [ 1 ] ) ; CheckRVectorEquality < Rcpp :: CharacterVector > ( outputDataSet [ 2 ] , inputDataSet [ 2 ] ) ; }
Name: ExecuteDifferentColumnsTest
Description:
Tests Execute with default script using an InputDataSet of different column types.
Name : ExecuteDifferentColumnsTest Description : Tests Execute with default script using an InputDataSet of different column types .
// Initialize with a default Session that prints Hello RExtension // and assigns InputDataSet to OutputDataSet // // inputSchemaColumnsNumber // columnNumber // decimalDigits // columnNumber // decimalDigits // columnNumber // decimalDigits // The second column doubleColData is not nullable, // so passing a non-null strLenOrInd should be ignored. // // Test print message was printed correctly // // Test InputDataSet // // Test OutputDataSet //