Chinaunix首页 | 论坛 | 博客
  • 博客访问: 404612
  • 博文数量: 21
  • 博客积分: 5030
  • 博客等级: 大校
  • 技术积分: 1275
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-16 09:18
文章分类
文章存档

2012年(1)

2011年(6)

2010年(2)

2009年(1)

2008年(11)

我的朋友

分类: Java

2012-03-06 17:32:54

  1. /**
  2.  * Licensed to the Apache Software Foundation (ASF) under one
  3.  * or more contributor license agreements. See the NOTICE file
  4.  * distributed with this work for additional information
  5.  * regarding copyright ownership. The ASF licenses this file
  6.  * to you under the Apache License, Version 2.0 (the
  7.  * "License"); you may not use this file except in compliance
  8.  * with the License. You may obtain a copy of the License at
  9.  *
  10.  *
  11.  *
  12.  * Unless required by applicable law or agreed to in writing, software
  13.  * distributed under the License is distributed on an "AS IS" BASIS,
  14.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15.  * See the License for the specific language governing permissions and
  16.  * limitations under the License.
  17.  */
  18. package org.apache.hadoop.hive.contrib.udf.example;
  19.  
  20. import java.util.ArrayList;
  21. import java.util.Collections;
  22. import java.util.Map;
  23.  
  24. import org.apache.hadoop.hive.ql.exec.UDF;
  25.  
  26. public class UDFExampleMapConcat extends UDF {
  27.  
  28.   public String evaluate(Map<String, String> a) {
  29.     if (a == null) {
  30.       return null;
  31.     }
  32.     ArrayList<String> r = new ArrayList<String>(a.size());
  33.     for (Map.Entry<String,String> entry: a.entrySet()) {
  34.       r.add("(" + entry.getKey() + ":" + entry.getValue() + ")");
  35.     }
  36.     Collections.sort(r);
  37.      
  38.     StringBuilder sb = new StringBuilder();
  39.     for (int i = 0; i < r.size(); i++) {
  40.       sb.append(r.get(i));
  41.     }
  42.     return sb.toString();
  43.   }
  44.    
  45. }
阅读(2773) | 评论(0) | 转发(0) |
0

上一篇:如何提高团队开发速度

下一篇:没有了

给主人留下些什么吧!~~