Skip to content
This repository has been archived by the owner on Jun 7, 2021. It is now read-only.

[TRAFODION-2680] Add CSV_FORMAT function to Trafodion SQL #1169

Closed
wants to merge 1 commit into from

Conversation

DaveBirdsall
Copy link
Contributor

This change adds a new function, CSV_FORMAT, to Trafodion SQL.

Syntax: CSV_FORMAT(argument1, ... ,argumentn)

Semantics: The result of CSV_FORMAT is a VARCHAR string consisting of a comma-separated list of the argument values. If the argument itself contains a comma, it is surrounded with double quotes.

This is a prototype for evaluation. For example, it does not escape double quotes within a double quoted string; the need for that is to be determined. Also, a regression test for this needs to be added.

@Traf-Jenkins
Copy link

Check Test Started: https://jenkins.esgyn.com/job/Check-PR-master/1926/

@Traf-Jenkins
Copy link

Copy link
Contributor

@zellerh zellerh left a comment

Choose a reason for hiding this comment

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

+1 looks good to me

}
}

strcpy(buf,"CASE WHEN POSITION(',' IN @A1) > 0 THEN '\"' || @A1 || '\"' ELSE @A1 END");
Copy link
Contributor

@zellerh zellerh Jul 13, 2017

Choose a reason for hiding this comment

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

You mention the current lack of handling of embedded double quotes. Those could be handled by adding a REPLACE(@A1, '"', '""') and always adding the enclosing double quotes. Also, since neither commas nor double quotes occur in booleans, datetimes, intervals, or numerics, would it be ok to apply this transformation on character types only?

Copy link
Contributor

Choose a reason for hiding this comment

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

One more thought: I think that in a CSV file, white space between fields is ignored. So, it may be best if this code adds a TRIM, so that the padding around fixed chars is not included.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Re: booleans and so on. I think you're right. I need to check if we have a European form of CAST that uses a comma for the decimal point for numbers. Will look into this.

Re: double quotes: Thanks very much for the tip. I need to do a little experimentation with Excel spreadsheets to see how they behave with double quotes. Then I'll make changes accordingly.

Re: white space: I wondered about that. I suspect programs such as Excel do ignore trailing white space (not sure about leading). Seems like adding TRIM would be redundant in that case? There is an aesthetic case to be made though in getting rid of the extra white space in the output.

// / \
// c d
//
// The code below traverses accordingly.
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a class ItemExprList that can convert such trees into a collection class. Other binder methods use that to traverse lists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, Hans. Will use that.

@DaveBirdsall
Copy link
Contributor Author

Please do not merge. I intend to take another approach (improving the CSV format feature in trafci). I will close this request when that approach is ready.

@DaveBirdsall
Copy link
Contributor Author

Closing this pull request. Will take another approach, as discussed in the JIRA.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants