improve odps support

This commit is contained in:
wenshao
2014-10-13 00:34:27 +08:00
parent 3c85ead1fa
commit ff3f6b76fa
6 changed files with 42 additions and 1 deletions
@@ -36,6 +36,7 @@ import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URL;
import java.nio.charset.Charset;
import java.security.AccessControlException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
@@ -171,6 +172,10 @@ public class ParserConfig {
} else {
asmFactory = new ASMDeserializerFactory(parentClassLoader);
}
} catch (ExceptionInInitializerError error) {
// skip
} catch (AccessControlException error) {
// skip
} catch (NoClassDefFoundError error) {
// skip
}
@@ -150,6 +150,8 @@ public class SerializeConfig extends IdentityHashMap<Type, ObjectSerializer> {
try {
asmFactory = new ASMSerializerFactory();
} catch (NoClassDefFoundError eror) {
asm = false;
} catch (ExceptionInInitializerError error) {
asm = false;
}
@@ -1,4 +1,4 @@
package com.alibaba.fastjson.support.odps;
package com.alibaba.fastjson.support.odps.udf;
import com.alibaba.fastjson.JSON;
import com.aliyun.odps.udf.UDF;
@@ -0,0 +1,19 @@
package com.alibaba.fastjson.support.odps.udf;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONPath;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.aliyun.odps.udf.UDF;
public class GetJSONObject extends UDF {
public GetJSONObject() {
// SerializeConfig.getGlobalInstance().setAsmEnable(false);
}
public String evaluate(String jsonString, String path) throws Exception {
Object json = JSON.parse(jsonString);
JSONPath json_path = new JSONPath(path);
Object result = json_path.eval(json);
return JSON.toJSONString(result);
}
}
@@ -0,0 +1,14 @@
package com.alibaba.json.bvt.odps;
import junit.framework.TestCase;
import com.alibaba.fastjson.support.odps.udf.GetJSONObject;
public class GetJSONObjectTest extends TestCase {
public void test_udf() throws Exception {
GetJSONObject udf = new GetJSONObject();
String result = udf.evaluate("{\"id\":123,\"name\":\"wenshao\"}", "$");
System.out.println(result);
}
}
@@ -18,6 +18,7 @@ public class JSONPath_list extends TestCase {
List list = new ArrayList();
list.add(map);
Assert.assertSame(map.get("val"), new JSONPath("$[0].val").eval(list));
Assert.assertSame(map.get("val"), new JSONPath("$[-1].val").eval(list));
}
}