[ https://issues.apache.org/jira/browse/PIG-3939?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14002376#comment-14002376 ]
Cheolsoo Park commented on PIG-3939: ------------------------------------ This is great! Few minor comments- # Your unit test case fails for me- {code} Testcase: testSPRINTF took 0.013 sec FAILED expected:<...993.142 1991-02-03T0[2:00:00-06]00> but was:<...993.142 1991-02-03T0[0:00:00-08]00> junit.framework.AssertionFailedError: expected:<...993.142 1991-02-03T0[2:00:00-06]00> but was:<...993.142 1991-02-03T0[0:00:00-08]00> at org.apache.pig.test.TestBuiltin.testSPRINTF(TestBuiltin.java:2469) {code} # A couple of java warnings in SPRINTF.java- * formatter is not closed. * Unused imports {code} import org.apache.pig.EvalFunc.SchemaType; import org.apache.pig.backend.executionengine.ExecException; {code} * Delete the following lines- {code} // List<FuncSpec> funcList = new ArrayList<FuncSpec>(); // Schema s = new Schema(); // s.add(new Schema.FieldSchema(null, DataType.CHARARRAY)); // s.add(new Schema.FieldSchema(null, DataType.CHARARRAY)); // funcList.add(new FuncSpec(this.getClass().getName(), s)); // return funcList; {code} > SPRINTF function to format strings using a printf-style template > ---------------------------------------------------------------- > > Key: PIG-3939 > URL: https://issues.apache.org/jira/browse/PIG-3939 > Project: Pig > Issue Type: New Feature > Components: impl, internal-udfs > Reporter: Philip (flip) Kromer > Assignee: Philip (flip) Kromer > Labels: builtin, formatted, function, string, udf > Attachments: > 0001-SPRINTF-function-to-format-strings-using-a-printf-st.patch > > > Pig should provide a function to format output using java.util.Formatter > (printf-style) templates. > {code} > SPRINTF( > '%6s|%-8s|%2$,10d %2$8x %3$1TFT%<tT%<tz', > 'yay', 1234567, ToMilliSeconds(CurrentTime())) > -- ' yay|1234567 | 1,234,567 12d687 2014-05-15T08:22:26-0500' > {code} > I've written a UDF implementing SPRINTF(...), a variable-arguments function > that accepts a string and any number of objects and returns a string. It > counts on the java.util.Formatter to do its type-conversion, which works > quite well. It doesn't appreciates pig's Dates for datetime formats ('%t'), > but is quite happy to use epoch milliseconds for these as shown above. > Patch forthcoming. -- This message was sent by Atlassian JIRA (v6.2#6252)