-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Roberto Congiu
committed
May 29, 2014
1 parent
5c303d8
commit bc10f2a
Showing
112 changed files
with
1,685 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<parent> | ||
<groupId>org.openx.data</groupId> | ||
<artifactId>json-serde</artifactId> | ||
<relativePath>../pom.xml</relativePath> | ||
<version>1.2-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.openx.data</groupId> | ||
<artifactId>json-serde-cdh4-shim</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>json-cdh4-shim</name> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.openx.data</groupId> | ||
<artifactId>json</artifactId> | ||
<version>${project.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.hive</groupId> | ||
<artifactId>hive-serde</artifactId> | ||
<version>${cdh.hive.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.hive</groupId> | ||
<artifactId>hive-exec</artifactId> | ||
<version>${cdh.hive.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.hadoop</groupId> | ||
<artifactId>hadoop-common</artifactId> | ||
<version>${cdh.hadoop.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> | ||
|
||
|
||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
Binary file added
BIN
+3.63 KB
...4-shim/target/classes/org/openx/data/jsonserde/objectinspector/JSONObjectMapAdapter.class
Binary file not shown.
Binary file added
BIN
+1.63 KB
...him/target/classes/org/openx/data/jsonserde/objectinspector/JsonListObjectInspector.class
Binary file not shown.
Binary file added
BIN
+1.72 KB
...shim/target/classes/org/openx/data/jsonserde/objectinspector/JsonMapObjectInspector.class
Binary file not shown.
Binary file added
BIN
+1.19 KB
...arget/classes/org/openx/data/jsonserde/objectinspector/JsonObjectInspectorFactory$1.class
Binary file not shown.
Binary file added
BIN
+8.22 KB
.../target/classes/org/openx/data/jsonserde/objectinspector/JsonObjectInspectorFactory.class
Binary file not shown.
Binary file added
BIN
+2.5 KB
...rget/classes/org/openx/data/jsonserde/objectinspector/JsonStringJavaObjectInspector.class
Binary file not shown.
Binary file added
BIN
+1.32 KB
...h4-shim/target/classes/org/openx/data/jsonserde/objectinspector/JsonStructOIOptions.class
Binary file not shown.
Binary file added
BIN
+3.67 KB
...m/target/classes/org/openx/data/jsonserde/objectinspector/JsonStructObjectInspector.class
Binary file not shown.
Binary file added
BIN
+3.21 KB
...es/org/openx/data/jsonserde/objectinspector/primitive/JavaStringByteObjectInspector.class
Binary file not shown.
Binary file added
BIN
+2.01 KB
.../org/openx/data/jsonserde/objectinspector/primitive/JavaStringDoubleObjectInspector.class
Binary file not shown.
Binary file added
BIN
+2 KB
...s/org/openx/data/jsonserde/objectinspector/primitive/JavaStringFloatObjectInspector.class
Binary file not shown.
Binary file added
BIN
+2.06 KB
...ses/org/openx/data/jsonserde/objectinspector/primitive/JavaStringIntObjectInspector.class
Binary file not shown.
Binary file added
BIN
+2.06 KB
...es/org/openx/data/jsonserde/objectinspector/primitive/JavaStringLongObjectInspector.class
Binary file not shown.
Binary file added
BIN
+2.08 KB
...s/org/openx/data/jsonserde/objectinspector/primitive/JavaStringShortObjectInspector.class
Binary file not shown.
Binary file added
BIN
+3.08 KB
...g/openx/data/jsonserde/objectinspector/primitive/JavaStringTimestampObjectInspector.class
Binary file not shown.
Binary file added
BIN
+1.87 KB
...rget/classes/org/openx/data/jsonserde/objectinspector/primitive/ParsePrimitiveUtils.class
Binary file not shown.
Binary file added
BIN
+1.88 KB
json-serde-cdh4-shim/target/json-serde-cdh4-shim-1.2-SNAPSHOT-tests.jar
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#Generated by Maven | ||
#Wed May 28 18:04:55 PDT 2014 | ||
version=1.2-SNAPSHOT | ||
groupId=org.openx.data | ||
artifactId=json-serde-cdh4-shim |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<parent> | ||
<groupId>org.openx.data</groupId> | ||
<artifactId>json-serde</artifactId> | ||
<relativePath>../pom.xml</relativePath> | ||
<version>1.2-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.openx.data</groupId> | ||
<artifactId>json-serde-cdh5-shim</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>json-cdh5-shim</name> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.openx.data</groupId> | ||
<artifactId>json</artifactId> | ||
<version>${project.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
|
||
<dependency> | ||
<groupId>org.apache.hive</groupId> | ||
<artifactId>hive-serde</artifactId> | ||
<version>${cdh.hive.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.hive</groupId> | ||
<artifactId>hive-exec</artifactId> | ||
<version>${cdh.hive.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.hadoop</groupId> | ||
<artifactId>hadoop-common</artifactId> | ||
<version>${cdh.hadoop.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> | ||
|
||
|
||
|
155 changes: 155 additions & 0 deletions
155
...dh5-shim/src/main/java/org/openx/data/jsonserde/objectinspector/JSONObjectMapAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/*======================================================================* | ||
* Copyright (c) 2011, OpenX Technologies, Inc. All rights reserved. * | ||
* * | ||
* Licensed under the New BSD License (the "License"); you may not use * | ||
* this file except in compliance with the License. Unless required * | ||
* by applicable law or agreed to in writing, software distributed * | ||
* under the License is distributed on an "AS IS" BASIS, WITHOUT * | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | ||
* See the License for the specific language governing permissions and * | ||
* limitations under the License. See accompanying LICENSE file. * | ||
*======================================================================*/ | ||
|
||
package org.openx.data.jsonserde.objectinspector; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import org.openx.data.jsonserde.json.JSONException; | ||
import org.openx.data.jsonserde.json.JSONObject; | ||
|
||
/** | ||
* JSONObject is technically different from a map, since a json object | ||
* has string keys and values can be of any kind, while hive could | ||
* define a column as map<string,string>. This consistency is left | ||
* to the user to satisfy. | ||
* | ||
* Since we want to present a map, and we don't want to extract keys | ||
* and values every time, we keep a cache | ||
* | ||
* @author rcongiu | ||
*/ | ||
/* TODO: having an initialize() that copies everything into a map is expensive | ||
and won't work well for large maps. Good enough for now since | ||
we seldom - if ever - use maps. */ | ||
public class JSONObjectMapAdapter implements Map { | ||
HashMap cache; | ||
JSONObject jsonObject; | ||
|
||
public JSONObjectMapAdapter(JSONObject obj) { | ||
jsonObject = obj; | ||
initialize(); | ||
} | ||
|
||
public JSONObjectMapAdapter() { | ||
|
||
} | ||
|
||
public JSONObject getJSONObject() { | ||
return jsonObject; | ||
} | ||
|
||
public void setJSONObject(JSONObject jsonObject) { | ||
this.jsonObject = jsonObject; | ||
initialize(); | ||
} | ||
|
||
|
||
|
||
@Override | ||
public int size() { | ||
return jsonObject.length(); | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return cache.isEmpty(); | ||
} | ||
|
||
protected final void initialize() { | ||
if(cache==null) cache = new HashMap(); | ||
|
||
for(Iterator<String> i = jsonObject.keys(); i.hasNext(); ) { | ||
String o = i.next(); | ||
try { | ||
cache.put(o, safeGet(o)); | ||
} catch (JSONException ex) { | ||
// if key does not exist - should not happen | ||
throw new RuntimeException("Non existent key - should never happen!"); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* sanitize all the JSONObject.NULL converting them to nulls. | ||
* @param s | ||
* @return | ||
* @throws JSONException | ||
*/ | ||
private Object safeGet(String s) throws JSONException { | ||
if(s == null) return null; | ||
Object obj = jsonObject.get(s); | ||
if(JSONObject.NULL.equals(obj)) { | ||
return null; | ||
} else { | ||
return obj; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean containsKey(Object key) { | ||
return cache.containsKey(key); | ||
} | ||
|
||
@Override | ||
public boolean containsValue(Object value) { | ||
return cache.containsValue(value); | ||
} | ||
|
||
@Override | ||
public Object get(Object key) { | ||
return cache.get(key); | ||
} | ||
|
||
@Override | ||
public Object put(Object key, Object value) { | ||
return cache.put(key,value); | ||
} | ||
|
||
@Override | ||
public Object remove(Object key) { | ||
return cache.remove(key); | ||
} | ||
|
||
@Override | ||
public void putAll(Map m) { | ||
cache.putAll(m); | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
cache.clear(); | ||
} | ||
|
||
@Override | ||
public Set keySet() { | ||
return cache.keySet(); | ||
} | ||
|
||
@Override | ||
public Collection values() { | ||
return cache.values(); | ||
} | ||
|
||
@Override | ||
public Set entrySet() { | ||
return cache.entrySet(); | ||
} | ||
|
||
public Map<?, ?> getMap() { | ||
return cache; | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
...-shim/src/main/java/org/openx/data/jsonserde/objectinspector/JsonListObjectInspector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/*======================================================================* | ||
* Copyright (c) 2011, OpenX Technologies, Inc. All rights reserved. * | ||
* * | ||
* Licensed under the New BSD License (the "License"); you may not use * | ||
* this file except in compliance with the License. Unless required * | ||
* by applicable law or agreed to in writing, software distributed * | ||
* under the License is distributed on an "AS IS" BASIS, WITHOUT * | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | ||
* See the License for the specific language governing permissions and * | ||
* limitations under the License. See accompanying LICENSE file. * | ||
*======================================================================*/ | ||
|
||
package org.openx.data.jsonserde.objectinspector; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; | ||
import org.apache.hadoop.hive.serde2.objectinspector.StandardListObjectInspector; | ||
import org.openx.data.jsonserde.json.JSONArray; | ||
import org.openx.data.jsonserde.json.JSONException; | ||
import org.openx.data.jsonserde.json.JSONObject; | ||
|
||
/** | ||
* | ||
* @author rcongiu | ||
*/ | ||
public class JsonListObjectInspector extends StandardListObjectInspector { | ||
|
||
JsonListObjectInspector(ObjectInspector listElementObjectInspector) { | ||
super(listElementObjectInspector); | ||
} | ||
|
||
@Override | ||
public List<?> getList(Object data) { | ||
if (data == null || JSONObject.NULL.equals(data)) { | ||
return null; | ||
} | ||
JSONArray array = (JSONArray) data; | ||
List al = new ArrayList(array.length()); | ||
for(int i =0; i< array.length(); i++) { | ||
al.add(getListElement(data,i)); | ||
} | ||
return al; | ||
} | ||
|
||
@Override | ||
public Object getListElement(Object data, int index) { | ||
if (data == null) { | ||
return null; | ||
} | ||
JSONArray array = (JSONArray) data; | ||
try { | ||
Object obj = array.get(index); | ||
if(JSONObject.NULL == obj) { | ||
return null; | ||
} else { | ||
return obj; | ||
} | ||
} catch(JSONException ex) { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public int getListLength(Object data) { | ||
if (data == null) { | ||
return -1; | ||
} | ||
JSONArray array = (JSONArray) data; | ||
return array.length(); | ||
} | ||
|
||
} |
Oops, something went wrong.