You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hawq.apache.org by od...@apache.org on 2016/09/22 01:19:39 UTC

[1/4] incubator-hawq git commit: HAWQ-1048. Draft implementation.

Repository: incubator-hawq
Updated Branches:
  refs/heads/HAWQ-1048 [created] 0ff70373b


HAWQ-1048. Draft implementation.


Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/cd186f6f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/cd186f6f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/cd186f6f

Branch: refs/heads/HAWQ-1048
Commit: cd186f6fb3ab6bc74833ef5184da03f113ee7995
Parents: 981c0a9
Author: Oleksandr Diachenko <od...@pivotal.io>
Authored: Fri Sep 16 19:00:50 2016 -0700
Committer: Oleksandr Diachenko <od...@pivotal.io>
Committed: Fri Sep 16 19:00:50 2016 -0700

----------------------------------------------------------------------
 src/backend/access/external/pxffilters.c | 152 ++++++++++++--------------
 src/include/access/pxffilters.h          |   9 +-
 2 files changed, 80 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cd186f6f/src/backend/access/external/pxffilters.c
----------------------------------------------------------------------
diff --git a/src/backend/access/external/pxffilters.c b/src/backend/access/external/pxffilters.c
index 6767735..76e83b4 100644
--- a/src/backend/access/external/pxffilters.c
+++ b/src/backend/access/external/pxffilters.c
@@ -31,7 +31,7 @@
 #include "utils/guc.h"
 #include "utils/lsyscache.h"
 
-static List* pxf_make_filter_list(List* quals);
+static List* pxf_make_expression_items_list(List *quals);
 static void pxf_free_filter(PxfFilterDesc* filter);
 static void pxf_free_filter_list(List *filters);
 static char* pxf_serialize_filter_list(List *filters);
@@ -157,7 +157,7 @@ Oid pxf_supported_types[] =
 };
 
 /*
- * pxf_make_filter_list
+ * pxf_make_expression_items_list
  *
  * Given a scan node qual list, find the filters that are eligible to be used
  * by PXF, construct a PxfFilterDesc list that describes the filter information,
@@ -166,7 +166,7 @@ Oid pxf_supported_types[] =
  * Caller is responsible for pfreeing the returned PxfFilterDesc List.
  */
 static List *
-pxf_make_filter_list(List *quals)
+pxf_make_expression_items_list(List *quals)
 {
 	List			*result = NIL;
 	ListCell		*lc = NULL;
@@ -174,10 +174,6 @@ pxf_make_filter_list(List *quals)
 	if (list_length(quals) == 0)
 		return NIL;
 
-	/*
-	 * Iterate over all implicitly ANDed qualifiers and add the ones
-	 * that are supported for push-down into the result filter list.
-	 */
 	foreach (lc, quals)
 	{
 		Node *node = (Node *) lfirst(lc);
@@ -187,38 +183,19 @@ pxf_make_filter_list(List *quals)
 		{
 			case T_OpExpr:
 			{
-				OpExpr			*expr 	= (OpExpr *) node;
-				PxfFilterDesc	*filter;
-
-				filter = (PxfFilterDesc *) palloc0(sizeof(PxfFilterDesc));
-				elog(DEBUG5, "pxf_make_filter_list: node tag %d (T_OpExpr)", tag);
-
-				if (opexpr_to_pxffilter(expr, filter))
-					result = lappend(result, filter);
-				else
-					pfree(filter);
-
+				result = lappend(result, node);
 				break;
 			}
 			case T_BoolExpr:
 			{
 				BoolExpr	*expr = (BoolExpr *) node;
-				BoolExprType boolType = expr->boolop;
-				elog(DEBUG5, "pxf_make_filter_list: node tag %d (T_BoolExpr), bool node type %d %s",
-						tag, boolType, boolType==AND_EXPR ? "(AND_EXPR)" : "");
-
-				/* only AND_EXPR is supported */
-				if (expr->boolop == AND_EXPR)
-				{
-					List *inner_result = pxf_make_filter_list(expr->args);
-					elog(DEBUG5, "pxf_make_filter_list: inner result size %d", list_length(inner_result));
-					result = list_concat(result, inner_result);
-				}
+				List *inner_result = pxf_make_expression_items_list(expr->args);
+				result = list_concat(result, inner_result);
+				result = lappend(result, node);
 				break;
 			}
 			default:
-				/* expression not supported. ignore */
-				elog(DEBUG5, "pxf_make_filter_list: unsupported node tag %d", tag);
+				elog(DEBUG5, "pxf_make_expression_items_list: unsupported node tag %d", tag);
 				break;
 		}
 	}
@@ -297,19 +274,16 @@ pxf_free_filter_list(List *filters)
  *
  */
 static char *
-pxf_serialize_filter_list(List *filters)
+pxf_serialize_filter_list(List *expressionItems)
 {
 	StringInfo	 resbuf;
-	StringInfo	 curbuf;
 	ListCell	*lc = NULL;
 
-	if (list_length(filters) == 0)
+	if (list_length(expressionItems) == 0)
 		return NULL;
 
 	resbuf = makeStringInfo();
 	initStringInfo(resbuf);
-	curbuf = makeStringInfo();
-	initStringInfo(curbuf);
 
 	/*
 	 * Iterate through the filters in the list and serialize them one after
@@ -317,53 +291,71 @@ pxf_serialize_filter_list(List *filters)
 	 * typical small number of memcpy's this generates overall, there's no
 	 * point in optimizing, better keep it clear.
 	 */
-	foreach (lc, filters)
+	foreach (lc, expressionItems)
 	{
-		PxfFilterDesc		*filter	= (PxfFilterDesc *) lfirst(lc);
-		PxfOperand			 l		= filter->l;
-		PxfOperand			 r 		= filter->r;
-		PxfOperatorCode	 o 		= filter->op;
-
-		/* last result is stored in 'oldbuf'. start 'curbuf' clean */
-		resetStringInfo(curbuf);
-
-		/* format the operands */
-		if (pxfoperand_is_attr(l) && pxfoperand_is_const(r))
-		{
-			appendStringInfo(curbuf, "%c%d%c%s",
-									 PXF_ATTR_CODE, l.attnum - 1, /* Java attrs are 0-based */
-									 PXF_CONST_CODE, (r.conststr)->data);
-		}
-		else if (pxfoperand_is_const(l) && pxfoperand_is_attr(r))
-		{
-			appendStringInfo(curbuf, "%c%s%c%d",
-									 PXF_CONST_CODE, (l.conststr)->data,
-									 PXF_ATTR_CODE, r.attnum - 1); /* Java attrs are 0-based */
-		}
-		else
-		{
-			/* pxf_make_filter_list() should have never let this happen */
-			ereport(ERROR,
-					(errcode(ERRCODE_INTERNAL_ERROR),
-					 errmsg("internal error in pxffilters.c:pxf_serialize_"
-							 "filter_list. Found a non const+attr filter")));
-		}
-
-		/* format the operator */
-		appendStringInfo(curbuf, "%c%d", PXF_OPERATOR_CODE, o);
-
-		/* append this result to the previous result */
-		appendBinaryStringInfo(resbuf, curbuf->data, curbuf->len);
+		Node *node = (Node *) lfirst(lc);
+		NodeTag tag = nodeTag(node);
 
-		/* if there was a previous result, append a trailing AND operator */
-		if(resbuf->len > curbuf->len)
+		switch (tag)
 		{
-			appendStringInfo(resbuf, "%c%d", PXF_OPERATOR_CODE, PXFOP_AND);
+			case T_OpExpr:
+			{
+				PxfFilterDesc *filter = (PxfFilterDesc *) palloc0(sizeof(PxfFilterDesc));
+				OpExpr *expr = (OpExpr *) node;
+				if (opexpr_to_pxffilter(expr, filter))
+				{
+					PxfOperand l = filter->l;
+					PxfOperand r = filter->r;
+					PxfOperatorCode o = filter->op;
+					if (pxfoperand_is_attr(l) && pxfoperand_is_const(r))
+					{
+						appendStringInfo(resbuf, "%c%d%c%s",
+												 PXF_ATTR_CODE, l.attnum - 1, /* Java attrs are 0-based */
+												 PXF_CONST_CODE, (r.conststr)->data);
+					}
+					else if (pxfoperand_is_const(l) && pxfoperand_is_attr(r))
+					{
+						appendStringInfo(resbuf, "%c%s%c%d",
+												 PXF_CONST_CODE, (l.conststr)->data,
+												 PXF_ATTR_CODE, r.attnum - 1); /* Java attrs are 0-based */
+					}
+					else
+					{
+						/* pxf_make_filter_list() should have never let this happen */
+						ereport(ERROR,
+								(errcode(ERRCODE_INTERNAL_ERROR),
+								 errmsg("internal error in pxffilters.c:pxf_serialize_"
+										 "filter_list. Found a non const+attr filter")));
+					}
+					appendStringInfo(resbuf, "%c%d", PXF_OPERATOR_CODE, o);
+				}
+				else
+					pfree(filter);
+				break;
+			}
+			case T_BoolExpr:
+			{
+				BoolExpr *expr = (BoolExpr *) node;
+				BoolExprType boolType = expr->boolop;
+				PxfOperatorCode pxfOperandCode;
+				switch (boolType)
+				{
+					case AND_EXPR:
+						pxfOperandCode = PXFLOP_AND;
+						break;
+					case OR_EXPR:
+						pxfOperandCode = PXFLOP_OR;
+						break;
+					case NOT_EXPR:
+						pxfOperandCode = PXFLOP_NOT;
+						break;
+				}
+				appendStringInfo(resbuf, "%c%d", PXF_LOGICAL_OPERATOR_CODE, pxfOperandCode);
+				break;
+			}
 		}
 	}
 
-	pfree(curbuf->data);
-
 	return resbuf->data;
 }
 
@@ -626,10 +618,10 @@ char *serializePxfFilterQuals(List *quals)
 
 	if (pxf_enable_filter_pushdown)
 	{
-		List *filters = pxf_make_filter_list(quals);
 
-		result  = pxf_serialize_filter_list(filters);
-		pxf_free_filter_list(filters);
+		List *expressionItems = pxf_make_expression_items_list(quals);
+		result  = pxf_serialize_filter_list(expressionItems);
+		//pxf_free_filter_list(expressionItems);
 	}
 	elog(DEBUG2, "serializePxfFilterQuals: filter result: %s", (result == NULL) ? "null" : result);
 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/cd186f6f/src/include/access/pxffilters.h
----------------------------------------------------------------------
diff --git a/src/include/access/pxffilters.h b/src/include/access/pxffilters.h
index f54c47c..3e80944 100644
--- a/src/include/access/pxffilters.h
+++ b/src/include/access/pxffilters.h
@@ -44,11 +44,17 @@ typedef enum PxfOperatorCode
 	PXFOP_GE,
 	PXFOP_EQ,
 	PXFOP_NE,
-	PXFOP_AND,
 	PXFOP_LIKE
 
 } PxfOperatorCode;
 
+typedef enum PxfLogicalOperatorCode
+{
+	PXFLOP_AND = 0,
+	PXFLOP_OR,
+	PXFLOP_NOT,
+} PxfLogicalOperatorCode;
+
 /*
  * each supported operand from both sides of the operator is represented
  * by a code that will describe the operator type in the final serialized
@@ -57,6 +63,7 @@ typedef enum PxfOperatorCode
 #define PXF_ATTR_CODE		'a'
 #define PXF_CONST_CODE		'c'
 #define PXF_OPERATOR_CODE	'o'
+#define PXF_LOGICAL_OPERATOR_CODE	'l'
 
 /*
  * An Operand has any of the above codes, and the information specific to


[3/4] incubator-hawq git commit: HAWQ-1048. Updated comments.

Posted by od...@apache.org.
HAWQ-1048. Updated comments.


Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/7a9cc88d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/7a9cc88d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/7a9cc88d

Branch: refs/heads/HAWQ-1048
Commit: 7a9cc88df6b53bbe6cb9b6e5735f08da1a651a42
Parents: 7ef7e0f
Author: Oleksandr Diachenko <od...@pivotal.io>
Authored: Mon Sep 19 17:01:25 2016 -0700
Committer: Oleksandr Diachenko <od...@pivotal.io>
Committed: Mon Sep 19 17:01:25 2016 -0700

----------------------------------------------------------------------
 src/backend/access/external/pxffilters.c | 35 ++++++++-------------------
 src/include/access/pxffilters.h          |  7 ------
 2 files changed, 10 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7a9cc88d/src/backend/access/external/pxffilters.c
----------------------------------------------------------------------
diff --git a/src/backend/access/external/pxffilters.c b/src/backend/access/external/pxffilters.c
index bcd781c..0d1e1fa 100644
--- a/src/backend/access/external/pxffilters.c
+++ b/src/backend/access/external/pxffilters.c
@@ -159,10 +159,11 @@ Oid pxf_supported_types[] =
  * pxf_make_expression_items_list
  *
  * Given a scan node qual list, find the filters that are eligible to be used
- * by PXF, construct a PxfFilterDesc list that describes the filter information,
+ * by PXF, construct an expressions list, which consists of OpExpr or BoolExpr nodes
  * and return it to the caller.
  *
- * Caller is responsible for pfreeing the returned PxfFilterDesc List.
+ * Basically this function just transforms expression tree to Reversed Polish Notation list.
+ *
  */
 static List *
 pxf_make_expression_items_list(List *quals)
@@ -227,7 +228,7 @@ pxf_free_filter(PxfFilterDesc* filter)
 /*
  * pxf_serialize_filter_list
  *
- * Given a list of implicitly ANDed PxfFilterDesc objects, produce a
+ * Takes expression items list in RPN notation, produce a
  * serialized string representation in order to communicate this list
  * over the wire.
  *
@@ -239,9 +240,7 @@ pxf_free_filter(PxfFilterDesc* filter)
  *
  * Example filter list:
  *
- * Column(0) > 1
- * Column(0) < 5
- * Column(2) == "third"
+ * Column(0) > 1 AND Column(0) < 5 AND Column(2) == "third"
  *
  * Yields the following serialized string:
  *
@@ -261,10 +260,7 @@ pxf_serialize_filter_list(List *expressionItems)
 	initStringInfo(resbuf);
 
 	/*
-	 * Iterate through the filters in the list and serialize them one after
-	 * the other. We use buffer copying because it's clear. Considering the
-	 * typical small number of memcpy's this generates overall, there's no
-	 * point in optimizing, better keep it clear.
+	 * Iterate through the expression items in the list and serialize them one after the other.
 	 */
 	foreach (lc, expressionItems)
 	{
@@ -275,6 +271,7 @@ pxf_serialize_filter_list(List *expressionItems)
 		{
 			case T_OpExpr:
 			{
+				elog(DEBUG5, "pxf_serialize_filter_list: node tag %d (T_OpExpr)", tag);
 				PxfFilterDesc *filter = (PxfFilterDesc *) palloc0(sizeof(PxfFilterDesc));
 				OpExpr *expr = (OpExpr *) node;
 				if (opexpr_to_pxffilter(expr, filter))
@@ -296,7 +293,7 @@ pxf_serialize_filter_list(List *expressionItems)
 					}
 					else
 					{
-						/* pxf_make_filter_list() should have never let this happen */
+						/* opexpr_to_pxffilter() should have never let this happen */
 						ereport(ERROR,
 								(errcode(ERRCODE_INTERNAL_ERROR),
 								 errmsg("internal error in pxffilters.c:pxf_serialize_"
@@ -313,20 +310,8 @@ pxf_serialize_filter_list(List *expressionItems)
 			{
 				BoolExpr *expr = (BoolExpr *) node;
 				BoolExprType boolType = expr->boolop;
-				PxfOperatorCode pxfOperandCode;
-				switch (boolType)
-				{
-					case AND_EXPR:
-						pxfOperandCode = PXFLOP_AND;
-						break;
-					case OR_EXPR:
-						pxfOperandCode = PXFLOP_OR;
-						break;
-					case NOT_EXPR:
-						pxfOperandCode = PXFLOP_NOT;
-						break;
-				}
-				appendStringInfo(resbuf, "%c%d", PXF_LOGICAL_OPERATOR_CODE, pxfOperandCode);
+				elog(DEBUG5, "pxf_serialize_filter_list: node tag %d (T_BoolExpr), bool node type %d", tag, boolType);
+				appendStringInfo(resbuf, "%c%d", PXF_LOGICAL_OPERATOR_CODE, boolType);
 				break;
 			}
 		}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7a9cc88d/src/include/access/pxffilters.h
----------------------------------------------------------------------
diff --git a/src/include/access/pxffilters.h b/src/include/access/pxffilters.h
index 3e80944..a1cd661 100644
--- a/src/include/access/pxffilters.h
+++ b/src/include/access/pxffilters.h
@@ -48,13 +48,6 @@ typedef enum PxfOperatorCode
 
 } PxfOperatorCode;
 
-typedef enum PxfLogicalOperatorCode
-{
-	PXFLOP_AND = 0,
-	PXFLOP_OR,
-	PXFLOP_NOT,
-} PxfLogicalOperatorCode;
-
 /*
  * each supported operand from both sides of the operator is represented
  * by a code that will describe the operator type in the final serialized


[2/4] incubator-hawq git commit: HAWQ-1048. Added free logic.

Posted by od...@apache.org.
HAWQ-1048. Added free logic.


Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/7ef7e0fb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/7ef7e0fb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/7ef7e0fb

Branch: refs/heads/HAWQ-1048
Commit: 7ef7e0fbfe332d28755175045b1835f5c1117e25
Parents: cd186f6
Author: Oleksandr Diachenko <od...@pivotal.io>
Authored: Mon Sep 19 14:05:22 2016 -0700
Committer: Oleksandr Diachenko <od...@pivotal.io>
Committed: Mon Sep 19 14:05:22 2016 -0700

----------------------------------------------------------------------
 src/backend/access/external/pxffilters.c | 31 +++------------------------
 1 file changed, 3 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7ef7e0fb/src/backend/access/external/pxffilters.c
----------------------------------------------------------------------
diff --git a/src/backend/access/external/pxffilters.c b/src/backend/access/external/pxffilters.c
index 76e83b4..bcd781c 100644
--- a/src/backend/access/external/pxffilters.c
+++ b/src/backend/access/external/pxffilters.c
@@ -33,7 +33,6 @@
 
 static List* pxf_make_expression_items_list(List *quals);
 static void pxf_free_filter(PxfFilterDesc* filter);
-static void pxf_free_filter_list(List *filters);
 static char* pxf_serialize_filter_list(List *filters);
 static bool opexpr_to_pxffilter(OpExpr *expr, PxfFilterDesc *filter);
 static bool supported_filter_type(Oid type);
@@ -226,30 +225,6 @@ pxf_free_filter(PxfFilterDesc* filter)
 }
 
 /*
- * pxf_free_filter_list
- *
- * free all memory associated with the filters once no longer needed.
- * alternatively we could have allocated them in a shorter lifespan
- * memory context, however explicitly freeing them is easier and makes
- * more sense.
- */
-static void
-pxf_free_filter_list(List *filters)
-{
-	ListCell		*lc 	= NULL;
-	PxfFilterDesc 	*filter = NULL;
-
-	if (list_length(filters) == 0)
-		return;
-
-	foreach (lc, filters)
-	{
-		filter	= (PxfFilterDesc *) lfirst(lc);
-		pxf_free_filter(filter);
-	}
-}
-
-/*
  * pxf_serialize_filter_list
  *
  * Given a list of implicitly ANDed PxfFilterDesc objects, produce a
@@ -328,9 +303,10 @@ pxf_serialize_filter_list(List *expressionItems)
 										 "filter_list. Found a non const+attr filter")));
 					}
 					appendStringInfo(resbuf, "%c%d", PXF_OPERATOR_CODE, o);
-				}
-				else
+					pxf_free_filter(filter);
+				} else{
 					pfree(filter);
+				}
 				break;
 			}
 			case T_BoolExpr:
@@ -621,7 +597,6 @@ char *serializePxfFilterQuals(List *quals)
 
 		List *expressionItems = pxf_make_expression_items_list(quals);
 		result  = pxf_serialize_filter_list(expressionItems);
-		//pxf_free_filter_list(expressionItems);
 	}
 	elog(DEBUG2, "serializePxfFilterQuals: filter result: %s", (result == NULL) ? "null" : result);
 


[4/4] incubator-hawq git commit: HAWQ-1048. Return NULL instead of empty string.

Posted by od...@apache.org.
HAWQ-1048. Return NULL instead of empty string.


Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/0ff70373
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/0ff70373
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/0ff70373

Branch: refs/heads/HAWQ-1048
Commit: 0ff70373b3b700028892c72fd9e1fb516bbcaa25
Parents: 7a9cc88
Author: Oleksandr Diachenko <od...@pivotal.io>
Authored: Wed Sep 21 18:19:18 2016 -0700
Committer: Oleksandr Diachenko <od...@pivotal.io>
Committed: Wed Sep 21 18:19:18 2016 -0700

----------------------------------------------------------------------
 src/backend/access/external/pxffilters.c | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0ff70373/src/backend/access/external/pxffilters.c
----------------------------------------------------------------------
diff --git a/src/backend/access/external/pxffilters.c b/src/backend/access/external/pxffilters.c
index 0d1e1fa..8c3864d 100644
--- a/src/backend/access/external/pxffilters.c
+++ b/src/backend/access/external/pxffilters.c
@@ -317,6 +317,12 @@ pxf_serialize_filter_list(List *expressionItems)
 		}
 	}
 
+	if (resbuf->len == 0)
+	{
+		pfree(resbuf->data);
+		return NULL;
+	}
+
 	return resbuf->data;
 }