Add expression context to evaluate default expressions

pull/390/head
Metin Doslu 2016-03-21 16:12:13 -07:00
parent 566a9462b8
commit 6ef48e657b
3 changed files with 53 additions and 1 deletions

View File

@ -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);

View File

@ -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,

View File

@ -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,