1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

Reformat all code to coding standard

This commit is contained in:
Andrew Hutchings
2017-10-26 17:18:17 +01:00
parent 4985f3456e
commit 01446d1e22
1296 changed files with 403852 additions and 353747 deletions

View File

@ -30,43 +30,48 @@ using namespace boost;
using namespace WriteEngine;
class XmlTest : public CppUnit::TestFixture {
class XmlTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( XmlTest );
CPPUNIT_TEST_SUITE( XmlTest );
CPPUNIT_TEST( test1 );
CPPUNIT_TEST( test1 );
// XML basic testing
CPPUNIT_TEST( testBasicXMLRead );
/*CPPUNIT_TEST( testAddTreeNode );
CPPUNIT_TEST( testBasicXMLRead );
/*CPPUNIT_TEST( testAddTreeNode );
// Index tree testing
CPPUNIT_TEST( testTreeGetTestbitValue );
*/
CPPUNIT_TEST_SUITE_END();
// Index tree testing
CPPUNIT_TEST( testTreeGetTestbitValue );
*/
CPPUNIT_TEST_SUITE_END();
private:
public:
void setUp() {
}
void setUp()
{
}
void tearDown() {
}
void tearDown()
{
}
void test1() {
}
void testBasicXMLRead() {
int rc;
XMLJob myJob;
void test1()
{
}
void testBasicXMLRead()
{
int rc;
XMLJob myJob;
rc = myJob.loadJobXmlFile( "../test/bulk/job/Job_127.xml" );
CPPUNIT_ASSERT( rc == NO_ERROR );
myJob.printJobInfo();
}
rc = myJob.loadJobXmlFile( "../test/bulk/job/Job_127.xml" );
CPPUNIT_ASSERT( rc == NO_ERROR );
myJob.printJobInfo();
}
};
@ -75,13 +80,13 @@ CPPUNIT_TEST_SUITE_REGISTRATION( XmlTest );
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
int main( int argc, char **argv)
int main( int argc, char** argv)
{
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() );
bool wasSuccessful = runner.run( "", false );
return (wasSuccessful ? 0 : 1);
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() );
bool wasSuccessful = runner.run( "", false );
return (wasSuccessful ? 0 : 1);
}

View File

@ -28,37 +28,37 @@
namespace
{
const std::string JOBDIR("job");
const std::string JOBDIR("job");
}
namespace WriteEngine
{
/* static */ const std::string XMLGenData::DELIMITER ("-d");
/* static */ const std::string XMLGenData::DESCRIPTION ("-s");
#ifdef _MSC_VER
__declspec(dllexport)
#endif
/* static */ const std::string XMLGenData::ENCLOSED_BY_CHAR ("-E");
#ifdef _MSC_VER
__declspec(dllexport)
#endif
/* static */ const std::string XMLGenData::ESCAPE_CHAR ("-C");
#ifdef _MSC_VER
__declspec(dllexport)
#endif
/* static */ const std::string XMLGenData::JOBID ("-j");
/* static */ const std::string XMLGenData::MAXERROR ("-e");
/* static */ const std::string XMLGenData::NAME ("-n");
/* static */ const std::string XMLGenData::PATH ("-p");
#ifdef _MSC_VER
__declspec(dllexport)
#endif
/* static */ const std::string XMLGenData::RPT_DEBUG ("-b");
/* static */ const std::string XMLGenData::USER ("-u");
/* static */ const std::string XMLGenData::NO_OF_READ_BUFFER ("-r");
/* static */ const std::string XMLGenData::READ_BUFFER_CAPACITY("-c");
/* static */ const std::string XMLGenData::WRITE_BUFFER_SIZE ("-w");
/* static */ const std::string XMLGenData::EXT ("-x");
/* static */ const std::string XMLGenData::DELIMITER ("-d");
/* static */ const std::string XMLGenData::DESCRIPTION ("-s");
#ifdef _MSC_VER
__declspec(dllexport)
#endif
/* static */ const std::string XMLGenData::ENCLOSED_BY_CHAR ("-E");
#ifdef _MSC_VER
__declspec(dllexport)
#endif
/* static */ const std::string XMLGenData::ESCAPE_CHAR ("-C");
#ifdef _MSC_VER
__declspec(dllexport)
#endif
/* static */ const std::string XMLGenData::JOBID ("-j");
/* static */ const std::string XMLGenData::MAXERROR ("-e");
/* static */ const std::string XMLGenData::NAME ("-n");
/* static */ const std::string XMLGenData::PATH ("-p");
#ifdef _MSC_VER
__declspec(dllexport)
#endif
/* static */ const std::string XMLGenData::RPT_DEBUG ("-b");
/* static */ const std::string XMLGenData::USER ("-u");
/* static */ const std::string XMLGenData::NO_OF_READ_BUFFER ("-r");
/* static */ const std::string XMLGenData::READ_BUFFER_CAPACITY("-c");
/* static */ const std::string XMLGenData::WRITE_BUFFER_SIZE ("-w");
/* static */ const std::string XMLGenData::EXT ("-x");
//------------------------------------------------------------------------------
// XMLGenData constructor
@ -66,31 +66,31 @@ namespace WriteEngine
//------------------------------------------------------------------------------
XMLGenData::XMLGenData( )
{
fParms.insert(ParmList::value_type(DELIMITER,std::string("|")));
fParms.insert(ParmList::value_type(DESCRIPTION,std::string()));
fParms.insert(ParmList::value_type(ENCLOSED_BY_CHAR,std::string("")));
fParms.insert(ParmList::value_type(ESCAPE_CHAR,std::string("\\")));
fParms.insert(ParmList::value_type(JOBID,std::string("299")));
fParms.insert(ParmList::value_type(MAXERROR,std::string("10")));
fParms.insert(ParmList::value_type(NAME,std::string()));
fParms.insert(ParmList::value_type(DELIMITER, std::string("|")));
fParms.insert(ParmList::value_type(DESCRIPTION, std::string()));
fParms.insert(ParmList::value_type(ENCLOSED_BY_CHAR, std::string("")));
fParms.insert(ParmList::value_type(ESCAPE_CHAR, std::string("\\")));
fParms.insert(ParmList::value_type(JOBID, std::string("299")));
fParms.insert(ParmList::value_type(MAXERROR, std::string("10")));
fParms.insert(ParmList::value_type(NAME, std::string()));
#ifdef _MSC_VER
std::string br;
br = Config::getBulkRoot();
boost::filesystem::path p(br);
std::string br;
br = Config::getBulkRoot();
boost::filesystem::path p(br);
#else
boost::filesystem::path p( std::string(Config::getBulkRoot()) );
#endif
p /= JOBDIR;
fParms.insert(ParmList::value_type(PATH, p.string()));
fParms.insert(ParmList::value_type(RPT_DEBUG,std::string("0")));
fParms.insert(ParmList::value_type(USER,std::string()));
fParms.insert(ParmList::value_type(NO_OF_READ_BUFFER,std::string("5")));
fParms.insert(ParmList::value_type(RPT_DEBUG, std::string("0")));
fParms.insert(ParmList::value_type(USER, std::string()));
fParms.insert(ParmList::value_type(NO_OF_READ_BUFFER, std::string("5")));
fParms.insert(ParmList::value_type(READ_BUFFER_CAPACITY,
std::string("1048576")));
std::string("1048576")));
fParms.insert(ParmList::value_type(WRITE_BUFFER_SIZE,
std::string("10485760")));
fParms.insert(ParmList::value_type(EXT,std::string("tbl")));
std::string("10485760")));
fParms.insert(ParmList::value_type(EXT, std::string("tbl")));
}
//------------------------------------------------------------------------------
@ -107,6 +107,7 @@ XMLGenData::~XMLGenData( )
std::string XMLGenData::getParm(const std::string& key) const
{
ParmList::const_iterator p = fParms.find(key);
if (fParms.end() != p)
return p->second;
else

View File

@ -46,7 +46,7 @@ namespace WriteEngine
*/
class XMLGenData
{
public:
public:
typedef std::vector<execplan::CalpontSystemCatalog::TableName> TableList;
typedef std::map<std::string, std::string> ParmList;
typedef std::vector<std::string> LoadNames;
@ -54,23 +54,23 @@ class XMLGenData
// Valid parms that can be stored and retrieved from XMLGenData
EXPORT const static std::string DELIMITER;
EXPORT const static std::string DESCRIPTION;
#if defined(_MSC_VER) && !defined(WRITEENGINE_DLLEXPORT)
__declspec(dllimport)
#if defined(_MSC_VER) && !defined(WRITEENGINE_DLLEXPORT)
__declspec(dllimport)
#endif
EXPORT const static std::string ENCLOSED_BY_CHAR;
#if defined(_MSC_VER) && !defined(WRITEENGINE_DLLEXPORT)
__declspec(dllimport)
#if defined(_MSC_VER) && !defined(WRITEENGINE_DLLEXPORT)
__declspec(dllimport)
#endif
EXPORT const static std::string ESCAPE_CHAR;
#if defined(_MSC_VER) && !defined(WRITEENGINE_DLLEXPORT)
__declspec(dllimport)
#if defined(_MSC_VER) && !defined(WRITEENGINE_DLLEXPORT)
__declspec(dllimport)
#endif
EXPORT const static std::string JOBID;
EXPORT const static std::string MAXERROR;
EXPORT const static std::string NAME;
EXPORT const static std::string PATH;
#if defined(_MSC_VER) && !defined(WRITEENGINE_DLLEXPORT)
__declspec(dllimport)
#if defined(_MSC_VER) && !defined(WRITEENGINE_DLLEXPORT)
__declspec(dllimport)
#endif
EXPORT const static std::string RPT_DEBUG;
EXPORT const static std::string USER;
@ -92,17 +92,26 @@ class XMLGenData
EXPORT virtual void print(std::ostream& os) const;
EXPORT std::string getParm(const std::string& key) const;
const TableList& getTables() const { return fTables; }
const std::string& getSchema() const { return fSchema; }
const LoadNames& getLoadNames() const { return fLoadNames; }
const TableList& getTables() const
{
return fTables;
}
const std::string& getSchema() const
{
return fSchema;
}
const LoadNames& getLoadNames() const
{
return fLoadNames;
}
protected:
protected:
TableList fTables;
ParmList fParms;
std::string fSchema;
LoadNames fLoadNames;
private:
private:
XMLGenData(const XMLGenData&); // disable default copy ctor
XMLGenData& operator=(const XMLGenData&); // disable default assignment
};

View File

@ -36,11 +36,11 @@ using namespace execplan;
namespace
{
const char* DICT_TYPE("D");
const char* ENCODING("UTF-8");
const char* JOBNAME("Job_");
const char* LOGNAME("Jobxml_");
const std::string LOGDIR("/log/");
const char* DICT_TYPE("D");
const char* ENCODING("UTF-8");
const char* JOBNAME("Job_");
const char* LOGNAME("Jobxml_");
const std::string LOGDIR("/log/");
}
namespace WriteEngine
@ -61,10 +61,11 @@ XMLGenProc::XMLGenProc(XMLGenData* mgr, bool bUseXmlLogFile, bool bSysCatRpt) :
fUseXmlLogFile(bUseXmlLogFile)
{
std::string logFile(Config::getBulkRoot() + std::string(LOGDIR) + LOGNAME +
fInputMgr->getParm(XMLGenData::JOBID) + ".log" );
fInputMgr->getParm(XMLGenData::JOBID) + ".log" );
std::string errFile(Config::getBulkRoot() + std::string(LOGDIR) + LOGNAME +
fInputMgr->getParm(XMLGenData::JOBID) + ".err" );
fInputMgr->getParm(XMLGenData::JOBID) + ".err" );
fErrorString.append(errFile + "\n");
if (fUseXmlLogFile)
{
fLog.setLogFileName( logFile.c_str(), errFile.c_str() );
@ -90,52 +91,57 @@ XMLGenProc::~XMLGenProc()
void XMLGenProc::startXMLFile( )
{
fWriter = xmlNewTextWriterDoc(&fDoc, 0);
if (fWriter == NULL) {
if (fWriter == NULL)
{
throw std::runtime_error("Error creating the xml fWriter: "
"bad return from xmlNewTextWriter");
"bad return from xmlNewTextWriter");
}
/* Start the fDocument with the xml default for the version,
* encoding UTF-8 and the default for the standalone
* declaration. */
int rc = xmlTextWriterStartDocument(fWriter, NULL, ENCODING, NULL);
if (rc < 0) {
if (rc < 0)
{
throw std::runtime_error("Error at xmlTextWriterStartfDocument: "
"bad return from xmlTextWriterStartDocument");
"bad return from xmlTextWriterStartDocument");
}
if (!fSysCatRpt) // skip non-syscat tags if we are writing a syscat dump
{
xmlTextWriterStartElement(fWriter, BAD_CAST xmlTagTable[TAG_BULK_JOB]);
xmlTextWriterWriteFormatElement(fWriter, BAD_CAST xmlTagTable[TAG_ID],
"%d", atoi(fInputMgr->getParm(XMLGenData::JOBID).c_str()));
"%d", atoi(fInputMgr->getParm(XMLGenData::JOBID).c_str()));
xmlTextWriterWriteElement(fWriter, BAD_CAST xmlTagTable[TAG_NAME],
BAD_CAST fInputMgr->getParm(XMLGenData::NAME).c_str() );
BAD_CAST fInputMgr->getParm(XMLGenData::NAME).c_str() );
xmlTextWriterWriteElement(fWriter, BAD_CAST xmlTagTable[TAG_DESC],
BAD_CAST fInputMgr->getParm(XMLGenData::DESCRIPTION).c_str() );
BAD_CAST fInputMgr->getParm(XMLGenData::DESCRIPTION).c_str() );
std::string now(boost::posix_time::to_iso_string(
boost::posix_time::second_clock::local_time()));
boost::posix_time::second_clock::local_time()));
xmlTextWriterWriteElement(fWriter,
BAD_CAST xmlTagTable[TAG_CREATE_DATE],
BAD_CAST now.substr(0, 8).c_str() );
BAD_CAST xmlTagTable[TAG_CREATE_DATE],
BAD_CAST now.substr(0, 8).c_str() );
xmlTextWriterWriteElement(fWriter,
BAD_CAST xmlTagTable[TAG_CREATE_TIME],
BAD_CAST now.substr(9, 4).c_str() );
BAD_CAST xmlTagTable[TAG_CREATE_TIME],
BAD_CAST now.substr(9, 4).c_str() );
xmlTextWriterWriteElement(fWriter, BAD_CAST xmlTagTable[TAG_USER],
BAD_CAST fInputMgr->getParm(XMLGenData::USER).c_str() );
BAD_CAST fInputMgr->getParm(XMLGenData::USER).c_str() );
xmlTextWriterWriteElement(fWriter, BAD_CAST xmlTagTable[TAG_DELIMITER],
BAD_CAST fInputMgr->getParm(XMLGenData::DELIMITER).c_str() );
BAD_CAST fInputMgr->getParm(XMLGenData::DELIMITER).c_str() );
// Only include enclosedBy and escape chars if enclosedBy was specified
std::string enclosedByChar = fInputMgr->getParm(
XMLGenData::ENCLOSED_BY_CHAR);
XMLGenData::ENCLOSED_BY_CHAR);
if (enclosedByChar.length() > 0)
{
xmlTextWriterWriteElement(fWriter,
BAD_CAST xmlTagTable[TAG_ENCLOSED_BY_CHAR],
BAD_CAST fInputMgr->getParm(
XMLGenData::ENCLOSED_BY_CHAR).c_str() );
BAD_CAST xmlTagTable[TAG_ENCLOSED_BY_CHAR],
BAD_CAST fInputMgr->getParm(
XMLGenData::ENCLOSED_BY_CHAR).c_str() );
}
// Include escape character regardless of whether the "enclosed by"
@ -143,28 +149,28 @@ void XMLGenProc::startXMLFile( )
// to override the default NULL escape sequence '\N', to be something
// else like '#N'.
xmlTextWriterWriteElement(fWriter,
BAD_CAST xmlTagTable[TAG_ESCAPE_CHAR],
BAD_CAST fInputMgr->getParm(XMLGenData::ESCAPE_CHAR).c_str() );
BAD_CAST xmlTagTable[TAG_ESCAPE_CHAR],
BAD_CAST fInputMgr->getParm(XMLGenData::ESCAPE_CHAR).c_str() );
// Added new tags for configurable parameters
xmlTextWriterStartElement(fWriter,
BAD_CAST xmlTagTable[TAG_READ_BUFFERS]);
BAD_CAST xmlTagTable[TAG_READ_BUFFERS]);
xmlTextWriterWriteFormatAttribute(fWriter,
BAD_CAST xmlTagTable[TAG_NO_OF_READ_BUFFERS], "%d",
atoi(fInputMgr->getParm(XMLGenData::NO_OF_READ_BUFFER).c_str()));
BAD_CAST xmlTagTable[TAG_NO_OF_READ_BUFFERS], "%d",
atoi(fInputMgr->getParm(XMLGenData::NO_OF_READ_BUFFER).c_str()));
xmlTextWriterWriteFormatAttribute(fWriter,
BAD_CAST xmlTagTable[TAG_READ_BUFFER_SIZE], "%d",
atoi(fInputMgr->getParm(XMLGenData::READ_BUFFER_CAPACITY).c_str()));
BAD_CAST xmlTagTable[TAG_READ_BUFFER_SIZE], "%d",
atoi(fInputMgr->getParm(XMLGenData::READ_BUFFER_CAPACITY).c_str()));
xmlTextWriterEndElement(fWriter);
xmlTextWriterWriteFormatElement(fWriter,
BAD_CAST xmlTagTable[TAG_WRITE_BUFFER_SIZE], "%d",
atoi( fInputMgr->getParm(XMLGenData::WRITE_BUFFER_SIZE).c_str()));
BAD_CAST xmlTagTable[TAG_WRITE_BUFFER_SIZE], "%d",
atoi( fInputMgr->getParm(XMLGenData::WRITE_BUFFER_SIZE).c_str()));
// End of additions
}
xmlTextWriterStartElement(fWriter, BAD_CAST xmlTagTable[TAG_SCHEMA]);
xmlTextWriterWriteAttribute(fWriter, BAD_CAST xmlTagTable[TAG_NAME],
BAD_CAST fInputMgr->getSchema().c_str() );
BAD_CAST fInputMgr->getSchema().c_str() );
}
//------------------------------------------------------------------------------
@ -178,7 +184,7 @@ void XMLGenProc::makeTableData(const CalpontSystemCatalog::TableName& table)
xmlTextWriterStartElement(fWriter, BAD_CAST xmlTagTable[TAG_TABLE]);
std::string tmp(table.schema + "." + table.table);
xmlTextWriterWriteAttribute(fWriter,
BAD_CAST xmlTagTable[TAG_TBL_NAME], BAD_CAST tmp.c_str() );
BAD_CAST xmlTagTable[TAG_TBL_NAME], BAD_CAST tmp.c_str() );
if (fSysCatRpt) // Write full schema information for syscat rpt
{
@ -186,11 +192,11 @@ void XMLGenProc::makeTableData(const CalpontSystemCatalog::TableName& table)
{
boost::shared_ptr<CalpontSystemCatalog> cat =
CalpontSystemCatalog::makeCalpontSystemCatalog(
BULK_SYSCAT_SESSION_ID);
BULK_SYSCAT_SESSION_ID);
cat->identity(CalpontSystemCatalog::EC);
xmlTextWriterWriteFormatAttribute(fWriter,
BAD_CAST xmlTagTable[TAG_TBL_OID], "%d",
cat->tableRID(table).objnum);
BAD_CAST xmlTagTable[TAG_TBL_OID], "%d",
cat->tableRID(table).objnum);
}
catch (std::exception& ex)
{
@ -211,20 +217,22 @@ void XMLGenProc::makeTableData(const CalpontSystemCatalog::TableName& table)
if (!fSysCatRpt) // skip non-syscat tags if we are writing a syscat dump
{
const XMLGenData::LoadNames& loadNames = fInputMgr->getLoadNames();
if ( loadNames.size() > kount )
{
tmp = loadNames[kount];
}
else
else
{
tmp = (table.table + "." + fInputMgr->getParm(
XMLGenData::EXT).c_str());
XMLGenData::EXT).c_str());
}
xmlTextWriterWriteAttribute(fWriter,
BAD_CAST xmlTagTable[TAG_LOAD_NAME], BAD_CAST tmp.c_str() );
BAD_CAST xmlTagTable[TAG_LOAD_NAME], BAD_CAST tmp.c_str() );
xmlTextWriterWriteFormatAttribute(fWriter,
BAD_CAST xmlTagTable[TAG_MAX_ERR_ROW], "%d",
atoi( fInputMgr->getParm(XMLGenData::MAXERROR).c_str()) );
BAD_CAST xmlTagTable[TAG_MAX_ERR_ROW], "%d",
atoi( fInputMgr->getParm(XMLGenData::MAXERROR).c_str()) );
}
kount++;
@ -234,25 +242,27 @@ void XMLGenProc::makeTableData(const CalpontSystemCatalog::TableName& table)
// sortColumnsByPosition
// Sort list of columns by column position.
//------------------------------------------------------------------------------
void XMLGenProc::sortColumnsByPosition(SysCatColumnList &columns)
void XMLGenProc::sortColumnsByPosition(SysCatColumnList& columns)
{
std::map<int,SysCatColumn> tempCols;
std::map<int, SysCatColumn> tempCols;
SysCatColumnList::const_iterator cend = columns.end();
for (SysCatColumnList::const_iterator col = columns.begin();
col != cend; ++col)
col != cend; ++col)
{
tempCols[col->colType.colPosition] = *col ;
}
columns.clear();
std::map<int,SysCatColumn>::iterator pos;
for (pos = tempCols.begin(); pos != tempCols.end(); ++pos)
std::map<int, SysCatColumn>::iterator pos;
for (pos = tempCols.begin(); pos != tempCols.end(); ++pos)
{
columns.push_back(pos->second);
}
tempCols.clear();
}
@ -263,8 +273,9 @@ void XMLGenProc::sortColumnsByPosition(SysCatColumnList &columns)
bool XMLGenProc::makeColumnData(const CalpontSystemCatalog::TableName& table)
{
SysCatColumnList columns;
getColumnsForTable(table.schema,table.table, columns);
getColumnsForTable(table.schema, table.table, columns);
sortColumnsByPosition(columns);
if (columns.empty())
{
if (fUseXmlLogFile)
@ -272,91 +283,97 @@ bool XMLGenProc::makeColumnData(const CalpontSystemCatalog::TableName& table)
fLog.logMsg("No columns for " + table.table +
", or table does not exist", MSGLVL_ERROR );
}
return false;
}
SysCatColumnList::const_iterator cend = columns.end();
for (SysCatColumnList::const_iterator col = columns.begin();
col != cend; ++col)
col != cend; ++col)
{
xmlTextWriterStartElement(fWriter, BAD_CAST xmlTagTable[TAG_COLUMN]);
xmlTextWriterWriteAttribute(fWriter,
BAD_CAST xmlTagTable[TAG_COL_NAME],
BAD_CAST col->tableColName.column.c_str());
BAD_CAST xmlTagTable[TAG_COL_NAME],
BAD_CAST col->tableColName.column.c_str());
if (fSysCatRpt) // Write full schema information for syscat rpt
{
xmlTextWriterWriteFormatAttribute(fWriter,
BAD_CAST xmlTagTable[TAG_COL_OID], "%d", col->oid);
BAD_CAST xmlTagTable[TAG_COL_OID], "%d", col->oid);
xmlTextWriterWriteAttribute(fWriter,
BAD_CAST xmlTagTable[TAG_DATA_TYPE],
BAD_CAST ColDataTypeStr[
col->colType.colDataType]);
BAD_CAST xmlTagTable[TAG_DATA_TYPE],
BAD_CAST ColDataTypeStr[
col->colType.colDataType]);
if (col->colType.compressionType !=
CalpontSystemCatalog::NO_COMPRESSION)
CalpontSystemCatalog::NO_COMPRESSION)
xmlTextWriterWriteFormatAttribute(fWriter,
BAD_CAST xmlTagTable[TAG_COMPRESS_TYPE], "%d",
col->colType.compressionType);
BAD_CAST xmlTagTable[TAG_COMPRESS_TYPE], "%d",
col->colType.compressionType);
// Old logic went by scale > 0; New logic checks for "decimal" type
if ( (0 < col->colType.scale ) ||
(col->colType.colDataType == CalpontSystemCatalog::DECIMAL) ||
(col->colType.colDataType == CalpontSystemCatalog::UDECIMAL) )
(col->colType.colDataType == CalpontSystemCatalog::DECIMAL) ||
(col->colType.colDataType == CalpontSystemCatalog::UDECIMAL) )
{
xmlTextWriterWriteFormatAttribute(fWriter,
BAD_CAST xmlTagTable[TAG_PRECISION], "%d",
col->colType.precision);
BAD_CAST xmlTagTable[TAG_PRECISION], "%d",
col->colType.precision);
xmlTextWriterWriteFormatAttribute(fWriter,
BAD_CAST xmlTagTable[TAG_SCALE], "%d", col->colType.scale);
BAD_CAST xmlTagTable[TAG_SCALE], "%d", col->colType.scale);
}
xmlTextWriterWriteFormatAttribute(fWriter,
BAD_CAST xmlTagTable[TAG_WIDTH], "%d", col->colType.colWidth);
BAD_CAST xmlTagTable[TAG_WIDTH], "%d", col->colType.colWidth);
if (col->colType.autoincrement)
{
int autoInc = 1;
xmlTextWriterWriteFormatAttribute(fWriter,
BAD_CAST xmlTagTable[TAG_AUTOINCREMENT_FLAG], "%d",autoInc);
BAD_CAST xmlTagTable[TAG_AUTOINCREMENT_FLAG], "%d", autoInc);
}
//need dictionary and decimal stuff
if (col->colType.ddn.dictOID > 0)
{
xmlTextWriterWriteAttribute(fWriter,
BAD_CAST xmlTagTable[TAG_COL_TYPE], BAD_CAST DICT_TYPE );
BAD_CAST xmlTagTable[TAG_COL_TYPE], BAD_CAST DICT_TYPE );
xmlTextWriterWriteFormatAttribute(fWriter,
BAD_CAST xmlTagTable[TAG_DVAL_OID], "%d",
col->colType.ddn.dictOID );
BAD_CAST xmlTagTable[TAG_DVAL_OID], "%d",
col->colType.ddn.dictOID );
}
// Include NotNull and Default value
const std::string col_defaultValue(col->colType.defaultValue);
if (col->colType.constraintType ==
execplan::CalpontSystemCatalog::NOTNULL_CONSTRAINT)
execplan::CalpontSystemCatalog::NOTNULL_CONSTRAINT)
{
int notNull = 1;
xmlTextWriterWriteFormatAttribute(fWriter,
BAD_CAST xmlTagTable[TAG_NOT_NULL], "%d", notNull);
BAD_CAST xmlTagTable[TAG_NOT_NULL], "%d", notNull);
if (!col_defaultValue.empty())
{
xmlTextWriterWriteAttribute(fWriter,
BAD_CAST xmlTagTable[TAG_DEFAULT_VALUE],
BAD_CAST col_defaultValue.c_str());
BAD_CAST xmlTagTable[TAG_DEFAULT_VALUE],
BAD_CAST col_defaultValue.c_str());
}
}
else if (col->colType.constraintType ==
execplan::CalpontSystemCatalog::DEFAULT_CONSTRAINT)
execplan::CalpontSystemCatalog::DEFAULT_CONSTRAINT)
{
xmlTextWriterWriteAttribute(fWriter,
BAD_CAST xmlTagTable[TAG_DEFAULT_VALUE],
BAD_CAST col_defaultValue.c_str());
BAD_CAST xmlTagTable[TAG_DEFAULT_VALUE],
BAD_CAST col_defaultValue.c_str());
}
} // end of "if fSysCatRpt"
xmlTextWriterEndElement(fWriter);
}
xmlTextWriterEndElement(fWriter); //table
xmlTextWriterEndElement(fWriter); //table
return true;
}
@ -383,7 +400,7 @@ void XMLGenProc::getColumnsForTable(
{
boost::shared_ptr<CalpontSystemCatalog> systemCatalogPtr =
CalpontSystemCatalog::makeCalpontSystemCatalog(
BULK_SYSCAT_SESSION_ID);
BULK_SYSCAT_SESSION_ID);
systemCatalogPtr->identity(CalpontSystemCatalog::EC);
const CalpontSystemCatalog::RIDList ridList =
@ -391,6 +408,7 @@ void XMLGenProc::getColumnsForTable(
CalpontSystemCatalog::RIDList::const_iterator rid_iterator =
ridList.begin();
while (rid_iterator != ridList.end())
{
CalpontSystemCatalog::ROPair roPair = *rid_iterator;
@ -428,7 +446,7 @@ std::string XMLGenProc::genJobXMLFileName( ) const
{
std::string xmlFileName;
boost::filesystem::path p(std::string(
fInputMgr->getParm(XMLGenData::PATH)));
fInputMgr->getParm(XMLGenData::PATH)));
//Append the jobname, jobid & file extension
std::string fileName( JOBNAME );
@ -443,6 +461,7 @@ std::string XMLGenProc::genJobXMLFileName( ) const
// path if so given
xmlFileName = p.string();
#else
if (!p.has_root_path())
{
char cwdPath[4096];
@ -455,9 +474,10 @@ std::string XMLGenProc::genJobXMLFileName( ) const
{
xmlFileName = p.string();
}
#endif
return xmlFileName;
return xmlFileName;
}
//------------------------------------------------------------------------------
@ -474,11 +494,11 @@ void XMLGenProc::writeXMLFile( const std::string& xmlFileName )
//------------------------------------------------------------------------------
// logErrorMessage
//------------------------------------------------------------------------------
void XMLGenProc::logErrorMessage(const std::string& msg)
{
void XMLGenProc::logErrorMessage(const std::string& msg)
{
if (fUseXmlLogFile)
{
fLog.logMsg( msg , MSGLVL_ERROR );
fLog.logMsg( msg, MSGLVL_ERROR );
}
}

View File

@ -72,11 +72,11 @@ public:
/** @brief start constructing XML file document.
*/
EXPORT void startXMLFile( );
/** @brief Creates table tag for the specified table.
*
* @param table Name of table for which the table tag is to be generated.
*/
/** @brief Creates table tag for the specified table.
*
* @param table Name of table for which the table tag is to be generated.
*/
EXPORT void makeTableData(
const execplan::CalpontSystemCatalog::TableName& table);
@ -84,18 +84,18 @@ public:
*
* @param table Name of table for which the column tags are to be generated.
* @return true means column tags created; else false is returned
*/
*/
EXPORT bool makeColumnData(
const execplan::CalpontSystemCatalog::TableName& table);
/** @brief Generate Job XML file name
*/
*/
EXPORT std::string genJobXMLFileName( ) const;
/** @brief Write xml file document to the destination Job XML file.
*
* @param xmlFileName Name of XML file to be generated.
*/
*/
EXPORT void writeXMLFile( const std::string& xmlFileName );
/** @brief log a message.
@ -103,11 +103,17 @@ public:
* @param msg The message to be logged to the error log file.
*/
EXPORT void logErrorMessage(const std::string& msg);
std::string errorString() { return fErrorString; }
std::string errorString()
{
return fErrorString;
}
/** @brief set debug level
*/
void setDebugLevel( int dbg ) { fDebugLevel = dbg; }
void setDebugLevel( int dbg )
{
fDebugLevel = dbg;
}
protected:
@ -115,9 +121,9 @@ private:
XMLGenProc(const XMLGenProc&); // disable default copy ctor
XMLGenProc& operator=(const XMLGenProc&); // disable default assignment
void getColumnsForTable(const std::string& schema,
const std::string& table, SysCatColumnList& colList);
void sortColumnsByPosition(SysCatColumnList &columns);
const std::string& table, SysCatColumnList& colList);
void sortColumnsByPosition(SysCatColumnList& columns);
Log fLog;
xmlDocPtr fDoc;
xmlTextWriterPtr fWriter;
@ -132,4 +138,4 @@ private:
#undef EXPORT
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -87,7 +87,10 @@ public:
/**
* @brief Get job structure
*/
const Job& getJob() const { return fJob; }
const Job& getJob() const
{
return fJob;
}
/**
* @brief Load job information
@ -115,7 +118,7 @@ public:
EXPORT void printJobInfoBrief(Log& logger) const;
/**
* @brief Process node
* @brief Process node
* @param pParentNode Node to be parsed from XML
*/
EXPORT bool processNode( xmlNode* pParentNode );
@ -132,24 +135,24 @@ private:
void setSchema ( xmlNode* pNode );
void initSatLimits( JobColumn& column ) const;
void fillInXMLDataAsLoaded(
execplan::CalpontSystemCatalog::RIDList& colRidList);
execplan::CalpontSystemCatalog::RIDList& colRidList);
void fillInXMLDataNotNullDefault(
const std::string& fullTblName,
execplan::CalpontSystemCatalog::ColType& colType,
JobColumn& col );
const std::string& fullTblName,
execplan::CalpontSystemCatalog::ColType& colType,
JobColumn& col );
void validateAllColumnsHaveTags( const
execplan::CalpontSystemCatalog::RIDList& colRidList) const;
execplan::CalpontSystemCatalog::RIDList& colRidList) const;
void postProcessTableNode( );
static int createTempJobDir( const std::string& xmlFilePath,
std::string& errMsg );
Job fJob; // current job xml
Job fJob; // current job xml
DebugLevel fDebugLevel; // internal use debug level
bool fDeleteTempFile; // delete tmp jobfile in destructor
std::string fJobFileName; // job file name
JobColList fDefaultColumns; // temporary list of default cols
// for table node being processed
// for table node being processed
bool fValidateColList; // Validate all cols have XML tag
};

View File

@ -49,11 +49,12 @@ XMLOp::~XMLOp()
//------------------------------------------------------------------------------
// Close xml doc
//------------------------------------------------------------------------------
void XMLOp::closeDoc()
void XMLOp::closeDoc()
{
if( m_fDoc != NULL ) {
if ( m_fDoc != NULL )
{
xmlFreeDoc( m_fDoc );
m_fDoc = NULL;
m_fDoc = NULL;
}
}
@ -63,16 +64,27 @@ void XMLOp::closeDoc()
// dataType - data type
//------------------------------------------------------------------------------
void XMLOp::convertNodeValue( void* pVal, const char* buf,
XML_DTYPE dataType ) const
XML_DTYPE dataType ) const
{
switch( dataType ) {
case TYPE_CHAR : strcpy( (char*) pVal, buf ); break;
case TYPE_DOUBLE :
case TYPE_FLOAT : *((float*)pVal) = (float) atof( buf ); break;
case TYPE_LONGLONG : *((long long*)pVal) = (long long) atoll( buf );
break;
case TYPE_INT :
default : *((int*)pVal) = (int) atoi( buf ); break;
switch ( dataType )
{
case TYPE_CHAR :
strcpy( (char*) pVal, buf );
break;
case TYPE_DOUBLE :
case TYPE_FLOAT :
*((float*)pVal) = (float) atof( buf );
break;
case TYPE_LONGLONG :
*((long long*)pVal) = (long long) atoll( buf );
break;
case TYPE_INT :
default :
*((int*)pVal) = (int) atoi( buf );
break;
}
}
@ -85,20 +97,22 @@ void XMLOp::convertNodeValue( void* pVal, const char* buf,
// returns TRUE if found, FALSE otherwise
//------------------------------------------------------------------------------
bool XMLOp::getNodeAttribute( xmlNode* pNode, const char* pTag,
void* pVal, XML_DTYPE dataType ) const
void* pVal, XML_DTYPE dataType ) const
{
char buf[XML_NODE_BUF_SIZE];
xmlChar* pTmp = NULL;
bool bFound = false;
pTmp = xmlGetProp( pNode, (xmlChar*) pTag );
if( pTmp ) {
if ( pTmp )
{
bFound = true;
strcpy( buf, (char*) pTmp );
xmlFree( pTmp );
convertNodeValue( pVal, buf, dataType );
} // end if
} // end if
return bFound;
}
@ -112,17 +126,19 @@ bool XMLOp::getNodeAttribute( xmlNode* pNode, const char* pTag,
// returns TRUE if found, FALSE otherwise
//------------------------------------------------------------------------------
bool XMLOp::getNodeAttributeStr( xmlNode* pNode, const char* pTag,
std::string& strVal ) const
std::string& strVal ) const
{
xmlChar* pTmp = NULL;
bool bFound = false;
pTmp = xmlGetProp( pNode, (xmlChar*) pTag );
if( pTmp ) {
if ( pTmp )
{
bFound = true;
strVal = (char*)pTmp;
xmlFree( pTmp );
} // end if
} // end if
return bFound;
}
@ -135,15 +151,18 @@ bool XMLOp::getNodeAttributeStr( xmlNode* pNode, const char* pTag,
// returns TRUE if found, FALSE otherwise
//------------------------------------------------------------------------------
bool XMLOp::getNodeContent( const xmlNode* pNode, void* pVal,
XML_DTYPE dataType )
XML_DTYPE dataType )
{
char buf[XML_NODE_BUF_SIZE];
xmlChar* pTmp = NULL;
bool bFound = false;
if( pNode->children != NULL ) {
if ( pNode->children != NULL )
{
pTmp = xmlNodeGetContent( pNode->children );
if( pTmp ) {
if ( pTmp )
{
bFound = true;
strcpy( buf, (char*) pTmp );
xmlFree( pTmp );
@ -151,7 +170,7 @@ bool XMLOp::getNodeContent( const xmlNode* pNode, void* pVal,
}
}
return bFound;
return bFound;
}
//------------------------------------------------------------------------------
@ -165,16 +184,19 @@ bool XMLOp::getNodeContentStr( const xmlNode* pNode, std::string& strVal)
xmlChar* pTmp = NULL;
bool bFound = false;
if( pNode->children != NULL ) {
if ( pNode->children != NULL )
{
pTmp = xmlNodeGetContent( pNode->children );
if( pTmp ) {
if ( pTmp )
{
bFound = true;
strVal = (char*)pTmp;
xmlFree( pTmp );
}
}
return bFound;
return bFound;
}
//------------------------------------------------------------------------------
@ -182,12 +204,13 @@ bool XMLOp::getNodeContentStr( const xmlNode* pNode, std::string& strVal)
// xmlFileName - xml file name
// returns NO_ERROR if success; other if failure
//------------------------------------------------------------------------------
int XMLOp::parseDoc( const char* xmlFileName )
int XMLOp::parseDoc( const char* xmlFileName )
{
int rc;
rc = readDoc( xmlFileName );
if( rc != NO_ERROR )
if ( rc != NO_ERROR )
return rc;
return processNode( m_pRoot ) ? NO_ERROR : ERR_XML_PARSE;
@ -198,17 +221,17 @@ int XMLOp::parseDoc( const char* xmlFileName )
// xmlFileName - xml file name
// returns NO_ERROR if success; other if failure
//------------------------------------------------------------------------------
int XMLOp::readDoc( const char* xmlFileName )
int XMLOp::readDoc( const char* xmlFileName )
{
// xmlNodePtr curPtr;
m_fDoc = xmlParseFile( xmlFileName );
if( m_fDoc == NULL )
if ( m_fDoc == NULL )
return ERR_XML_FILE;
m_pRoot = xmlDocGetRootElement( m_fDoc );
if( m_pRoot == NULL )
if ( m_pRoot == NULL )
{
closeDoc();
return ERR_XML_ROOT_ELEM;
@ -227,11 +250,11 @@ bool XMLOp::processNode( xmlNode* pParentNode )
xmlNode* pCurNode = NULL;
bool bContinue = true;
for( pCurNode = pParentNode->children; pCurNode; pCurNode = pCurNode->next)
if( pCurNode->type == XML_ELEMENT_NODE)
for ( pCurNode = pParentNode->children; pCurNode; pCurNode = pCurNode->next)
if ( pCurNode->type == XML_ELEMENT_NODE)
bContinue = processNode( pCurNode );
return bContinue;
return bContinue;
}
} //end of namespace

View File

@ -30,8 +30,8 @@
/** Namespace WriteEngine */
namespace WriteEngine
{
// Size of buffer used to parse non-string node content or attribute
const int XML_NODE_BUF_SIZE = 256;
// Size of buffer used to parse non-string node content or attribute
const int XML_NODE_BUF_SIZE = 256;
/** @brief Class wrapper around XML2 API. Used by XmlGenProc to save Job XML
* file for input into cpimport.bin.
@ -73,7 +73,7 @@ protected:
* @brief Get node attribute for strings
*/
bool getNodeAttributeStr( xmlNode* pNode, const char* pTag,
std::string& strVal ) const;
std::string& strVal ) const;
/**
* @brief Get node content for non-strings
@ -90,7 +90,9 @@ protected:
* @brief Check whether it is certain tag
*/
bool isTag( const xmlNode* pNode, const xmlTag tag )
{ return !xmlStrcmp( pNode->name, (const xmlChar *)xmlTagTable[tag] ); }
{
return !xmlStrcmp( pNode->name, (const xmlChar*)xmlTagTable[tag] );
}
/**
* @brief Parse xml document

View File

@ -28,98 +28,100 @@
/** Namespace WriteEngine */
namespace WriteEngine
{
const int MAX_XML_TAG_NAME_SIZE = 30; /** @brief Max size of xml tag name */
const int MAX_XML_TAG_NAME_SIZE = 30; /** @brief Max size of xml tag name */
enum xmlTag {
// Element
TAG_BULK_JOB,
TAG_COLUMN,
TAG_CREATE_DATE,
TAG_CREATE_TIME,
TAG_DEFAULT_COLUMN,
TAG_DELIMITER,
TAG_DESC,
TAG_ENCLOSED_BY_CHAR,
TAG_ESCAPE_CHAR,
TAG_ID,
TAG_IGNORE_FIELD,
TAG_NAME,
TAG_PATH, // obsolete, but keep to be backwards compatible with old files
TAG_SCHEMA,
TAG_TABLE,
TAG_TYPE, // obsolete, but kept to be backwards compatible with old files
TAG_USER,
TAG_READ_BUFFERS,
TAG_WRITE_BUFFER_SIZE,
enum xmlTag
{
// Element
TAG_BULK_JOB,
TAG_COLUMN,
TAG_CREATE_DATE,
TAG_CREATE_TIME,
TAG_DEFAULT_COLUMN,
TAG_DELIMITER,
TAG_DESC,
TAG_ENCLOSED_BY_CHAR,
TAG_ESCAPE_CHAR,
TAG_ID,
TAG_IGNORE_FIELD,
TAG_NAME,
TAG_PATH, // obsolete, but keep to be backwards compatible with old files
TAG_SCHEMA,
TAG_TABLE,
TAG_TYPE, // obsolete, but kept to be backwards compatible with old files
TAG_USER,
TAG_READ_BUFFERS,
TAG_WRITE_BUFFER_SIZE,
// Attributes
TAG_NO_OF_READ_BUFFERS,
TAG_READ_BUFFER_SIZE,
TAG_COL_NAME,
TAG_COL_OID,
TAG_COL_TYPE,
TAG_COMPRESS_TYPE,
TAG_DATA_TYPE,
TAG_AUTOINCREMENT_FLAG,
TAG_DVAL_OID,
TAG_LOAD_NAME,
TAG_MAX_ERR_ROW,
TAG_NOT_NULL,
TAG_DEFAULT_VALUE,
TAG_ORIG_NAME, //@bug 3599: deprecated; kept for backwards compatibility
TAG_PRECISION,
TAG_SCALE,
TAG_TBL_NAME,
TAG_TBL_OID,
TAG_WIDTH,
TAG_SCHEMA_NAME,
NUM_OF_XML_TAGS
};
// Attributes
TAG_NO_OF_READ_BUFFERS,
TAG_READ_BUFFER_SIZE,
TAG_COL_NAME,
TAG_COL_OID,
TAG_COL_TYPE,
TAG_COMPRESS_TYPE,
TAG_DATA_TYPE,
TAG_AUTOINCREMENT_FLAG,
TAG_DVAL_OID,
TAG_LOAD_NAME,
TAG_MAX_ERR_ROW,
TAG_NOT_NULL,
TAG_DEFAULT_VALUE,
TAG_ORIG_NAME, //@bug 3599: deprecated; kept for backwards compatibility
TAG_PRECISION,
TAG_SCALE,
TAG_TBL_NAME,
TAG_TBL_OID,
TAG_WIDTH,
TAG_SCHEMA_NAME,
NUM_OF_XML_TAGS
};
const char xmlTagTable[NUM_OF_XML_TAGS + 1][MAX_XML_TAG_NAME_SIZE] = {
// Elements
"BulkJob",
"Column",
"CreateDate",
"CreateTime",
"DefaultColumn",
"Delimiter",
"Desc",
"EnclosedByChar",
"EscapeChar",
"Id",
"IgnoreField",
"Name",
"Path", //@bug 3777: keep obsolete tag
"Schema",
"Table",
"Type", //@bug 3777: keep obsolete tag
"User",
"ReadBuffers",
"WriteBufferSize",
const char xmlTagTable[NUM_OF_XML_TAGS + 1][MAX_XML_TAG_NAME_SIZE] =
{
// Elements
"BulkJob",
"Column",
"CreateDate",
"CreateTime",
"DefaultColumn",
"Delimiter",
"Desc",
"EnclosedByChar",
"EscapeChar",
"Id",
"IgnoreField",
"Name",
"Path", //@bug 3777: keep obsolete tag
"Schema",
"Table",
"Type", //@bug 3777: keep obsolete tag
"User",
"ReadBuffers",
"WriteBufferSize",
// Attributes
"count",
"size",
"colName", //@bug 3599: replaces origName
"colOid",
"colType",
"compressType",
"dataType",
"autoincrement",
"dValOid",
"loadName",
"maxErrRow",
"notnull",
"defaultValue",
"origName", //@bug 3599: deprecated; kept for backwards compatibility
"precision",
"scale",
"tblName", //@bug 3599: replaces origName
"tblOid",
"width",
"Name"
};
// Attributes
"count",
"size",
"colName", //@bug 3599: replaces origName
"colOid",
"colType",
"compressType",
"dataType",
"autoincrement",
"dValOid",
"loadName",
"maxErrRow",
"notnull",
"defaultValue",
"origName", //@bug 3599: deprecated; kept for backwards compatibility
"precision",
"scale",
"tblName", //@bug 3599: replaces origName
"tblOid",
"width",
"Name"
};
} //end of namespace
#endif // _WE_XMLTAG_H_