language-extensions/python/src/PythonDataSet.cpp
//-------------------------------------------------------------------------------------------------
// Name: PythonOutputDataSet::RetrieveRawColumnFromDataFrame
//
// Description:
//  Gets raw column information from the underlying DataFrame,
//  adds data to m_data and nullmap to m_columnNullMap.
//

:RetrieveRawColumnFromDataFrame
Description:
Gets raw column information from the underlying DataFrame,
adds data to m_data and nullmap to m_columnNullMap.
: RetrieveRawColumnFromDataFrame Description : Gets raw column information from the underlying DataFrame adds data to m_data and nullmap to m_columnNullMap .
void PythonOutputDataSet::RetrieveRawColumnFromDataFrame(
	string      columnName,
	SQLULEN     &columnSize,
	SQLSMALLINT &decimalDigits,
	SQLSMALLINT &nullable)
{
	LOG("PythonOutputDataSet::RetrieveRawColumnFromDataFrame");
	vector<char> columnData;
	SQLINTEGER *strLenOrNullMap = nullptr;
	if (m_rowsNumber > 0)
	{
		strLenOrNullMap = new SQLINTEGER[m_rowsNumber];
	}
	decimalDigits = 0;
	nullable = SQL_NO_NULLS;
	np::ndarray column = ExtractArrayFromDataFrame(columnName);
	SQLINTEGER maxLen = sizeof(char);
	int fullSize = 0;
	for (SQLULEN row = 0; row < m_rowsNumber; ++row)
	{
		bp::object pyObj = column[row];
		if (!pyObj.is_none())
		{
			PyObject *baseObj = pyObj.ptr();
			int size = PyBytes_Size(baseObj);
			char *bytes = static_cast<char *>(
				static_cast<void *>(PyBytes_AsString(baseObj)));
			fullSize += size;
			strLenOrNullMap[row] = size;
			columnData.insert(columnData.end(), bytes, bytes+size);
		}
		else
		{
			strLenOrNullMap[row] = SQL_NULL_DATA;
			nullable = SQL_NULLABLE;
		}
		if (maxLen < strLenOrNullMap[row])
		{
			maxLen = strLenOrNullMap[row];
		}
	}
	unique_ptr<char[]> dataPtr(new char[fullSize]);
	memcpy(dataPtr.get(), columnData.data(), fullSize);
	columnSize = maxLen;
	if (m_rowsNumber > 0)
	{
		m_data.push_back(static_cast<SQLPOINTER>(dataPtr.release()));
	}
	else
	{
		m_data.push_back(nullptr);
	}
	m_columnNullMap.push_back(strLenOrNullMap);
}
void PythonOutputDataSet :: RetrieveRawColumnFromDataFrame ( string columnName , SQLULEN & columnSize , SQLSMALLINT & decimalDigits , SQLSMALLINT & nullable ) { LOG ( " " ) ; vector < char > columnData ; SQLINTEGER * strLenOrNullMap = nullptr ; if ( m_rowsNumber > 0 ) { strLenOrNullMap = new SQLINTEGER [ m_rowsNumber ] ; } decimalDigits = 0 ; nullable = SQL_NO_NULLS ; np :: ndarray column = ExtractArrayFromDataFrame ( columnName ) ; SQLINTEGER maxLen = sizeof ( char ) ; int fullSize = 0 ; for ( SQLULEN row = 0 ; row < m_rowsNumber ; ++ row ) { bp :: object pyObj = column [ row ] ; if ( ! pyObj . is_none ( ) ) { PyObject * baseObj = pyObj . ptr ( ) ; int size = PyBytes_Size ( baseObj ) ; char * bytes = static_cast < char * > ( static_cast < void * > ( PyBytes_AsString ( baseObj ) ) ) ; fullSize += size ; strLenOrNullMap [ row ] = size ; columnData . insert ( columnData . end ( ) , bytes , bytes + size ) ; } else { strLenOrNullMap [ row ] = SQL_NULL_DATA ; nullable = SQL_NULLABLE ; } if ( maxLen < strLenOrNullMap [ row ] ) { maxLen = strLenOrNullMap [ row ] ; } } unique_ptr < char [ ] > dataPtr ( new char [ fullSize ] ) ; memcpy ( dataPtr . get ( ) , columnData . data ( ) , fullSize ) ; columnSize = maxLen ; if ( m_rowsNumber > 0 ) { m_data . push_back ( static_cast < SQLPOINTER > ( dataPtr . release ( ) ) ) ; } else { m_data . push_back ( nullptr ) ; } m_columnNullMap . push_back ( strLenOrNullMap ) ; }
Name: PythonOutputDataSet::RetrieveRawColumnFromDataFrame
Description:
Gets raw column information from the underlying DataFrame,
adds data to m_data and nullmap to m_columnNullMap.
Name : PythonOutputDataSet :: RetrieveRawColumnFromDataFrame Description : Gets raw column information from the underlying DataFrame adds data to m_data and nullmap to m_columnNullMap .
// Store the data in a vector (columnData) while we calculate the total size we need 
 // for the contiguous char data.
 //
 // Extract the size and bytes of the pyObj
 //
 // Store the maximum length to find the widest the column needs to be
 //
 // Create a single block of memory that will hold all the data contiguously.
 //
 // Copy our data from the vector of strings to the single chunk of memory.
 //
 // Add the memory block to the m_data and give the memory handling job to m_data.
 //
