funcs.cpp 2.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//---------------------------------------------------------------------------
//	Greenplum Database
//	Copyright (C) 2011 EMC Greenplum, Inc.
//
//	@filename:
//		funcs.cpp
//
//	@doc:
//		API for invoking optimizer using GPDB udfs
//
//	@test:
//
//
//---------------------------------------------------------------------------

#include <sys/stat.h>

H
Heikki Linnakangas 已提交
18 19 20 21 22 23
extern "C" {
#include "postgres.h"
#include "fmgr.h"
#include "utils/builtins.h"
}

24
#include "gpopt/utils/funcs.h"
25
#include "gpopt/utils/COptTasks.h"
26

27 28
#include "gpos/_api.h"
#include "gpopt/gpdbwrappers.h"
29

30 31
#include "gpopt/version.h"
#include "xercesc/util/XercesVersion.hpp"
32 33 34 35 36 37 38 39 40 41 42

//---------------------------------------------------------------------------
//	@function:
//		DisableXform
//
//	@doc:
//		Takes transformation name as input, and disables this transformation.
//
//---------------------------------------------------------------------------

extern "C" {
J
Jesse Zhang 已提交
43
Datum DisableXform(PG_FUNCTION_ARGS)
44
{
45
	char *szXform = text_to_cstring(PG_GETARG_TEXT_P(0));
46
	bool is_result = COptTasks::SetXform(szXform, true /*fDisable*/);
47 48 49 50

	StringInfoData str;
	initStringInfo(&str);

51
	if (is_result)
52 53 54 55 56 57 58
	{
		appendStringInfo(&str, "%s is disabled", szXform);
	}
	else
	{
		appendStringInfo(&str, "%s is not recognized", szXform);
	}
59
	text *result = cstring_to_text(str.data);
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

	PG_RETURN_TEXT_P(result);
}
}

//---------------------------------------------------------------------------
//	@function:
//		EnableXform
//
//	@doc:
//		Takes transformation name as input, and enables this transformation.
//
//---------------------------------------------------------------------------

extern "C" {
J
Jesse Zhang 已提交
75
Datum EnableXform(PG_FUNCTION_ARGS)
76
{
77
	char *szXform = text_to_cstring(PG_GETARG_TEXT_P(0));
78
	bool is_result = COptTasks::SetXform(szXform, false /*fDisable*/);
79 80 81 82

	StringInfoData str;
	initStringInfo(&str);

83
	if (is_result)
84 85 86 87 88 89 90
	{
		appendStringInfo(&str, "%s is enabled", szXform);
	}
	else
	{
		appendStringInfo(&str, "%s is not recognized", szXform);
	}
91
	text *result = cstring_to_text(str.data);
92 93 94 95 96 97 98 99 100 101 102

	PG_RETURN_TEXT_P(result);
}
}


//---------------------------------------------------------------------------
//	@function:
//		LibraryVersion
//
//	@doc:
H
Haisheng Yuan 已提交
103
//		Returns the optimizer and xerces library versions as a message
104 105 106 107 108 109 110 111
//
//---------------------------------------------------------------------------
extern "C" {
Datum
LibraryVersion()
{
	StringInfoData str;
	initStringInfo(&str);
H
Haisheng Yuan 已提交
112
	appendStringInfo(&str, "GPOPT version: %s", GPORCA_VERSION_STRING);
113
	appendStringInfo(&str, ", Xerces version: %s", XERCES_FULLVERSIONDOT);
114
	text *result = cstring_to_text(str.data);
115 116 117 118 119 120

	PG_RETURN_TEXT_P(result);
}
}

extern "C" {
H
Heikki Linnakangas 已提交
121
const char *
122 123
OptVersion()
{
H
Heikki Linnakangas 已提交
124
	return GPORCA_VERSION_STRING;
125 126
}
}