int main(void) { { cout << "---PerLoc.aql---" << endl; string str = textToString("../dataset/PerLoc.aql"); for (auto token : getAQLTokens(str)) { cout << AQLTypeToString(token.type) << endl; } } { cout << "---Revenue.aql---" << endl; string str = textToString("../dataset/Revenue.aql"); for (auto token : getAQLTokens(str)) { cout << AQLTypeToString(token.type) << endl; } } return 0; }
Datum DumpQueryToDXLFile(PG_FUNCTION_ARGS) { char *szSqlText = textToString(PG_GETARG_TEXT_P(0)); char *szFilename = textToString(PG_GETARG_TEXT_P(1)); int iLen = translateQueryToFile(szSqlText, szFilename); PG_RETURN_INT32(iLen); }
int main(int argc, char const *argv[]) { if (argc == 3) { string aql_file = string(argv[1]); string aql_text = textToString(aql_file); vector<AQLToken> aqlTokens = getAQLTokens(aql_text); string input_source = string(argv[2]); string input_text = textToString(input_source); if (input_text.length() <= 0) // input source is a directory { if (input_source[input_source.length() - 1] != '/') { input_source += '/'; } DIR *dirp = opendir(input_source.c_str()); struct dirent *dp; if (dirp == NULL) { printf("%s\n", "ERROR: no such directory"); return 0; } while ((dp = readdir(dirp)) != NULL) { string file_name = string(dp->d_name); if (file_name.find(".input") != string::npos \ || file_name.find(".txt") != string::npos) { string file_path = input_source + file_name; string input_text = textToString(file_path); parser(aqlTokens, input_text, file_path); } } closedir(dirp); } else // input source is a file { if (input_source.find(".input") != string::npos \ || input_source.find(".txt") != string::npos) { string input_text = textToString(input_source); parser(aqlTokens, input_text, input_source); } } } else { printf("%s\n", "ERROR: must have exactly two parameters"); } return 0; }
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 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 DumpQueryToFile(PG_FUNCTION_ARGS) { char *szSql = textToString(PG_GETARG_TEXT_P(0)); char *szFilename = textToString(PG_GETARG_TEXT_P(1)); size_t iQueryStringLen = -1; char *pcQuery = getQueryBinary(szSql, &iQueryStringLen); CFileWriter fw; fw.Open(szFilename, S_IRUSR | S_IWUSR); fw.Write(reinterpret_cast<const BYTE*>(&iQueryStringLen), sizeof(iQueryStringLen)); fw.Write(reinterpret_cast<const BYTE*>(pcQuery), iQueryStringLen); fw.Close(); PG_RETURN_UINT32( (ULONG) iQueryStringLen); }
Datum DumpCatalogDXL(PG_FUNCTION_ARGS) { char *szFilename = textToString(PG_GETARG_TEXT_P(0)); List *plAllOids = CCatalogUtils::PlAllOids(); COptTasks::DumpMDObjs(plAllOids, szFilename); PG_RETURN_INT32(0); }
Datum DumpMDScCmpDXL(PG_FUNCTION_ARGS) { Oid oidLeft = gpdb::OidFromDatum(PG_GETARG_DATUM(0)); Oid oidRight = gpdb::OidFromDatum(PG_GETARG_DATUM(1)); char *szCmpType = textToString(PG_GETARG_TEXT_P(2)); char *szDXL = COptTasks::SzMDScCmp(ListMake2Oid(oidLeft, oidRight), szCmpType); PG_RETURN_TEXT_P(stringToText(szDXL)); }
Datum DumpPlanToDXLFile(PG_FUNCTION_ARGS) { char *szSql = textToString(PG_GETARG_TEXT_P(0)); char *szFilename = textToString(PG_GETARG_TEXT_P(1)); PlannedStmt *pplstmt = planQuery(szSql); Assert(pplstmt); char *szXmlString = COptTasks::SzDXL(pplstmt); int iLen = (int) gpos::clib::UlStrLen(szXmlString); CFileWriter fw; fw.Open(szFilename, S_IRUSR | S_IWUSR); fw.Write(reinterpret_cast<const BYTE*>(szXmlString), iLen + 1); fw.Close(); PG_RETURN_INT32(iLen); }
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); }
Datum RestorePlanDXL(PG_FUNCTION_ARGS) { char *szXmlString = textToString(PG_GETARG_TEXT_P(0)); int iProcessed = executeXMLPlan(szXmlString); StringInfoData str; initStringInfo(&str); appendStringInfo(&str, "processed %d rows", iProcessed); text *ptResult = stringToText(str.data); PG_RETURN_TEXT_P(ptResult); }
Datum DumpQuery(PG_FUNCTION_ARGS) { char *szSqlText = textToString(PG_GETARG_TEXT_P(0)); Query *pquery = parseSQL(szSqlText); elog(NOTICE, "(DumpQuery - Original) \n %s", pretty_format_node_dump(const_cast<char*>(gpdb::SzNodeToString(pquery)))); Query *pqueryNormalized = preprocess_query_optimizer(pquery, NULL); elog(NOTICE, "(DumpQuery - Normalized) \n %s", pretty_format_node_dump(const_cast<char*>(gpdb::SzNodeToString(pqueryNormalized)))); text *ptResult = stringToText("Query dumped"); PG_RETURN_TEXT_P(ptResult); }
Datum DumpQueryDXL(PG_FUNCTION_ARGS) { char *szSqlText = textToString(PG_GETARG_TEXT_P(0)); Query *pquery = parseSQL(szSqlText); Assert(pquery); char *szXmlString = COptTasks::SzDXL(pquery); if (NULL == szXmlString) { elog(ERROR, "Error translating query to DXL"); } PG_RETURN_TEXT_P(stringToText(szXmlString)); }
Datum DumpPlanDXL(PG_FUNCTION_ARGS) { char *szSqlText = textToString(PG_GETARG_TEXT_P(0)); PlannedStmt *pplstmt = planQuery(szSqlText); Assert(pplstmt); char *szXmlString = COptTasks::SzDXL(pplstmt); if (NULL == szXmlString) { elog(ERROR, "Error translating plan to DXL"); } PG_RETURN_TEXT_P(stringToText(szXmlString)); }
Datum OptimizeMinidumpFromFile(PG_FUNCTION_ARGS) { char *szFileName = textToString(PG_GETARG_TEXT_P(0)); char *szResultDXL = COptTasks::SzOptimizeMinidumpFromFile(szFileName); if (NULL != szResultDXL) { text *ptResult = stringToText(szResultDXL); gpdb::GPDBFree(szResultDXL); PG_RETURN_TEXT_P(ptResult); } else { elog(NOTICE, "Execution of UDF 'OptimizeMinidumpFromFile' failed. Consult the LOG for more information."); // return a dummy value PG_RETURN_NULL(); } }
Datum Optimize(PG_FUNCTION_ARGS) { char *szSQLText = textToString(PG_GETARG_TEXT_P(0)); Query *pquery = parseSQL(szSQLText); Query *pqueryNormalized = preprocess_query_optimizer(pquery, NULL); Assert(pqueryNormalized); char *szOutput = COptTasks::SzOptimize(pqueryNormalized); if (NULL == szOutput) { elog(ERROR, "Error optimizing query"); } PG_RETURN_TEXT_P(stringToText(szOutput)); }
Datum ExecuteMinidumpFromFile(PG_FUNCTION_ARGS) { char *szFileName = textToString(PG_GETARG_TEXT_P(0)); char *szResultDXL = COptTasks::SzOptimizeMinidumpFromFile(szFileName); if (NULL == szResultDXL) { elog(NOTICE, "Execution of UDF 'ExecuteMinidumpFromFile' failed. Consult the LOG for more information."); // return a dummy value PG_RETURN_NULL(); } int iProcessed = executeXMLPlan(szResultDXL); gpdb::GPDBFree(szResultDXL); StringInfoData str; initStringInfo(&str); appendStringInfo(&str, "processed %d rows", iProcessed); text *ptResult = stringToText(str.data); PG_RETURN_TEXT_P(ptResult); }
Datum EnableXform(PG_FUNCTION_ARGS) { char *szXform = textToString(PG_GETARG_TEXT_P(0)); bool fResult = COptTasks::FSetXform(szXform, false /*fDisable*/); StringInfoData str; initStringInfo(&str); if (fResult) { appendStringInfo(&str, "%s is enabled", szXform); } else { appendStringInfo(&str, "%s is not recognized", szXform); } text *result = stringToText(str.data); PG_RETURN_TEXT_P(result); }