Skip to content

[Zeppelin-1001] Take care of comma/tab escape in csv/tsv download - #1445

Closed
meenakshisekar wants to merge 6 commits into
apache:masterfrom
meenakshisekar:ZEPPELIN-1001
Closed

[Zeppelin-1001] Take care of comma/tab escape in csv/tsv download#1445
meenakshisekar wants to merge 6 commits into
apache:masterfrom
meenakshisekar:ZEPPELIN-1001

Conversation

@meenakshisekar

Copy link
Copy Markdown
Contributor

What is this PR for?

When the data is downloaded as CSV/TSV, the comma/tab in the actual data has to be handled so that they come exactly as the same data when downloaded.

What type of PR is it?

[Bug Fix]

Todos

  • - Task

What is the Jira issue?

https://issues.apache.org/jira/browse/ZEPPELIN-1001

How should this be tested?

Modify the data to be loaded to have a comma.
Create a paragraph to pull up that data and display.
Now click on the download as CSV/TSV button in the tool bar.
Once the data is downloaded verify whether the original data is unaltered and the comma is escaped.

Screenshots (if appropriate)

Questions:

  • Does the licenses files need update? No
  • Is there breaking changes for older versions? No
  • Does this needs documentation? No

var dsvRow = '';
for (var index in row) {
dsvRow += row[index].value + delimiter;
var stringValue = (row[index].value).toString();

@felixcheungfelixcheungSep 23, 2016

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would need to handle other cases too. to quote here
"CSV implementations permit them, often by requiring " (double quote) characters around values that contain reserved characters (such as commas, double quotes, or less commonly, newlines). Embedded double quote characters may then be represented by a pair of consecutive double quotes,[10] or by prefixing an escape character such as a backslash (for example in Sybase Central)."

For instance, when the stringValue has " or \n

@corneadoug

Copy link
Copy Markdown
Contributor

@felixcheung So you want him to escape the " and \ from the string also?
Otherwise, I tested it, LGTM
CI is failing, but I think that if @meenakshisekar rebase his branch it might be green

@felixcheung

felixcheung commented Sep 23, 2016 via email

Copy link
Copy Markdown
Member

@corneadoug

Copy link
Copy Markdown
Contributor

@meenakshisekar Could you take care of that?

@meenakshisekar

meenakshisekar commented Sep 26, 2016

Copy link
Copy Markdown
ContributorAuthor

@corneadoug

I'm working towards that. Shall let you know once it is done.
Adding on further @corneadoug
I understand from the above conversation, that when the input to CSV contains double quote or \ it should be retained in the CSV file downloaded.

Confirm this understanding.
If the above is right, i see that the string and \ and " are already escaped when downloaded. I have attached a sample for your reference. Please let me know if you are expecting something different.

slash
doublequote

]

@meenakshisekar

meenakshisekar commented Sep 28, 2016

Copy link
Copy Markdown
ContributorAuthor

@corneadoug

Let me know in case of any issues or queries.

Thanks,
Meenakshi

@meenakshisekar

Copy link
Copy Markdown
ContributorAuthor

Re opening the pull request to run CI build.

@meenakshisekar

Copy link
Copy Markdown
ContributorAuthor

Re opening the pull request to run CI build.

@meenakshisekar

Copy link
Copy Markdown
ContributorAuthor

Re opening the pull request to run CI build.

@meenakshisekar

Copy link
Copy Markdown
ContributorAuthor

CI build passed!

@corneadoug

Copy link
Copy Markdown
Contributor

Tested using

%sh echo -e "%table name\tval\nhello\thello\you\"good\nhello2\theelow,world"

LGTM

dsvRow += row[index].value + delimiter;
var stringValue = (row[index].value).toString();
if (stringValue.contains(delimiter)) {
dsvRow += stringValue.replace(stringValue, '"' + stringValue + '"') + delimiter;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit odd? why don't we

dsvRow += '"' + stringValue + '"' + delimiter;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meenakshisekar actually agree with felix, same result, so better use the easy one

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@corneadoug

Have done the changes and committed. Please go ahead with merge.

@corneadoug

Copy link
Copy Markdown
Contributor

Merging if there is no more discussions

var stringValue = (row[index].value).toString();
if (stringValue.contains(delimiter)) {
dsvRow += '"' + stringValue + '"' + delimiter;
} else {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build is failing on indentation error here

@corneadoug

Copy link
Copy Markdown
Contributor

@meenakshisekar There is an indent error breaking the build, can you fix it?
Then, merging this one

@corneadoug

Copy link
Copy Markdown
Contributor

@meenakshisekar Could you fix the indent issue?
I want to merge #1469 but since its refactoring job, it would need to be rebased after yours

@meenakshisekar

Copy link
Copy Markdown
ContributorAuthor

@corneadoug
working on this

@corneadoug

Copy link
Copy Markdown
Contributor

Ci failure is irrelevant, Merging

@asfgitasfgit closed this in 3017730Oct 3, 2016
@corneadoug

Copy link
Copy Markdown
Contributor

@meenakshisekar Can you tell me your JIRA username?

@meenakshisekar

Copy link
Copy Markdown
ContributorAuthor

@corneadoug
My jira user name is meenakshisekar

@corneadoug

Copy link
Copy Markdown
Contributor

@meenakshisekar I can't find you with this username

@meenakshisekar

Copy link
Copy Markdown
ContributorAuthor

OOPS !
It is
meenakshi.chandrasekar@imaginea.com

asfgit pushed a commit that referenced this pull request Oct 6, 2016
### What is this PR for?
This PR backports #1445 to branch-0.6 since using `./dev/test_zeppelin_pr.py` throws alert for backporting it.
### What type of PR is it?
Bug Fix
Author: meenakshisekar <meenakshi.chandrasekar@imaginea.com>
Closes#1484 from minahlee/branch-0.6_ZEPPELIN-1001 and squashes the following commits:
58fda8e [meenakshisekar] Formatting errors corrected for build
f5c7f61 [meenakshisekar] Changes committed as per review comments in PR
e404075 [meenakshisekar] Altered the code as per PR suggestion 1465
574803c [meenakshisekar] Zeppelin-1001 Modified the data with comma/tab to be surronded by double quotes so that they are escaped.
pedrozatta pushed a commit to pedrozatta/zeppelin that referenced this pull request Oct 27, 2016
### What is this PR for?
When the data is downloaded as CSV/TSV, the comma/tab in the actual data has to be handled so that they come exactly as the same data when downloaded.
### What type of PR is it?
[Bug Fix]
### Todos
* [ ] - Task
### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-1001
### How should this be tested?
Modify the data to be loaded to have a comma.
Create a paragraph to pull up that data and display.
Now click on the download as CSV/TSV button in the tool bar.
Once the data is downloaded verify whether the original data is unaltered and the comma is escaped.
### Screenshots (if appropriate)
### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No
Author: meenakshisekar <meenakshi.chandrasekar@imaginea.com>
Closesapache#1445 from meenakshisekar/ZEPPELIN-1001 and squashes the following commits:
a4a2009 [meenakshisekar] Formatting errors corrected for build
5e14da8 [meenakshisekar] review comments fixed
ce27b82 [meenakshisekar] Changes committed as per review comments in PR
2f7d78a [meenakshisekar] Altered the code as per PR suggestion 1465
657dcbe [meenakshisekar] Zeppelin-1001 Modified the data with comma/tab to be surronded by double quotes so that they are escaped.
73b1868 [meenakshisekar] Zeppelin-1001 Modified the data with comma/tab to be surronded by double quotes so that they are escaped.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@meenakshisekar@corneadoug@felixcheung