Datum RestoreQueryFromFile(PG_FUNCTION_ARGS) { char *szFilename = textToString(PG_GETARG_TEXT_P(0)); CFileReader fr; fr.Open(szFilename); ULLONG ullSize = fr.UllSize(); elog(NOTICE, "(RestoreFromFile) Filesize is %llu", 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 = 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 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); }
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); }