Datum RestorePlanFromDXLFile(PG_FUNCTION_ARGS) { char *szFilename = textToString(PG_GETARG_TEXT_P(0)); CFileReader fr; fr.Open(szFilename); ULLONG ullSize = fr.UllSize(); char *pcBuf = (char*) gpdb::GPDBAlloc(ullSize + 1); fr.UlpRead((BYTE*)pcBuf, ullSize); pcBuf[ullSize] = '\0'; fr.Close(); int iProcessed = executeXMLPlan(pcBuf); elog(NOTICE, "Processed %d rows.", iProcessed); gpdb::GPDBFree(pcBuf); StringInfoData str; initStringInfo(&str); appendStringInfo(&str, "Query processed %d rows", iProcessed); text *ptResult = stringToText(str.data); PG_RETURN_TEXT_P(ptResult); }
Datum EvalExprFromDXLFile(PG_FUNCTION_ARGS) { char *szFileName = textToString(PG_GETARG_TEXT_P(0)); CFileReader fr; fr.Open(szFileName); ULLONG ullSize = fr.UllSize(); char *pcBuf = (char*) gpdb::GPDBAlloc(ullSize + 1); fr.UlpRead((BYTE*)pcBuf, ullSize); fr.Close(); pcBuf[ullSize] = '\0'; char *szResultDXL = COptTasks::SzEvalExprFromXML(pcBuf); gpdb::GPDBFree(pcBuf); if (NULL != szResultDXL) { text *ptResult = stringToText(szResultDXL); gpdb::GPDBFree(szResultDXL); PG_RETURN_TEXT_P(ptResult); } else { // Return a dummy value so the tests can continue PG_RETURN_NULL(); } }
Datum RestorePlanFromFile(PG_FUNCTION_ARGS) { char *szFilename = textToString(PG_GETARG_TEXT_P(0)); CFileReader fr; fr.Open(szFilename); ULLONG ullSize = fr.UllSize(); char *pcBuf = (char*) gpdb::GPDBAlloc(ullSize); fr.UlpRead((BYTE*)pcBuf, ullSize); fr.Close(); int iBinaryLen; memcpy(&iBinaryLen, pcBuf, sizeof(int)); Assert(iBinaryLen == ullSize - sizeof(int)); char *pcBinary = pcBuf + sizeof(int); int iProcessed = extractFrozenPlanAndExecute(pcBinary); elog(NOTICE, "Processed %d rows.", iProcessed); gpdb::GPDBFree(pcBuf); StringInfoData str; initStringInfo(&str); appendStringInfo(&str, "Query processed %d rows", iProcessed); text *ptResult = stringToText(str.data); PG_RETURN_TEXT_P(ptResult); }
Datum RestoreQueryFromFile(PG_FUNCTION_ARGS) { char *szFilename = text_to_cstring(PG_GETARG_TEXT_P(0)); CFileReader fr; fr.Open(szFilename); ULLONG ullSize = fr.UllSize(); elog(NOTICE, "(RestoreFromFile) Filesize is " UINT64_FORMAT, (uint64) ullSize); char *pcBuf = (char*) gpdb::GPDBAlloc(ullSize); fr.UlpRead((BYTE*)pcBuf, ullSize); fr.Close(); int iBinaryLen; memcpy(&iBinaryLen, pcBuf, sizeof(int)); Assert(iBinaryLen == ullSize - sizeof(int)); elog(NOTICE, "(RestoreFromFile) BinaryLen is %d", iBinaryLen); char *pcBinary = pcBuf + sizeof(int); int iProcessed = extractFrozenQueryPlanAndExecute(pcBinary); elog(NOTICE, "(RestorePlan) PROCESSED %d", iProcessed); StringInfoData str; initStringInfo(&str); appendStringInfo(&str, "Query processed %d rows", iProcessed); text *ptResult = cstring_to_text(str.data); PG_RETURN_TEXT_P(ptResult); }
char *read_file(const char *szFilename) { CFileReader fr; fr.Open(szFilename); ULLONG ullSize = fr.UllSize(); char *pcBuf = (char*) gpdb::GPDBAlloc(ullSize); fr.UlpRead((BYTE*)pcBuf, ullSize); pcBuf[ullSize] = '\0'; fr.Close(); return pcBuf; }
Datum DumpQueryFromFileToDXLFile(PG_FUNCTION_ARGS) { char *szSqlFilename = textToString(PG_GETARG_TEXT_P(0)); char *szFilename = textToString(PG_GETARG_TEXT_P(1)); CFileReader fr; fr.Open(szSqlFilename); ULLONG ullSize = fr.UllSize(); char *pcBuf = (char*) gpdb::GPDBAlloc(ullSize + 1); fr.UlpRead((BYTE*)pcBuf, ullSize); pcBuf[ullSize] = '\0'; fr.Close(); int iLen = translateQueryToFile(pcBuf, szFilename); gpdb::GPDBFree(pcBuf); PG_RETURN_INT32(iLen); }
//--------------------------------------------------------------------------- // @function: // COstreamFileTest::Unittest_CheckOutputFile // // @doc: // Check the contents of the file used by the output stream // //--------------------------------------------------------------------------- void COstreamFileTest::Unittest_CheckOutputFile ( const CHAR *szFile ) { GPOS_ASSERT(NULL != szFile); CFileReader fr; fr.Open(szFile); const ULONG ulReadBufferSize = 1024; WCHAR wszReadBuffer[ulReadBufferSize]; #ifdef GPOS_DEBUG ULONG_PTR ulpRead = #endif // GPOS_DEBUG fr.UlpRead((BYTE *) wszReadBuffer, GPOS_ARRAY_SIZE(wszReadBuffer)); CWStringConst strExpected(GPOS_WSZ_LIT("WC102-10some regular stringdeadbeef")); GPOS_ASSERT(ulpRead == (ULONG_PTR) strExpected.UlLength() * GPOS_SIZEOF(WCHAR)); GPOS_ASSERT(strExpected.FEquals(&strExpected)); }