From 6ef48e657bd71d7e56844d7fdc6562dcbb7e62c1 Mon Sep 17 00:00:00 2001 From: Metin Doslu Date: Mon, 21 Mar 2016 16:12:13 -0700 Subject: [PATCH] Add expression context to evaluate default expressions --- src/backend/distributed/commands/multi_copy.c | 7 ++++- src/test/regress/input/multi_copy.source | 20 ++++++++++++++ src/test/regress/output/multi_copy.source | 27 +++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/backend/distributed/commands/multi_copy.c b/src/backend/distributed/commands/multi_copy.c index 7fa8fe80f..6ce4cd926 100644 --- a/src/backend/distributed/commands/multi_copy.c +++ b/src/backend/distributed/commands/multi_copy.c @@ -174,6 +174,7 @@ CitusCopyFrom(CopyStmt *copyStatement, char *completionTag) ErrorContextCallback errorCallback; CopyOutState copyOutState = NULL; FmgrInfo *columnOutputFunctions = NULL; + ExprContext *expressionContext = NULL; /* disallow COPY to/from file or program except for superusers */ if (copyStatement->filename != NULL && !superuser()) @@ -295,6 +296,9 @@ CitusCopyFrom(CopyStmt *copyStatement, char *completionTag) ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE); + expressionContext = CreateStandaloneExprContext(); + expressionContext->ecxt_per_tuple_memory = tupleContext; + copyOutState = (CopyOutState) palloc0(sizeof(CopyOutStateData)); copyOutState->binary = true; copyOutState->fe_msgbuf = makeStringInfo(); @@ -317,7 +321,8 @@ CitusCopyFrom(CopyStmt *copyStatement, char *completionTag) oldContext = MemoryContextSwitchTo(tupleContext); /* parse a row from the input */ - nextRowFound = NextCopyFrom(copyState, NULL, columnValues, columnNulls, NULL); + nextRowFound = NextCopyFrom(copyState, expressionContext, + columnValues,columnNulls, NULL); MemoryContextSwitchTo(oldContext); diff --git a/src/test/regress/input/multi_copy.source b/src/test/regress/input/multi_copy.source index 92544b9a8..17a6015a5 100644 --- a/src/test/regress/input/multi_copy.source +++ b/src/test/regress/input/multi_copy.source @@ -104,6 +104,26 @@ SELECT count(*) FROM customer_copy_hash; -- Confirm that data was copied SELECT count(*) FROM customer_copy_hash; +-- Create a new hash-partitioned table with default now() function +CREATE TABLE customer_with_default( + c_custkey integer, + c_name varchar(25) not null, + c_time timestamp default now()); + +SELECT master_create_distributed_table('customer_with_default', 'c_custkey', 'hash'); + +SELECT master_create_worker_shards('customer_with_default', 64, 1); + +-- Test with default values for now() function +COPY customer_with_default (c_custkey, c_name) FROM STDIN +WITH (FORMAT 'csv'); +1,customer1 +2,customer2 +\. + +-- Confirm that data was copied with now() function +SELECT count(*) FROM customer_with_default where c_time IS NOT NULL; + -- Create a new range-partitioned table into which to COPY CREATE TABLE customer_copy_range ( c_custkey integer, diff --git a/src/test/regress/output/multi_copy.source b/src/test/regress/output/multi_copy.source index 7edce8025..534675df7 100644 --- a/src/test/regress/output/multi_copy.source +++ b/src/test/regress/output/multi_copy.source @@ -126,6 +126,33 @@ SELECT count(*) FROM customer_copy_hash; 2006 (1 row) +-- Create a new hash-partitioned table with default now() function +CREATE TABLE customer_with_default( + c_custkey integer, + c_name varchar(25) not null, + c_time timestamp default now()); +SELECT master_create_distributed_table('customer_with_default', 'c_custkey', 'hash'); + master_create_distributed_table +--------------------------------- + +(1 row) + +SELECT master_create_worker_shards('customer_with_default', 64, 1); + master_create_worker_shards +----------------------------- + +(1 row) + +-- Test with default values for now() function +COPY customer_with_default (c_custkey, c_name) FROM STDIN +WITH (FORMAT 'csv'); +-- Confirm that data was copied with now() function +SELECT count(*) FROM customer_with_default where c_time IS NOT NULL; + count +------- + 2 +(1 row) + -- Create a new range-partitioned table into which to COPY CREATE TABLE customer_copy_range ( c_custkey integer,