You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hawq.apache.org by fo...@apache.org on 2015/11/12 21:25:19 UTC

[2/9] incubator-hawq git commit: HAWQ-149. Add orafce, gp_cancel_query, pgbench and extprotocol to HAWQ

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e74af545/contrib/orafce/sql/files.sql
----------------------------------------------------------------------
diff --git a/contrib/orafce/sql/files.sql b/contrib/orafce/sql/files.sql
new file mode 100644
index 0000000..d3f5c07
--- /dev/null
+++ b/contrib/orafce/sql/files.sql
@@ -0,0 +1,66 @@
+\set ECHO none
+SET client_min_messages = NOTICE;
+\set ECHO all
+
+INSERT INTO utl_file.utl_file_dir(dir) VALUES(utl_file.tmpdir());
+
+CREATE OR REPLACE FUNCTION gen_file(dir text) RETURNS void AS $$
+DECLARE
+  f utl_file.file_type;
+BEGIN
+  f := utl_file.fopen(dir, 'regress_orafce.txt', 'w');
+  PERFORM utl_file.put_line(f, 'ABC');
+  PERFORM utl_file.put_line(f, '123'::numeric);
+  PERFORM utl_file.put_line(f, '-----');
+  PERFORM utl_file.new_line(f);
+  PERFORM utl_file.put_line(f, '-----');
+  PERFORM utl_file.new_line(f, 0);
+  PERFORM utl_file.put_line(f, '-----');
+  PERFORM utl_file.new_line(f, 2);
+  PERFORM utl_file.put_line(f, '-----');
+  PERFORM utl_file.put(f, 'A');
+  PERFORM utl_file.put(f, 'B');
+  PERFORM utl_file.new_line(f);
+  PERFORM utl_file.putf(f, '[1=%s, 2=%s, 3=%s, 4=%s, 5=%s]', '1', '2', '3', '4', '5');
+  PERFORM utl_file.new_line(f);
+  PERFORM utl_file.put_line(f, '1234567890');
+  f := utl_file.fclose(f);
+END;
+$$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION read_file(dir text) RETURNS void AS $$
+DECLARE
+  f utl_file.file_type;
+BEGIN
+  f := utl_file.fopen(dir, 'regress_orafce.txt', 'r');
+  FOR i IN 1..11 LOOP
+    RAISE NOTICE '[%] >>%<<', i, utl_file.get_line(f);
+  END LOOP;
+  RAISE NOTICE '>>%<<', utl_file.get_line(f, 4);
+  RAISE NOTICE '>>%<<', utl_file.get_line(f, 4);
+  RAISE NOTICE '>>%<<', utl_file.get_line(f);
+  RAISE NOTICE '>>%<<', utl_file.get_line(f);
+  EXCEPTION
+    -- WHEN no_data_found THEN,  8.1 plpgsql doesn't know no_data_found
+    WHEN others THEN
+      RAISE NOTICE 'finish % ', sqlerrm;
+      RAISE NOTICE 'is_open = %', utl_file.is_open(f);
+      PERFORM utl_file.fclose_all();
+      RAISE NOTICE 'is_open = %', utl_file.is_open(f);
+END;
+$$ LANGUAGE plpgsql;
+
+SELECT gen_file(utl_file.tmpdir());
+SELECT fexists FROM utl_file.fgetattr(utl_file.tmpdir(), 'regress_orafce.txt');
+SELECT utl_file.fcopy(utl_file.tmpdir(), 'regress_orafce.txt', utl_file.tmpdir(), 'regress_orafce2.txt');
+SELECT fexists FROM utl_file.fgetattr(utl_file.tmpdir(), 'regress_orafce2.txt');
+SELECT utl_file.frename(utl_file.tmpdir(), 'regress_orafce2.txt', utl_file.tmpdir(), 'regress_orafce.txt', true);
+SELECT fexists FROM utl_file.fgetattr(utl_file.tmpdir(), 'regress_orafce.txt');
+SELECT fexists FROM utl_file.fgetattr(utl_file.tmpdir(), 'regress_orafce2.txt');
+SELECT read_file(utl_file.tmpdir());
+SELECT utl_file.fremove(utl_file.tmpdir(), 'regress_orafce.txt');
+SELECT fexists FROM utl_file.fgetattr(utl_file.tmpdir(), 'regress_orafce.txt');
+DROP FUNCTION gen_file(text);
+DROP FUNCTION read_file(text);
+
+DELETE FROM utl_file.utl_file_dir;

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e74af545/contrib/orafce/sqlparse.y
----------------------------------------------------------------------
diff --git a/contrib/orafce/sqlparse.y b/contrib/orafce/sqlparse.y
new file mode 100644
index 0000000..ca86d06
--- /dev/null
+++ b/contrib/orafce/sqlparse.y
@@ -0,0 +1,111 @@
+%{
+
+#define YYPARSE_PARAM result  /* need this to pass a pointer (void *) to yyparse */
+#define YYDEBUG 1
+
+#define YYLLOC_DEFAULT(Current, Rhs, N) \
+do { \
+if (N) \
+(Current) = (Rhs)[1]; \
+else \
+(Current) = (Rhs)[0]; \
+} while (0)                      
+
+#include "postgres.h"
+#include "orafunc.h"
+#include "plvlex.h"
+#include "nodes/pg_list.h"
+
+
+#define MOVE_TO_S(src,dest,col)	dest->col = src.col ? pstrdup(src.col) : NULL
+#define MOVE_TO(src,dest,col)	dest->col = src.col
+
+#define FILL_NODE(src,dest)	\
+	MOVE_TO_S(src,dest,str), \
+	MOVE_TO(src,dest,keycode), \
+	MOVE_TO(src,dest,lloc), \
+	MOVE_TO_S(src,dest,sep), \
+	MOVE_TO(src,dest,modificator)
+
+static orafce_lexnode *__node;
+
+#define CREATE_NODE(src,type) 	\
+  ( \
+    __node = (orafce_lexnode*) palloc(sizeof(orafce_lexnode)), \
+    __node->typenode = X_##type, \
+    __node->classname = #type, \
+    FILL_NODE(src,__node), \
+    __node)
+    
+    
+
+
+extern int yylex(void);      /* defined as fdate_yylex in fdatescan.l */
+
+static char *scanbuf;
+static int	scanbuflen;
+
+void orafce_sql_yyerror(const char *message);
+
+
+#define YYLTYPE int
+
+%}
+%name-prefix="orafce_sql_yy" 
+%locations
+
+%union
+{
+    int 	ival;
+    orafce_lexnode	*node;
+    List		*list;
+    struct
+    {
+	    char 	*str;
+	    int		keycode;
+	    int		lloc;
+	    char	*sep;
+	    char *modificator;
+    }				val;
+
+
+}
+    
+/* BISON Declarations */
+%token <val>    X_IDENT X_NCONST X_SCONST X_OP X_PARAM X_COMMENT X_WHITESPACE X_KEYWORD X_OTHERS X_TYPECAST
+
+%type <list> elements
+%type <node> anyelement
+%type <list> root
+
+%start root
+
+
+/* Grammar follows */
+%%
+
+root:
+	    elements { *((void**)result) = $1; }
+	;
+
+elements:
+		anyelement { $$ = list_make1($1);}
+		| elements anyelement { $$ = lappend($1, $2);}
+	;
+
+anyelement:
+		X_IDENT		{ $$ = (orafce_lexnode*) CREATE_NODE($1, IDENT);  }
+		| X_NCONST	{ $$ = (orafce_lexnode*) CREATE_NODE($1, NCONST); }
+		| X_SCONST	{ $$ = (orafce_lexnode*) CREATE_NODE($1, SCONST); }
+		| X_OP		{ $$ = (orafce_lexnode*) CREATE_NODE($1, OP);    }
+		| X_PARAM		{ $$ = (orafce_lexnode*) CREATE_NODE($1, PARAM); }
+		| X_COMMENT	{ $$ = (orafce_lexnode*) CREATE_NODE($1, COMMENT);    }
+		| X_WHITESPACE	{ $$ = (orafce_lexnode*) CREATE_NODE($1, WHITESPACE); }
+		| X_KEYWORD	{ $$ = (orafce_lexnode*) CREATE_NODE($1, KEYWORD); }
+		| X_OTHERS	{ $$ = (orafce_lexnode*) CREATE_NODE($1, OTHERS);  }
+	;
+%%
+
+
+
+#include "sqlscan.c"

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e74af545/contrib/orafce/sqlscan.l
----------------------------------------------------------------------
diff --git a/contrib/orafce/sqlscan.l b/contrib/orafce/sqlscan.l
new file mode 100644
index 0000000..dcb3b05
--- /dev/null
+++ b/contrib/orafce/sqlscan.l
@@ -0,0 +1,1061 @@
+%{
+/* 
+** A scanner for EMP-style numeric ranges 
+*/
+
+#include "postgres.h"
+#include "parser/keywords.h"
+
+#ifdef GP_VERSION_NUM
+#define YY_NO_INPUT 1
+#endif
+
+#undef yyparse  /* don't need it now and solve problems with 8.1 */
+
+#include "parser/gramparse.h"                                                                                               
+#include "parser/keywords.h"                                                                                                
+/* Not needed now that this file is compiled as part of gram.y */                                                           
+/* #include "parser/parse.h" */                                                                                             
+#include "parser/scansup.h"      
+#include "mb/pg_wchar.h"
+
+#define unify_version(a,b,c) ((a<<16)+(b<<8)+c)
+
+/* simplified current version */
+#define YY_FLEX_FULL_VERSION \
+  unify_version(YY_FLEX_MAJOR_VERSION,YY_FLEX_MINOR_VERSION,YY_FLEX_SUBMINOR_VERSION)
+
+/* 
+ * Need to define these prototypes to shut GCC up. Flex fixes this from
+ * > 2.5.35
+ */
+#if YY_FLEX_FULL_VERSION < unify_version(2,5,35)
+int orafce_sql_yyget_lineno  (void);
+FILE *orafce_sql_yyget_in  (void);
+FILE *orafce_sql_yyget_out  (void);
+char *orafce_sql_yyget_text  (void);
+void orafce_sql_yyset_lineno (int  line_number );
+void orafce_sql_yyset_in (FILE *  in_str );
+void orafce_sql_yyset_out (FILE *  out_str );
+int orafce_sql_yyget_debug  (void);
+void orafce_sql_yyset_debug (int  bdebug );
+int orafce_sql_yylex_destroy  (void);
+int orafce_sql_yyget_leng(void);
+#endif
+
+#if PG_VERSION_NUM >= 80500
+extern PGDLLIMPORT const ScanKeyword ScanKeywords[];
+extern PGDLLIMPORT const int	NumScanKeywords;
+#define ScanKeywordLookupArgs	, ScanKeywords, NumScanKeywords
+#else
+#define ScanKeywordLookupArgs
+#endif
+
+#undef fprintf
+#define fprintf(file, fmt, msg)  ereport(ERROR, (errmsg_internal("%s", msg)))
+
+static int		xcdepth = 0;	/* depth of nesting in slash-star comments */
+static char    *dolqstart;      /* current $foo$ quote start string */
+static bool extended_string = false;
+
+
+/* No reason to constrain amount of data slurped */
+#define YY_READ_BUF_SIZE 16777216
+
+/* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
+#define fprintf(file, fmt, msg)  ereport(ERROR, (errmsg_internal("%s", msg)))
+
+/* Handles to the buffer that the lexer uses internally */
+
+
+static YY_BUFFER_STATE scanbufhandle;
+
+#define SET_YYLLOC()  (yylval.val.lloc = yylloc = yytext - scanbuf)                                                                                              
+                                                                                                                                               
+/* Handles to the buffer that the lexer uses internally */                                                                                     
+static char *scanbuf;       
+
+/* flex 2.5.4 doesn't bother with a decl for this */
+
+int orafce_sql_yylex(void);
+
+extern YYSTYPE yylval;
+
+void orafce_sql_scanner_init(const char *str);
+void orafce_sql_scanner_finish(void);
+
+/*
+ * literalbuf is used to accumulate literal values when multiple rules
+ * are needed to parse a single literal.  Call startlit to reset buffer
+ * to empty, addlit to add text.  Note that the buffer is palloc'd and
+ * starts life afresh on every parse cycle.
+ */
+static char	   *literalbuf;		/* expandable buffer */
+static int		literallen;		/* actual current length */
+static int		literalalloc;	/* current allocated buffer size */
+
+#define startlit()  (literalbuf[0] = '\0', literallen = 0)
+static void addlit(char *ytext, int yleng);
+static void addlitchar(unsigned char ychar);
+static char *litbufdup(void);
+
+static int	lexer_errposition(void);
+
+/*
+ * Each call to yylex must set yylloc to the location of the found token
+ * (expressed as a byte offset from the start of the input text).
+ * When we parse a token that requires multiple lexer rules to process,
+ * this should be done in the first such rule, else yylloc will point
+ * into the middle of the token.
+ */
+
+/* Handles to the buffer that the lexer uses internally */
+static char *scanbuf;
+
+static unsigned char unescape_single_char(unsigned char c);
+
+#ifndef _pg_mbstrlen_with_len
+#define _pg_mbstrlen_with_len(buf,loc) 	pg_mbstrlen_with_len(buf,loc)
+#endif
+
+%}
+
+%option 8bit
+%option never-interactive
+%option nodefault
+%option nounput
+%option noyywrap
+%option prefix="orafce_sql_yy"
+
+/*
+ * OK, here is a short description of lex/flex rules behavior.
+ * The longest pattern which matches an input string is always chosen.
+ * For equal-length patterns, the first occurring in the rules list is chosen.
+ * INITIAL is the starting state, to which all non-conditional rules apply.
+ * Exclusive states change parsing rules while the state is active.  When in
+ * an exclusive state, only those rules defined for that state apply.
+ *
+ * We use exclusive states for quoted strings, extended comments,
+ * and to eliminate parsing troubles for numeric strings.
+ * Exclusive states:
+ *  <xb> bit string literal
+ *  <xc> extended C-style comments
+ *  <xd> delimited identifiers (double-quoted identifiers)
+ *  <xh> hexadecimal numeric string
+ *  <xq> standard quoted strings
+ *  <xe> extended quoted strings (support backslash escape sequences)
+ *  <xdolq> $foo$ quoted strings
+ */
+
+%x xb
+%x xc
+%x xd
+%x xh
+%x xe
+%x xq
+%x xdolq
+
+
+/*
+ * In order to make the world safe for Windows and Mac clients as well as
+ * Unix ones, we accept either \n or \r as a newline.  A DOS-style \r\n
+ * sequence will be seen as two successive newlines, but that doesn't cause
+ * any problems.  Comments that start with -- and extend to the next
+ * newline are treated as equivalent to a single whitespace character.
+ *
+ * NOTE a fine point: if there is no newline following --, we will absorb
+ * everything to the end of the input as a comment.  This is correct.  Older
+ * versions of Postgres failed to recognize -- as a comment if the input
+ * did not end with a newline.
+ *
+ * XXX perhaps \f (formfeed) should be treated as a newline as well?
+ *
+ * XXX if you change the set of whitespace characters, fix scanner_isspace()
+ * to agree, and see also the plpgsql lexer.
+ */
+
+space			[ \t\n\r\f]
+horiz_space		[ \t\f]
+newline			[\n\r]
+non_newline		[^\n\r]
+
+comment			("--"{non_newline}*)
+
+whitespace		{space}+
+
+/*
+ * SQL requires at least one newline in the whitespace separating
+ * string literals that are to be concatenated.  Silly, but who are we
+ * to argue?  Note that {whitespace_with_newline} should not have * after
+ * it, whereas {whitespace} should generally have a * after it...
+ */
+
+special_whitespace		({space}+|{comment}{newline})
+horiz_whitespace		({horiz_space}|{comment})
+whitespace_with_newline	({horiz_whitespace}*{newline}{special_whitespace}*)
+
+/*
+ * To ensure that {quotecontinue} can be scanned without having to back up
+ * if the full pattern isn't matched, we include trailing whitespace in
+ * {quotestop}.  This matches all cases where {quotecontinue} fails to match,
+ * except for {quote} followed by whitespace and just one "-" (not two,
+ * which would start a {comment}).  To cover that we have {quotefail}.
+ * The actions for {quotestop} and {quotefail} must throw back characters
+ * beyond the quote proper.
+ */
+quote			'
+quotestop		{quote}{whitespace}*
+quotecontinue	{quote}{whitespace_with_newline}{quote}
+quotefail		{quote}{whitespace}*"-"
+
+/* Bit string
+ * It is tempting to scan the string for only those characters
+ * which are allowed. However, this leads to silently swallowed
+ * characters if illegal characters are included in the string.
+ * For example, if xbinside is [01] then B'ABCD' is interpreted
+ * as a zero-length string, and the ABCD' is lost!
+ * Better to pass the string forward and let the input routines
+ * validate the contents.
+ */
+xbstart			[bB]{quote}
+xbinside		[^']*
+
+/* Hexadecimal number */
+xhstart			[xX]{quote}
+xhinside		[^']*
+
+/* National character */
+xnstart			[nN]{quote}
+
+/* Quoted string that allows backslash escapes */
+xestart			[eE]{quote}
+xeinside		[^\\']+
+xeescape		[\\][^0-7]
+xeoctesc		[\\][0-7]{1,3}
+xehexesc		[\\]x[0-9A-Fa-f]{1,2}
+
+/* Extended quote
+ * xqdouble implements embedded quote, ''''
+ */
+xqstart			{quote}
+xqdouble		{quote}{quote}
+xqinside		[^']+
+
+/* $foo$ style quotes ("dollar quoting")
+ * The quoted string starts with $foo$ where "foo" is an optional string
+ * in the form of an identifier, except that it may not contain "$", 
+ * and extends to the first occurrence of an identical string.  
+ * There is *no* processing of the quoted text.
+ *
+ * {dolqfailed} is an error rule to avoid scanner backup when {dolqdelim}
+ * fails to match its trailing "$".
+ */
+dolq_start		[A-Za-z\200-\377_]
+dolq_cont		[A-Za-z\200-\377_0-9]
+dolqdelim		\$({dolq_start}{dolq_cont}*)?\$
+dolqfailed		\${dolq_start}{dolq_cont}*
+dolqinside		[^$]+
+
+/* Double quote
+ * Allows embedded spaces and other special characters into identifiers.
+ */
+dquote			\"
+xdstart			{dquote}
+xdstop			{dquote}
+xddouble		{dquote}{dquote}
+xdinside		[^"]+
+
+/* C-style comments
+ *
+ * The "extended comment" syntax closely resembles allowable operator syntax.
+ * The tricky part here is to get lex to recognize a string starting with
+ * slash-star as a comment, when interpreting it as an operator would produce
+ * a longer match --- remember lex will prefer a longer match!  Also, if we
+ * have something like plus-slash-star, lex will think this is a 3-character
+ * operator whereas we want to see it as a + operator and a comment start.
+ * The solution is two-fold:
+ * 1. append {op_chars}* to xcstart so that it matches as much text as
+ *    {operator} would. Then the tie-breaker (first matching rule of same
+ *    length) ensures xcstart wins.  We put back the extra stuff with yyless()
+ *    in case it contains a star-slash that should terminate the comment.
+ * 2. In the operator rule, check for slash-star within the operator, and
+ *    if found throw it back with yyless().  This handles the plus-slash-star
+ *    problem.
+ * Dash-dash comments have similar interactions with the operator rule.
+ */
+xcstart			\/\*{op_chars}*
+xcstop			\*+\/
+xcinside		[^*/]+
+
+digit			[0-9]
+ident_start		[A-Za-z\200-\377_]
+ident_cont		[A-Za-z\200-\377_0-9\$]
+
+identifier		{ident_start}{ident_cont}*
+
+typecast		"::"
+
+/*
+ * "self" is the set of chars that should be returned as single-character
+ * tokens.  "op_chars" is the set of chars that can make up "Op" tokens,
+ * which can be one or more characters long (but if a single-char token
+ * appears in the "self" set, it is not to be returned as an Op).  Note
+ * that the sets overlap, but each has some chars that are not in the other.
+ *
+ * If you change either set, adjust the character lists appearing in the
+ * rule for "operator"!
+ */
+self			[,()\[\].;\:\+\-\*\/\%\^\<\>\=]
+op_chars		[\~\!\@\#\^\&\|\`\?\+\-\*\/\%\<\>\=]
+operator		{op_chars}+
+
+/* we no longer allow unary minus in numbers. 
+ * instead we pass it separately to parser. there it gets
+ * coerced via doNegate() -- Leon aug 20 1999
+ *
+ * {realfail1} and {realfail2} are added to prevent the need for scanner
+ * backup when the {real} rule fails to match completely.
+ */
+
+integer			{digit}+
+decimal			(({digit}*\.{digit}+)|({digit}+\.{digit}*))
+real			({integer}|{decimal})[Ee][-+]?{digit}+
+realfail1		({integer}|{decimal})[Ee]
+realfail2		({integer}|{decimal})[Ee][-+]
+
+param			\${integer}
+
+other			.
+
+/*
+ * Dollar quoted strings are totally opaque, and no escaping is done on them.
+ * Other quoted strings must allow some special characters such as single-quote
+ *  and newline.
+ * Embedded single-quotes are implemented both in the SQL standard
+ *  style of two adjacent single quotes "''" and in the Postgres/Java style
+ *  of escaped-quote "\'".
+ * Other embedded escaped characters are matched explicitly and the leading
+ *  backslash is dropped from the string.
+ * Note that xcstart must appear before operator, as explained above!
+ *  Also whitespace (comment) must appear before operator.
+ */
+
+%%
+
+{whitespace}	{
+					SET_YYLLOC();
+					yylval.val.str = yytext;
+					yylval.val.modificator = NULL;
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_WHITESPACE;
+				}
+
+{comment}	{
+					SET_YYLLOC();
+					yylval.val.str = yytext;
+					yylval.val.modificator = "sc";
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_COMMENT;
+				}
+
+
+{xcstart}		{
+					/* Set location in case of syntax error in comment */
+					SET_YYLLOC();
+					xcdepth = 0;
+					BEGIN(xc);
+					/* Put back any characters past slash-star; see above */
+					startlit();
+					addlitchar('/');
+					addlitchar('*');
+				
+					yyless(2);
+				}
+
+<xc>{xcstart}	{
+					xcdepth++;
+					/* Put back any characters past slash-star; see above */
+					addlitchar('/');
+					addlitchar('*');
+
+					yyless(2);
+				}
+
+<xc>{xcstop}	{
+					if (xcdepth <= 0)
+					{
+						BEGIN(INITIAL);
+						addlitchar('*');
+						addlitchar('/');
+
+						yylval.val.str = litbufdup();
+						yylval.val.modificator = "ec";
+						yylval.val.keycode = -1;
+						yylval.val.sep = NULL;
+						return X_COMMENT;
+					}
+					else
+					{
+						xcdepth--;
+						addlitchar('*');
+						addlitchar('/');
+					}
+
+				}
+
+<xc>{xcinside}	{
+					addlit(yytext, yyleng);
+				}
+
+<xc>{op_chars}	{
+					addlit(yytext, yyleng);
+				}
+
+<xc>\*+			{
+					addlit(yytext, yyleng);
+				}
+
+<xc><<EOF>>		{ 
+					yylval.val.str = litbufdup();
+					yylval.val.modificator = "ecu";
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_COMMENT;
+
+				}
+
+{xbstart}		{
+					/* Binary bit type.
+					 * At some point we should simply pass the string
+					 * forward to the parser and label it there.
+					 * In the meantime, place a leading "b" on the string
+					 * to mark it for the input routine as a binary string.
+					 */
+					SET_YYLLOC();
+					BEGIN(xb);
+					startlit();
+					addlitchar('b');
+				}
+<xb>{quotestop}	|
+<xb>{quotefail} {
+					yyless(1);
+					BEGIN(INITIAL);
+					yylval.val.str = litbufdup();
+					yylval.val.modificator = "b";
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_NCONST;
+				}
+<xh>{xhinside}	|
+<xb>{xbinside}	{
+					addlit(yytext, yyleng);
+				}
+<xh>{quotecontinue}	|
+<xb>{quotecontinue}	{
+					/* ignore */
+				}
+<xb><<EOF>>		{ 
+					yylval.val.str = litbufdup();
+					yylval.val.modificator = "bu";
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_NCONST;
+				}
+
+{xhstart}		{
+					/* Hexadecimal bit type.
+					 * At some point we should simply pass the string
+					 * forward to the parser and label it there.
+					 * In the meantime, place a leading "x" on the string
+					 * to mark it for the input routine as a hex string.
+					 */
+					SET_YYLLOC();
+					BEGIN(xh);
+					startlit();
+					addlitchar('x');
+				}
+<xh>{quotestop}	|
+<xh>{quotefail} {
+					yyless(1);
+					BEGIN(INITIAL);
+					yylval.val.str = litbufdup();
+					yylval.val.modificator = "x";
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_NCONST;
+				}
+<xh><<EOF>>		{ 
+					yylval.val.str = litbufdup();
+					yylval.val.modificator = "xu";
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_NCONST;
+				}
+
+{xnstart}		{
+					/* National character.
+					 * We will pass this along as a normal character string,
+					 * but preceded with an internally-generated "NCHAR".
+					 */
+					const ScanKeyword *keyword;
+
+					SET_YYLLOC();
+					yyless(1);				/* eat only 'n' this time */
+					/* nchar had better be a keyword! */
+					keyword = ScanKeywordLookup("nchar" ScanKeywordLookupArgs);
+					Assert(keyword != NULL);
+					yylval.val.str = (char*) keyword->name;
+					yylval.val.keycode = keyword->value;
+					yylval.val.modificator = NULL;
+					yylval.val.sep = NULL;
+					return X_KEYWORD;
+				}
+
+{xqstart}		{
+					SET_YYLLOC();
+					BEGIN(xq);
+					extended_string = false;
+					startlit();
+				}
+{xestart}		{
+					SET_YYLLOC();
+					BEGIN(xe);
+					extended_string = true;
+					startlit();
+				}
+<xq,xe>{quotestop}	|
+<xq,xe>{quotefail} {
+					yyless(1);
+					BEGIN(INITIAL);
+					yylval.val.str = litbufdup();
+					yylval.val.modificator = extended_string ? "es" : "qs";
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_SCONST;
+				}
+<xq,xe>{xqdouble} {
+					addlitchar('\'');
+				}
+<xq>{xqinside}  {
+					addlit(yytext, yyleng);
+				}
+<xe>{xeinside}  {
+					addlit(yytext, yyleng);
+				}
+<xe>{xeescape}  {
+					addlitchar(unescape_single_char(yytext[1]));
+				}
+<xe>{xeoctesc}  {
+					unsigned char c = strtoul(yytext+1, NULL, 8);
+
+					addlitchar(c);
+				}
+<xe>{xehexesc}  {
+					unsigned char c = strtoul(yytext+2, NULL, 16);
+
+					addlitchar(c);
+				}
+<xq,xe>{quotecontinue} {
+					/* ignore */
+				}
+<xe>.			{
+					/* This is only needed for \ just before EOF */
+					addlitchar(yytext[0]);
+				}
+<xq,xe><<EOF>>		{ 
+					yylval.val.str = litbufdup();
+					yylval.val.modificator = extended_string ? "esu" : "qsu";
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_SCONST;
+				}    
+
+{dolqdelim}		{
+					SET_YYLLOC();
+					dolqstart = pstrdup(yytext);
+					BEGIN(xdolq);
+					startlit();
+				}
+{dolqfailed}	{
+					/* throw back all but the initial "$" */
+					yyless(1);
+					/* and treat it as {other} */
+					yylval.val.str = yytext;
+					yylval.val.modificator = "dolqf";
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_OTHERS;
+				}
+<xdolq>{dolqdelim} {
+					if (strcmp(yytext, dolqstart) == 0)
+					{
+						yylval.val.sep = dolqstart;
+						yylval.val.modificator = "dolq";
+						BEGIN(INITIAL);
+						yylval.val.str = litbufdup();
+						yylval.val.keycode = -1;
+						return X_SCONST;
+					}
+					else
+					{
+						/*
+						 * When we fail to match $...$ to dolqstart, transfer
+						 * the $... part to the output, but put back the final
+						 * $ for rescanning.  Consider $delim$...$junk$delim$
+						 */
+						addlit(yytext, yyleng-1);
+						yyless(yyleng-1);
+					}
+				}
+<xdolq>{dolqinside} {
+					addlit(yytext, yyleng);
+				}
+<xdolq>{dolqfailed} {
+					addlit(yytext, yyleng);
+				}
+<xdolq>.		{
+					/* This is only needed for inside the quoted text */
+					addlitchar(yytext[0]);
+				}
+<xdolq><<EOF>>	{ 
+					yylval.val.sep = dolqstart;
+					yylval.val.modificator = "dolqu";
+					yylval.val.str = litbufdup();
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_SCONST;
+				}
+
+{xdstart}		{
+					SET_YYLLOC();
+					BEGIN(xd);
+					startlit();
+				}
+<xd>{xdstop}	{
+					char		   *ident;
+
+					BEGIN(INITIAL);
+					if (literallen == 0)
+						yyerror("zero-length delimited identifier");
+					ident = litbufdup();
+					if (literallen >= NAMEDATALEN)
+						truncate_identifier(ident, literallen, true);
+					yylval.val.modificator = "dq";
+					yylval.val.str = ident;
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_IDENT;
+				}
+<xd>{xddouble}	{
+					addlitchar('"');
+				}
+<xd>{xdinside}	{
+					addlit(yytext, yyleng);
+				}
+<xd><<EOF>>		{ 
+					yylval.val.modificator = "dqu";
+					yylval.val.str = litbufdup();
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_IDENT;
+				}
+{typecast}		{
+					SET_YYLLOC();
+					yylval.val.modificator = "typecast";
+					yylval.val.keycode = X_TYPECAST;
+					yylval.val.sep = NULL;
+					return X_OTHERS;
+				}
+
+{self}			{
+					SET_YYLLOC();
+					yylval.val.str = yytext;
+					yylval.val.modificator = "self";
+					yylval.val.keycode = yytext[0];
+					yylval.val.sep = NULL;
+					return X_OTHERS;
+				}
+
+{operator}		{
+					/*
+					 * Check for embedded slash-star or dash-dash; those
+					 * are comment starts, so operator must stop there.
+					 * Note that slash-star or dash-dash at the first
+					 * character will match a prior rule, not this one.
+					 */
+					int		nchars = yyleng;
+					char   *slashstar = strstr(yytext, "/*");
+					char   *dashdash = strstr(yytext, "--");
+
+					if (slashstar && dashdash)
+					{
+						/* if both appear, take the first one */
+						if (slashstar > dashdash)
+							slashstar = dashdash;
+					}
+					else if (!slashstar)
+						slashstar = dashdash;
+					if (slashstar)
+						nchars = slashstar - yytext;
+
+					/*
+					 * For SQL compatibility, '+' and '-' cannot be the
+					 * last char of a multi-char operator unless the operator
+					 * contains chars that are not in SQL operators.
+					 * The idea is to lex '=-' as two operators, but not
+					 * to forbid operator names like '?-' that could not be
+					 * sequences of SQL operators.
+					 */
+					while (nchars > 1 &&
+						   (yytext[nchars-1] == '+' ||
+							yytext[nchars-1] == '-'))
+					{
+						int		ic;
+
+						for (ic = nchars-2; ic >= 0; ic--)
+						{
+							if (strchr("~!@#^&|`?%", yytext[ic]))
+								break;
+						}
+						if (ic >= 0)
+							break; /* found a char that makes it OK */
+						nchars--; /* else remove the +/-, and check again */
+					}
+
+					SET_YYLLOC();
+
+					if (nchars < yyleng)
+					{
+						/* Strip the unwanted chars from the token */
+						yyless(nchars);
+						/*
+						 * If what we have left is only one char, and it's
+						 * one of the characters matching "self", then
+						 * return it as a character token the same way
+						 * that the "self" rule would have.
+						 */
+						if (nchars == 1 &&
+							strchr(",()[].;:+-*/%^<>=", yytext[0]))
+						{
+							yylval.val.str = yytext;
+							yylval.val.modificator = NULL;
+							yylval.val.keycode = yytext[0];
+							yylval.val.sep = NULL;
+							return X_OTHERS;
+						}
+					}
+
+					/*
+					 * Complain if operator is too long.  Unlike the case
+					 * for identifiers, we make this an error not a notice-
+					 * and-truncate, because the odds are we are looking at
+					 * a syntactic mistake anyway.
+					 */
+					if (nchars >= NAMEDATALEN)
+						yyerror("operator too long");
+
+					/* Convert "!=" operator to "<>" for compatibility */
+					yylval.val.modificator = NULL;
+					if (strcmp(yytext, "!=") == 0)
+						yylval.val.str = pstrdup("<>");
+					else
+						yylval.val.str = pstrdup(yytext);
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_OP;
+				}
+
+{param}			{
+					SET_YYLLOC();
+					yylval.val.modificator = NULL;
+					yylval.val.str = yytext;
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_PARAM;
+				}
+
+{integer}		{
+					long val;
+					char* endptr;
+
+					SET_YYLLOC();
+					errno = 0;
+					val = strtol(yytext, &endptr, 10);
+					if (*endptr != '\0' || errno == ERANGE
+#ifdef HAVE_LONG_INT_64
+						/* if long > 32 bits, check for overflow of int4 */
+						|| val != (long) ((int32) val)
+#endif
+						)
+					{
+						/* integer too large, treat it as a float */
+						yylval.val.str = pstrdup(yytext);
+						yylval.val.modificator = "f";
+						yylval.val.keycode = -1;
+	    					yylval.val.sep = NULL;
+						return X_NCONST;
+					}
+					yylval.val.str = yytext;
+					yylval.val.modificator = "i";
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_NCONST;
+				}
+{decimal}		{
+					SET_YYLLOC();
+					yylval.val.str = pstrdup(yytext);
+					yylval.val.modificator = "f";
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_NCONST;
+				}
+{real}			{
+					SET_YYLLOC();
+					yylval.val.str = pstrdup(yytext);
+					yylval.val.modificator = "f";
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_NCONST;
+				}
+{realfail1}		{
+					/*
+					 * throw back the [Ee], and treat as {decimal}.  Note
+					 * that it is possible the input is actually {integer},
+					 * but since this case will almost certainly lead to a
+					 * syntax error anyway, we don't bother to distinguish.
+					 */
+					yyless(yyleng-1);
+					SET_YYLLOC();
+					yylval.val.str = pstrdup(yytext);
+					yylval.val.modificator = "f";
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_NCONST;
+				}
+{realfail2}		{
+					/* throw back the [Ee][+-], and proceed as above */
+					yyless(yyleng-2);
+					SET_YYLLOC();
+					yylval.val.str = pstrdup(yytext);
+					yylval.val.modificator = "f";
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_NCONST;
+				}
+
+
+{identifier}	{
+					const ScanKeyword *keyword;
+					char		   *ident;
+
+					SET_YYLLOC();
+
+					/* Is it a keyword? */
+					keyword = ScanKeywordLookup(yytext ScanKeywordLookupArgs);
+					if (keyword != NULL)
+					{
+						yylval.val.str = (char*) keyword->name;
+						yylval.val.keycode = keyword->value;
+						yylval.val.modificator = NULL;
+						yylval.val.sep = NULL;
+						return X_KEYWORD;
+					}
+
+					/*
+					 * No.  Convert the identifier to lower case, and truncate
+					 * if necessary.
+					 */
+					ident = downcase_truncate_identifier(yytext, yyleng, true);
+					yylval.val.str = ident;
+					yylval.val.modificator = NULL;
+					yylval.val.keycode = -1;
+					yylval.val.sep = NULL;
+					return X_IDENT;
+				}
+
+{other}			{
+					SET_YYLLOC();
+					yylval.val.str = yytext;
+					yylval.val.modificator = NULL;
+					yylval.val.keycode = yytext[0];
+					yylval.val.sep = NULL;
+					return X_OTHERS;
+				}
+
+<<EOF>>			{
+					SET_YYLLOC();
+					yyterminate();
+				}
+
+%%
+
+/*
+ * lexer_errposition
+ *		Report a lexical-analysis-time cursor position, if possible.
+ *
+ * This is expected to be used within an ereport() call.  The return value
+ * is a dummy (always 0, in fact).
+ *
+ * Note that this can only be used for messages from the lexer itself,
+ * since it depends on scanbuf to still be valid.
+ */
+static int
+lexer_errposition(void)
+{
+	int		pos;
+
+	/* Convert byte offset to character number */
+	pos = _pg_mbstrlen_with_len(scanbuf, yylloc) + 1;
+	/* And pass it to the ereport mechanism */
+	return errposition(pos);
+}
+
+/*
+ * yyerror
+ *		Report a lexer or grammar error.
+ *
+ * The message's cursor position identifies the most recently lexed token.
+ * This is OK for syntax error messages from the Bison parser, because Bison
+ * parsers report error as soon as the first unparsable token is reached.
+ * Beware of using yyerror for other purposes, as the cursor position might
+ * be misleading!
+ */
+void
+yyerror(const char *message)
+{
+	const char *loc = scanbuf + yylloc;
+
+	if (*loc == YY_END_OF_BUFFER_CHAR)
+	{
+		ereport(ERROR,
+				(errcode(ERRCODE_SYNTAX_ERROR),
+				 /* translator: %s is typically "syntax error" */
+				 errmsg("%s at end of input", _(message)),
+				 lexer_errposition()));
+	}
+	else
+	{
+		ereport(ERROR,
+				(errcode(ERRCODE_SYNTAX_ERROR),
+				 /* translator: first %s is typically "syntax error" */
+				 errmsg("%s at or near \"%s\"", _(message), loc),
+				 lexer_errposition()));
+	}
+}
+
+
+/*
+ * Called before any actual parsing is done
+ */
+void
+orafce_sql_scanner_init(const char *str)
+{
+	Size	slen = strlen(str);
+
+	/*
+	 * Might be left over after ereport()
+	 */
+	if (YY_CURRENT_BUFFER)
+		yy_delete_buffer(YY_CURRENT_BUFFER);
+
+	/*
+	 * Make a scan buffer with special termination needed by flex.
+	 */
+	scanbuflen = slen;
+	scanbuf = palloc(slen + 2);
+	memcpy(scanbuf, str, slen);
+	scanbuf[slen] = scanbuf[slen + 1] = YY_END_OF_BUFFER_CHAR;
+	scanbufhandle = yy_scan_buffer(scanbuf, slen + 2);
+
+	/* initialize literal buffer to a reasonable but expansible size */
+	literalalloc = 128;
+	literalbuf = (char *) palloc(literalalloc);
+	startlit();
+
+	BEGIN(INITIAL);
+}
+
+
+/*
+ * Called after parsing is done to clean up after fdate_scanner_init()
+ */
+void
+orafce_sql_scanner_finish(void)
+{
+	yy_delete_buffer(scanbufhandle);
+	pfree(scanbuf);
+}
+
+static void
+addlit(char *ytext, int yleng)
+{
+	/* enlarge buffer if needed */
+	if ((literallen+yleng) >= literalalloc)
+	{
+		do {
+			literalalloc *= 2;
+		} while ((literallen+yleng) >= literalalloc);
+		literalbuf = (char *) repalloc(literalbuf, literalalloc);
+	}
+	/* append new data, add trailing null */
+	memcpy(literalbuf+literallen, ytext, yleng);
+	literallen += yleng;
+	literalbuf[literallen] = '\0';
+}
+
+
+static void
+addlitchar(unsigned char ychar)
+{
+	/* enlarge buffer if needed */
+	if ((literallen+1) >= literalalloc)
+	{
+		literalalloc *= 2;
+		literalbuf = (char *) repalloc(literalbuf, literalalloc);
+	}
+	/* append new data, add trailing null */
+	literalbuf[literallen] = ychar;
+	literallen += 1;
+	literalbuf[literallen] = '\0';
+}
+
+
+/*
+ * One might be tempted to write pstrdup(literalbuf) instead of this,
+ * but for long literals this is much faster because the length is
+ * already known.
+ */
+static char *
+litbufdup(void)
+{
+	char *new;
+
+	new = palloc(literallen + 1);
+	memcpy(new, literalbuf, literallen+1);
+	return new;
+}
+
+
+static unsigned char
+unescape_single_char(unsigned char c)
+{
+	switch (c)
+	{
+		case 'b':
+			return '\b';
+		case 'f':
+			return '\f';
+		case 'n':
+			return '\n';
+		case 'r':
+			return '\r';
+		case 't':
+			return '\t';
+		default:
+			return c;
+	}
+}
+
+

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e74af545/contrib/orafce/tdhfunc.c
----------------------------------------------------------------------
diff --git a/contrib/orafce/tdhfunc.c b/contrib/orafce/tdhfunc.c
new file mode 100644
index 0000000..d03d81c
--- /dev/null
+++ b/contrib/orafce/tdhfunc.c
@@ -0,0 +1,81 @@
+/* 
+ * Hash three letter week days to some number. The TDH hash table makes this
+ * into a perfect hash for us. See generate_hash.c.
+ */
+static int
+tdhfunc(const char *s)
+{
+	int i = 0;
+	int ret = 0;
+
+	while (i < 3)
+	{
+		int out = 0;
+
+		switch (s[i])
+		{
+			case 'S':
+			case 's':
+				out += (int)'s';
+				break;
+			case 'U':
+			case 'u':
+				out += (int)'u';
+				break;
+			case 'N':
+			case 'n':
+				out += (int)'n';
+				break;
+			case 'M':
+			case 'm':
+				out += (int)'m';
+				break;
+			case 'O':
+			case 'o':
+				out += (int)'o';
+				break;
+			case 'T':
+			case 't':
+				out += (int)'t';
+				break;
+			case 'E':
+			case 'e':
+				out += (int)'e';
+				break;
+			case 'W':
+			case 'w':
+				out += (int)'w';
+				break;
+			case 'D':
+			case 'd':
+				out += (int)'d';
+				break;
+			case 'H':
+			case 'h':
+				out += (int)'h';
+				break;
+			case 'F':
+			case 'f':
+				out += (int)'f';
+				break;
+			case 'R':
+			case 'r':
+				out += (int)'r';
+				break;
+			case 'I':
+			case 'i':
+				out += (int)'i';
+				break;
+			case 'A':
+			case 'a':
+				out += (int)'a';
+				break;
+			default:
+				return -1;
+				break;
+		}
+		ret += out;
+		i++;
+	}
+	return ret;
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e74af545/contrib/orafce/uninstall_orafunc.full.sql
----------------------------------------------------------------------
diff --git a/contrib/orafce/uninstall_orafunc.full.sql b/contrib/orafce/uninstall_orafunc.full.sql
new file mode 100644
index 0000000..d894978
--- /dev/null
+++ b/contrib/orafce/uninstall_orafunc.full.sql
@@ -0,0 +1,152 @@
+DROP FUNCTION pg_catalog.trunc(value date, fmt text);
+DROP FUNCTION pg_catalog.round(value date, fmt text);
+DROP FUNCTION pg_catalog.next_day(value date, weekday text);
+DROP FUNCTION pg_catalog.last_day(value date);
+DROP FUNCTION pg_catalog.months_between(date1 date, date2 date);
+DROP FUNCTION pg_catalog.add_months(day date, value int);
+DROP FUNCTION pg_catalog.trunc(value timestamp with time zone, fmt text);
+DROP FUNCTION pg_catalog.round(value timestamp with time zone, fmt text);
+DROP FUNCTION pg_catalog.round(value timestamp with time zone);
+DROP FUNCTION pg_catalog.round(value date);
+DROP FUNCTION pg_catalog.trunc(value timestamp with time zone);
+DROP FUNCTION pg_catalog.trunc(value date);
+DROP FUNCTION pg_catalog.nlssort(text, text);
+DROP FUNCTION pg_catalog.nlssort(text);
+DROP FUNCTION pg_catalog.set_nls_sort(text);
+DROP FUNCTION pg_catalog.instr(str text, patt text, start int, nth int);
+DROP FUNCTION pg_catalog.instr(str text, patt text, start int);
+DROP FUNCTION pg_catalog.instr(str text, patt text);
+DROP FUNCTION pg_catalog.to_char(num int);
+DROP FUNCTION pg_catalog.to_char(num bigint);
+DROP FUNCTION pg_catalog.to_char(num real);
+DROP FUNCTION pg_catalog.to_char(num double precision);
+DROP FUNCTION pg_catalog.to_char(num numeric);
+DROP FUNCTION pg_catalog.to_number(str text);
+DROP FUNCTION pg_catalog.to_date(str text);
+DROP FUNCTION pg_catalog.reverse(str text);
+DROP FUNCTION pg_catalog.lnnvl(bool);
+
+DROP AGGREGATE pg_catalog.listagg(text);
+DROP AGGREGATE pg_catalog.listagg(text, text);
+
+DROP FUNCTION pg_catalog.listagg1_transfn(internal, text);
+DROP FUNCTION pg_catalog.listagg2_transfn(internal, text, text);
+DROP FUNCTION pg_catalog.listagg_finalfn(internal);
+
+DROP AGGREGATE pg_catalog.median(real);
+DROP AGGREGATE pg_catalog.median(double precision);
+
+DROP FUNCTION pg_catalog.median4_transfn(internal, real);
+DROP FUNCTION pg_catalog.median8_transfn(internal, double precision);
+DROP FUNCTION pg_catalog.median4_finalfn(internal);
+DROP FUNCTION pg_catalog.median8_finalfn(internal);
+
+DROP FUNCTION dump("any");
+DROP FUNCTION dump(text);
+DROP FUNCTION dump("any", integer);
+DROP FUNCTION dump(text, integer);
+
+DROP VIEW public.dual CASCADE;
+
+DROP FUNCTION nvl(anyelement, anyelement);
+DROP FUNCTION nvl2(anyelement, anyelement, anyelement);
+
+DROP FUNCTION concat(text, text);
+DROP FUNCTION concat(text, anyarray);
+DROP FUNCTION concat(anyarray, text);
+DROP FUNCTION concat(anyarray, anyarray);
+DROP FUNCTION concat(text, anynonarray);
+DROP FUNCTION concat(anynonarray, text);
+DROP FUNCTION concat(anynonarray, anynonarray);
+DROP FUNCTION concat(text, anyelement);
+DROP FUNCTION concat(anyelement, text);
+DROP FUNCTION concat(anyelement, anyelement);
+
+DROP FUNCTION bitand(bigint, bigint);
+DROP FUNCTION sinh(float8);
+DROP FUNCTION cosh(float8);
+DROP FUNCTION tanh(float8);
+DROP FUNCTION nanvl(float4, float4);
+DROP FUNCTION nanvl(float8, float8);
+DROP FUNCTION nanvl(numeric, numeric);
+DROP FUNCTION to_multi_byte(text);
+
+DROP FUNCTION decode(anyelement, anyelement, text);
+DROP FUNCTION decode(anyelement, anyelement, text, text);
+DROP FUNCTION decode(anyelement, anyelement, text, anyelement, text);
+DROP FUNCTION decode(anyelement, anyelement, text, anyelement, text, text);
+DROP FUNCTION decode(anyelement, anyelement, text, anyelement, text, anyelement, text);
+DROP FUNCTION decode(anyelement, anyelement, text, anyelement, text, anyelement, text, text);
+DROP FUNCTION decode(anyelement, anyelement, bpchar);
+DROP FUNCTION decode(anyelement, anyelement, bpchar, bpchar);
+DROP FUNCTION decode(anyelement, anyelement, bpchar, anyelement, bpchar);
+DROP FUNCTION decode(anyelement, anyelement, bpchar, anyelement, bpchar, bpchar);
+DROP FUNCTION decode(anyelement, anyelement, bpchar, anyelement, bpchar, anyelement, bpchar);
+DROP FUNCTION decode(anyelement, anyelement, bpchar, anyelement, bpchar, anyelement, bpchar, bpchar);
+DROP FUNCTION decode(anyelement, anyelement, integer);
+DROP FUNCTION decode(anyelement, anyelement, integer, integer);
+DROP FUNCTION decode(anyelement, anyelement, integer, anyelement, integer);
+DROP FUNCTION decode(anyelement, anyelement, integer, anyelement, integer, integer);
+DROP FUNCTION decode(anyelement, anyelement, integer, anyelement, integer, anyelement, integer);
+DROP FUNCTION decode(anyelement, anyelement, integer, anyelement, integer, anyelement, integer, integer);
+DROP FUNCTION decode(anyelement, anyelement, bigint);
+DROP FUNCTION decode(anyelement, anyelement, bigint, bigint);
+DROP FUNCTION decode(anyelement, anyelement, bigint, anyelement, bigint);
+DROP FUNCTION decode(anyelement, anyelement, bigint, anyelement, bigint, bigint);
+DROP FUNCTION decode(anyelement, anyelement, bigint, anyelement, bigint, anyelement, bigint);
+DROP FUNCTION decode(anyelement, anyelement, bigint, anyelement, bigint, anyelement, bigint, bigint);
+DROP FUNCTION decode(anyelement, anyelement, numeric);
+DROP FUNCTION decode(anyelement, anyelement, numeric, numeric);
+DROP FUNCTION decode(anyelement, anyelement, numeric, anyelement, numeric);
+DROP FUNCTION decode(anyelement, anyelement, numeric, anyelement, numeric, numeric);
+DROP FUNCTION decode(anyelement, anyelement, numeric, anyelement, numeric, anyelement, numeric);
+DROP FUNCTION decode(anyelement, anyelement, numeric, anyelement, numeric, anyelement, numeric, numeric);
+DROP FUNCTION decode(anyelement, anyelement, date);
+DROP FUNCTION decode(anyelement, anyelement, date, date);
+DROP FUNCTION decode(anyelement, anyelement, date, anyelement, date);
+DROP FUNCTION decode(anyelement, anyelement, date, anyelement, date, date);
+DROP FUNCTION decode(anyelement, anyelement, date, anyelement, date, anyelement, date);
+DROP FUNCTION decode(anyelement, anyelement, date, anyelement, date, anyelement, date, date);
+DROP FUNCTION decode(anyelement, anyelement, time);
+DROP FUNCTION decode(anyelement, anyelement, time, time);
+DROP FUNCTION decode(anyelement, anyelement, time, anyelement, time);
+DROP FUNCTION decode(anyelement, anyelement, time, anyelement, time, time);
+DROP FUNCTION decode(anyelement, anyelement, time, anyelement, time, anyelement, time);
+DROP FUNCTION decode(anyelement, anyelement, time, anyelement, time, anyelement, time, time);
+DROP FUNCTION decode(anyelement, anyelement, timestamp);
+DROP FUNCTION decode(anyelement, anyelement, timestamp, timestamp);
+DROP FUNCTION decode(anyelement, anyelement, timestamp, anyelement, timestamp);
+DROP FUNCTION decode(anyelement, anyelement, timestamp, anyelement, timestamp, timestamp);
+DROP FUNCTION decode(anyelement, anyelement, timestamp, anyelement, timestamp, anyelement, timestamp);
+DROP FUNCTION decode(anyelement, anyelement, timestamp, anyelement, timestamp, anyelement, timestamp, timestamp);
+DROP FUNCTION decode(anyelement, anyelement, timestamptz);
+DROP FUNCTION decode(anyelement, anyelement, timestamptz, timestamptz);
+DROP FUNCTION decode(anyelement, anyelement, timestamptz, anyelement, timestamptz);
+DROP FUNCTION decode(anyelement, anyelement, timestamptz, anyelement, timestamptz, timestamptz);
+DROP FUNCTION decode(anyelement, anyelement, timestamptz, anyelement, timestamptz, anyelement, timestamptz);
+DROP FUNCTION decode(anyelement, anyelement, timestamptz, anyelement, timestamptz, anyelement, timestamptz, timestamptz);
+
+DROP FUNCTION dbms_random.initialize();
+DROP FUNCTION dbms_random.normal();
+DROP FUNCTION dbms_random.random();
+DROP FUNCTION dbms_random.seed(integer);
+DROP FUNCTION dbms_random.seed(text);
+DROP FUNCTION dbms_random.string(opt text, len int);
+DROP FUNCTION dbms_random.terminate();
+DROP FUNCTION dbms_random.value(low double precision, high double precision);
+DROP FUNCTION dbms_random.value();
+
+DROP SCHEMA dbms_alert CASCADE;
+DROP SCHEMA dbms_assert CASCADE;
+DROP SCHEMA dbms_output CASCADE;
+DROP SCHEMA dbms_pipe CASCADE;
+DROP SCHEMA dbms_random CASCADE;
+DROP SCHEMA dbms_utility CASCADE;
+DROP SCHEMA oracle CASCADE;
+DROP SCHEMA plunit CASCADE;
+DROP SCHEMA plvchr CASCADE;
+DROP SCHEMA plvdate CASCADE;
+DROP SCHEMA plvlex CASCADE;
+DROP SCHEMA plvstr CASCADE;
+DROP SCHEMA plvsubst CASCADE;
+DROP SCHEMA utl_file CASCADE;

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e74af545/contrib/orafce/uninstall_orafunc.sql
----------------------------------------------------------------------
diff --git a/contrib/orafce/uninstall_orafunc.sql b/contrib/orafce/uninstall_orafunc.sql
new file mode 100644
index 0000000..142f73b
--- /dev/null
+++ b/contrib/orafce/uninstall_orafunc.sql
@@ -0,0 +1,61 @@
+-- Adjust the following if this is not the schema you installed into
+\set ORA_SCHEMA oracompat
+set search_path = :ORA_SCHEMA, pg_catalog;
+
+BEGIN;
+DROP FUNCTION IF EXISTS nvl(anyelement, anyelement);
+
+DROP FUNCTION IF EXISTS add_months(day date, value int);
+
+DROP FUNCTION IF EXISTS last_day(value date);
+
+DROP FUNCTION IF EXISTS next_day(value date, weekday text);
+DROP FUNCTION IF EXISTS next_day(value date, weekday integer);
+
+DROP FUNCTION IF EXISTS months_between(date1 date, date2 date);
+
+DROP FUNCTION IF EXISTS trunc(value date, fmt text);
+DROP FUNCTION IF EXISTS trunc(value timestamp with time zone, fmt text);
+DROP FUNCTION IF EXISTS trunc(value timestamp with time zone);
+DROP FUNCTION IF EXISTS trunc(value date);
+
+DROP FUNCTION IF EXISTS round(value timestamp with time zone, fmt text);
+DROP FUNCTION IF EXISTS round(value timestamp with time zone);
+DROP FUNCTION IF EXISTS round(value date);
+DROP FUNCTION IF EXISTS round(value date, fmt text);
+
+DROP FUNCTION IF EXISTS instr(str text, patt text, start int, nth int);
+DROP FUNCTION IF EXISTS instr(str text, patt text, start int);
+DROP FUNCTION IF EXISTS instr(str text, patt text);
+
+DROP FUNCTION IF EXISTS reverse(text, int, int);
+DROP FUNCTION IF EXISTS reverse(text, int);
+DROP FUNCTION IF EXISTS reverse(text);
+
+DROP FUNCTION IF EXISTS concat(text, text);
+DROP FUNCTION IF EXISTS concat(anyarray, text);
+DROP FUNCTION IF EXISTS concat(text, anyarray);
+DROP FUNCTION IF EXISTS concat(anyarray, anyarray);
+
+DROP FUNCTION IF EXISTS nanvl(float4, float4);
+DROP FUNCTION IF EXISTS nanvl(float8, float8);
+DROP FUNCTION IF EXISTS nanvl(numeric, numeric);
+
+DROP FUNCTION IF EXISTS bitand(bigint, bigint);
+
+DROP FUNCTION IF EXISTS listagg1_transfn(text, text);
+DROP FUNCTION IF EXISTS listagg2_transfn(text, text, text);
+
+DROP FUNCTION IF EXISTS nvl2(anyelement, anyelement, anyelement);
+
+DROP FUNCTION IF EXISTS lnnvl(bool);
+
+DROP FUNCTION IF EXISTS dump("any");
+DROP FUNCTION IF EXISTS dump("any", integer);
+
+DROP FUNCTION IF EXISTS nlssort(text, text);
+
+DROP FUNCTION IF EXISTS substr(text, int, int);
+DROP FUNCTION IF EXISTS substr(text, int);
+
+COMMIT;

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e74af545/contrib/orafce/utility.c
----------------------------------------------------------------------
diff --git a/contrib/orafce/utility.c b/contrib/orafce/utility.c
new file mode 100644
index 0000000..3b5b7be
--- /dev/null
+++ b/contrib/orafce/utility.c
@@ -0,0 +1,211 @@
+/*
+  This code implements one part of functonality of
+  free available library PL/Vision. Please look www.quest.com
+
+  Original author: Steven Feuerstein, 1996 - 2002
+  PostgreSQL implementation author: Pavel Stehule, 2006
+
+  This module is under BSD Licence
+
+  History:
+    1.0. first public version 22. September 2006
+
+*/
+
+#include "postgres.h"
+#include "utils/builtins.h"
+#include "utils/numeric.h"
+#include "string.h"
+#include "stdlib.h"
+#include "utils/pg_locale.h"
+#include "mb/pg_wchar.h"
+#include "lib/stringinfo.h"
+
+#include "catalog/pg_type.h"
+#include "libpq/pqformat.h"
+#include "utils/array.h"
+#include "utils/memutils.h"
+#include "utils/lsyscache.h"
+#include "access/tupmacs.h"
+#include "orafunc.h"
+#include "builtins.h"
+
+#include "utils/elog.h"
+
+PG_FUNCTION_INFO_V1(dbms_utility_format_call_stack0);
+PG_FUNCTION_INFO_V1(dbms_utility_format_call_stack1);
+
+static char*
+dbms_utility_format_call_stack(char mode)
+{
+	MemoryContext oldcontext = CurrentMemoryContext;
+	ErrorData *edata;
+	ErrorContextCallback *econtext;
+	StringInfo   sinfo;
+
+#ifdef GP_VERSION_NUM
+	errstart(ERROR, __FILE__, __LINE__, PG_FUNCNAME_MACRO, TEXTDOMAIN);
+#else
+#if PG_VERSION_NUM >= 80400
+	errstart(ERROR, __FILE__, __LINE__, PG_FUNCNAME_MACRO, TEXTDOMAIN);
+#else
+	errstart(ERROR, __FILE__, __LINE__, PG_FUNCNAME_MACRO);
+#endif
+#endif
+
+	MemoryContextSwitchTo(oldcontext);
+
+	for (econtext = error_context_stack;
+		 econtext != NULL;
+		 econtext = econtext->previous)
+		(*econtext->callback) (econtext->arg);
+
+	edata = CopyErrorData();
+
+	FlushErrorState();
+
+	/* Now I wont to parse edata->context to more traditional format */
+	/* I am not sure about order */
+
+	sinfo = makeStringInfo();
+
+	switch (mode)
+	{
+		case 'o':
+			appendStringInfoString(sinfo, "----- PL/pgSQL Call Stack -----\n");
+			appendStringInfoString(sinfo, "  object     line  object\n");
+			appendStringInfoString(sinfo, "  handle   number  name\n");
+			break;
+	}
+
+	if (edata->context)
+	{
+		char *start = edata->context;
+		while (*start)
+		{
+			char *oname =  "anonymous object";
+			char *line  = "";
+			char *eol = strchr(start, '\n');
+			Oid fnoid = InvalidOid;
+
+			/* first, solve multilines */
+			if (eol)
+				*eol = '\0';
+
+			/* first know format */
+			if (strncmp(start, "PL/pgSQL function ",18) == 0)
+			{
+				char *p1, *p2;
+
+				if ((p1 = strstr(start, "function \"")))
+				{
+					p1 += strlen("function \"");
+
+					if ((p2 = strchr(p1, '"')))
+					{
+						*p2++ = '\0';
+						oname = p1;
+						start = p2;
+					}
+				}
+				else if ((p1 = strstr(start, "function ")))
+				{
+					p1 += strlen("function ");
+
+					if ((p2 = strchr(p1, ')')))
+					{
+						char c = *++p2;
+						*p2 = '\0';
+
+						oname = pstrdup(p1);
+						fnoid = DatumGetObjectId(DirectFunctionCall1(regprocedurein,
+							CStringGetDatum(oname)));
+						*p2 = c;
+						start = p2;
+					}
+				}
+
+
+				if ((p1 = strstr(start, "line ")))
+				{
+					int p2i;
+					char c;
+
+					p1 += strlen("line ");
+					p2i = strspn(p1, "0123456789");
+
+					/* safe separator */
+					c = p1[p2i];
+
+					p1[p2i] = '\0';
+					line = pstrdup(p1);
+					p1[p2i] = c;
+
+					start = p1 + p2i;
+				}
+			}
+
+			switch (mode)
+			{
+				case 'o':
+					appendStringInfo(sinfo, "%8x    %5s  function %s", (int)fnoid, line, oname);
+					break;
+
+				case 'p':
+					appendStringInfo(sinfo, "%8d    %5s  function %s", (int)fnoid, line, oname);
+					break;
+
+				case 's':
+					appendStringInfo(sinfo, "%d,%s,%s", (int)fnoid, line, oname);
+					break;
+			}
+
+			if (eol)
+			{
+				start = eol + 1;
+				appendStringInfoChar(sinfo, '\n');
+			}
+			else
+				break;
+		}
+
+	}
+
+	return sinfo->data;
+}
+
+
+Datum
+dbms_utility_format_call_stack0(PG_FUNCTION_ARGS)
+{
+	PG_RETURN_TEXT_P(cstring_to_text(dbms_utility_format_call_stack('o')));
+};
+
+Datum
+dbms_utility_format_call_stack1(PG_FUNCTION_ARGS)
+{
+	text *arg = PG_GETARG_TEXT_P(0);
+	char mode;
+
+	if ((1 != VARSIZE(arg) - VARHDRSZ))
+		ereport(ERROR,
+			(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+			 errmsg("invalid parameter"),
+			 errdetail("Allowed only chars [ops].")));
+
+	mode = *VARDATA(arg);
+	switch (mode)
+	{
+		case 'o':
+		case 'p':
+		case 's':
+			break;
+		default:
+			ereport(ERROR,
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+				 errmsg("invalid parameter"),
+				 errdetail("Allowed only chars [ops].")));
+	}
+
+	PG_RETURN_TEXT_P(cstring_to_text(dbms_utility_format_call_stack(mode)));
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e74af545/src/bin/Makefile
----------------------------------------------------------------------
diff --git a/src/bin/Makefile b/src/bin/Makefile
index 54159a7..73425b9 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -13,7 +13,7 @@ subdir = src/bin
 top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
-DIRS = initdb ipcclean pg_ctl pg_dump \
+DIRS = initdb ipcclean pg_ctl pg_dump pgbench \
 	psql scripts pg_config pg_controldata pg_resetxlog \
 	gpfilesystem/hdfs gpupgrade \
 	gpfusion gp_workfile_mgr gpcheckhdfs gpfdist

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e74af545/src/bin/pgbench/.gitignore
----------------------------------------------------------------------
diff --git a/src/bin/pgbench/.gitignore b/src/bin/pgbench/.gitignore
new file mode 100644
index 0000000..929a08f
--- /dev/null
+++ b/src/bin/pgbench/.gitignore
@@ -0,0 +1 @@
+pgbench

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e74af545/src/bin/pgbench/.p4ignore
----------------------------------------------------------------------
diff --git a/src/bin/pgbench/.p4ignore b/src/bin/pgbench/.p4ignore
new file mode 100644
index 0000000..929a08f
--- /dev/null
+++ b/src/bin/pgbench/.p4ignore
@@ -0,0 +1 @@
+pgbench

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e74af545/src/bin/pgbench/Makefile
----------------------------------------------------------------------
diff --git a/src/bin/pgbench/Makefile b/src/bin/pgbench/Makefile
new file mode 100644
index 0000000..8b33b3c
--- /dev/null
+++ b/src/bin/pgbench/Makefile
@@ -0,0 +1,23 @@
+# $PostgreSQL: pgsql/contrib/pgbench/Makefile,v 1.16 2007/11/10 23:59:51 momjian Exp $
+
+PROGRAM = pgbench
+OBJS	= pgbench.o
+
+PG_CPPFLAGS = -I$(libpq_srcdir)
+PG_LIBS = $(libpq_pgport)
+
+ifdef USE_PGXS
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
+include $(PGXS)
+else
+subdir = src/bin/pgbench
+top_builddir = ../../..
+top_srcdir = $(top_builddir)/../cdb-pg
+include $(top_builddir)/src/Makefile.global
+include $(top_srcdir)/contrib/contrib-global.mk
+endif
+ifneq ($(PORTNAME), win32)
+override CFLAGS += $(PTHREAD_CFLAGS) -pthread
+endif
+