hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gcara...@apache.org
Subject incubator-hawq git commit: HAWQ 403 - Fix nested decode expression
Date Thu, 11 Feb 2016 21:59:09 GMT
Repository: incubator-hawq
Updated Branches:
  refs/heads/master 3426cb0e3 -> e424ad49e


HAWQ 403 - Fix nested decode expression


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

Branch: refs/heads/master
Commit: e424ad49e3a3ad9264cdca2f257ec6b432f806b0
Parents: 3426cb0
Author: Karthikeyan Jambu Rajaraman <krajaraman@pivotal.io>
Authored: Mon Feb 8 15:39:49 2016 -0800
Committer: Karthikeyan Jambu Rajaraman <krajaraman@pivotal.io>
Committed: Thu Feb 11 13:41:08 2016 -0800

----------------------------------------------------------------------
 src/backend/executor/execQual.c                | 12 +++++++++-
 src/test/regress/expected/nested_case_null.out | 25 +++++++++++++++++++++
 src/test/regress/known_good_schedule           |  1 +
 src/test/regress/sql/nested_case_null.sql      | 24 ++++++++++++++++++++
 4 files changed, 61 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e424ad49/src/backend/executor/execQual.c
----------------------------------------------------------------------
diff --git a/src/backend/executor/execQual.c b/src/backend/executor/execQual.c
index 4af8b55..79d8345 100644
--- a/src/backend/executor/execQual.c
+++ b/src/backend/executor/execQual.c
@@ -3128,10 +3128,20 @@ ExecEvalCase(CaseExprState *caseExpr, ExprContext *econtext,
 
 	if (caseExpr->arg)
 	{
+		/*
+		 * caseValue_datum and caseValue_isNull from econtext store the results of case
+		 * expression. caseValue_isNull will be true if caseValue_datum store null value.
+		 * Both caseValue_datum and caseValue_isNull should change at same time and they shouldn't
+		 * go out of sync.
+		 * Hence pass temporary variable(caseValue_isNull) and once evaluation is done,
+		 * update the caseValue_isNull from econtext.
+		 */
+		bool caseValue_isNull = false;
 		econtext->caseValue_datum = ExecEvalExpr(caseExpr->arg,
 												 econtext,
-												 &econtext->caseValue_isNull,
+												 &caseValue_isNull,
 												 NULL);
+		econtext->caseValue_isNull = caseValue_isNull;
 	}
 
 	/*

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e424ad49/src/test/regress/expected/nested_case_null.out
----------------------------------------------------------------------
diff --git a/src/test/regress/expected/nested_case_null.out b/src/test/regress/expected/nested_case_null.out
new file mode 100644
index 0000000..2374549
--- /dev/null
+++ b/src/test/regress/expected/nested_case_null.out
@@ -0,0 +1,25 @@
+---
+--- Drop existing table
+---
+DROP TABLE IF EXISTS t;
+---
+--- Create new table t
+---
+CREATE TABLE t(pid INT, wid INT, state CHARACTER VARYING(30));
+---
+--- Insert a row and keep state as empty
+---
+INSERT INTO t VALUES(1, 1);
+---
+--- use nested decode
+---
+SELECT DECODE(DECODE(state, '', NULL, state), '-', NULL, state) AS state FROM t;
+ state 
+-------
+ 
+(1 row)
+
+---
+--- Drop table
+---
+DROP TABLE t;

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e424ad49/src/test/regress/known_good_schedule
----------------------------------------------------------------------
diff --git a/src/test/regress/known_good_schedule b/src/test/regress/known_good_schedule
index 4272916..cde5a4c 100755
--- a/src/test/regress/known_good_schedule
+++ b/src/test/regress/known_good_schedule
@@ -76,6 +76,7 @@ ignore: triggers
 ignore: create_misc
 test: create_aggregate
 test: aggregate_with_groupingsets
+test: nested_case_null
 ignore: create_operator
 ignore: create_index
 ignore: drop_if_exists

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e424ad49/src/test/regress/sql/nested_case_null.sql
----------------------------------------------------------------------
diff --git a/src/test/regress/sql/nested_case_null.sql b/src/test/regress/sql/nested_case_null.sql
new file mode 100644
index 0000000..e3f1d24
--- /dev/null
+++ b/src/test/regress/sql/nested_case_null.sql
@@ -0,0 +1,24 @@
+---
+--- Drop existing table
+---
+DROP TABLE IF EXISTS t;
+
+---
+--- Create new table t
+---
+CREATE TABLE t(pid INT, wid INT, state CHARACTER VARYING(30));
+
+---
+--- Insert a row and keep state as empty
+---
+INSERT INTO t VALUES(1, 1);
+
+---
+--- use nested decode
+---
+SELECT DECODE(DECODE(state, '', NULL, state), '-', NULL, state) AS state FROM t;
+
+---
+--- Drop table
+---
+DROP TABLE t;
\ No newline at end of file


Mime
View raw message