提交 3d625727 编写于 作者: D Daniel Gustafsson

Avoid comparing newline option twice

This refactors the code to remove the separate step for setting the
eol_type in CopyEolStrToType(), which induced a second pointless
pg_strcasecmp() on the passed NEWLINE string. This function did more
originally but upstream merges have made it redundant, and the
function is refers to has never been in the Greenlpum code at all.
Reviewed-by: NAsim R P <apraveen@pivotal.io>
上级 8682589d
......@@ -218,7 +218,6 @@ static void HandleQDErrorFrame(CopyState cstate);
static void CopyInitDataParser(CopyState cstate);
static void setEncodingConversionProc(CopyState cstate, int encoding, bool iswritable);
static void CopyEolStrToType(CopyState cstate);
static GpDistributionData *InitDistributionData(CopyState cstate, EState *estate);
static void FreeDistributionData(GpDistributionData *distData);
......@@ -1688,13 +1687,18 @@ ProcessCopyOptions(CopyState cstate,
}
else
{
if(pg_strcasecmp(cstate->eol_str, "lf") != 0 &&
pg_strcasecmp(cstate->eol_str, "cr") != 0 &&
pg_strcasecmp(cstate->eol_str, "crlf") != 0)
if (pg_strcasecmp(cstate->eol_str, "lf") == 0)
cstate->eol_type = EOL_NL;
else if (pg_strcasecmp(cstate->eol_str, "cr") == 0)
cstate->eol_type = EOL_CR;
else if (pg_strcasecmp(cstate->eol_str, "crlf") == 0)
cstate->eol_type = EOL_CRNL;
else
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("invalid value for NEWLINE (%s)", cstate->eol_str),
errhint("valid options are: 'LF', 'CRLF', 'CR'")));
errmsg("invalid value for NEWLINE \"%s\"",
cstate->eol_str),
errhint("Valid options are: 'LF', 'CRLF' and 'CR'.")));
}
}
......@@ -1702,10 +1706,6 @@ ProcessCopyOptions(CopyState cstate,
{
cstate->escape_off = true;
}
/* set end of line type if NEWLINE keyword was specified */
if (cstate->eol_str)
CopyEolStrToType(cstate);
}
/*
......@@ -7171,29 +7171,6 @@ setEncodingConversionProc(CopyState cstate, int encoding, bool iswritable)
}
}
static void
CopyEolStrToType(CopyState cstate)
{
if (pg_strcasecmp(cstate->eol_str, "lf") == 0)
{
cstate->eol_type = EOL_NL;
}
else if (pg_strcasecmp(cstate->eol_str, "cr") == 0)
{
cstate->eol_type = EOL_CR;
}
else if (pg_strcasecmp(cstate->eol_str, "crlf") == 0)
{
cstate->eol_type = EOL_CRNL;
}
else /* error. must have been validated in CopyValidateControlChars() ! */
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("internal error in CopySetEolType. Trying to set NEWLINE %s",
cstate->eol_str)));
}
static GpDistributionData *
InitDistributionData(CopyState cstate, EState *estate)
{
......
......@@ -510,8 +510,8 @@ CONTEXT: COPY copy_regression_newline, line 1: "1|1
"
-- negative: invalid newline
COPY copy_regression_newline from stdin with delimiter '|' newline 'blah';
ERROR: invalid value for NEWLINE (blah)
HINT: valid options are: 'LF', 'CRLF', 'CR'
ERROR: invalid value for NEWLINE "blah"
HINT: Valid options are: 'LF', 'CRLF' and 'CR'.
-- negative: newline not yet supported for COPY TO
COPY copy_regression_newline to stdout with delimiter '|' newline 'blah';
ERROR: newline currently available for data loading only, not unloading
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册