猪脚本替换\ with - in date函数

时间:2016-05-03 10:04:16

标签: hadoop apache-pig

我正在尝试编写一个日期为04/15/2016格式的猪脚本。我想将其转换为04-15-2016。我在下面做的时候得到了:

x=REPLACE(date,'\','-');
dump x;

我想知道写这个的正确方法。

谢谢, stacky

2 个答案:

答案 0 :(得分:0)

REPLACE中将该字段作为chararray投放。

REPLACE(string, 'oldChar', 'newChar');

X = FOREACH A GENERATE REPLACE((chararray)date,'/','-');
dump X;

答案 1 :(得分:0)

这应该有用。

public class JettySampleAsyncServer
{
public static class EmbeddedAsyncServlet extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
final AsyncContext ctxt = req.startAsync();

ctxt.start(new Runnable()
{
@Override
public void run()
{
System.out.println("In AsyncContext / Start / Runnable / run");
ServletResponse response=ctxt.getResponse();
byte[] result="<h1>Hello World</h1>".getBytes();
try {
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
response.setContentLength(result.length);
response.getOutputStream().write(result);

} catch (IOException e) {
e.printStackTrace();
}
ctxt.setTimeout(new Long(1000));
ctxt.complete();
}
});
}
}
public static void main(String[] args) throws Exception
{
Server server = new Server();
QueuedThreadPool queuedThreadPool=(QueuedThreadPool) server.getThreadPool();
queuedThreadPool.setMaxThreads(8);
ServerConnector serverConnector=new ServerConnector(server,1,4);
serverConnector.setHost("localhost");
serverConnector.setPort(9090);
//   serverConnector.setAcceptQueueSize(100);
server.addConnector(serverConnector);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
ServletHolder asyncHolder = context.addServlet(EmbeddedAsyncServlet.class,"/*");
asyncHolder.setAsyncSupported(true);
server.setHandler(context);
server.start();
server.join();
}
}