-
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.
fixed #82, can handle maps with empty string
- Loading branch information
Roberto Congiu
committed
Aug 25, 2014
1 parent
d367e3a
commit a387336
Showing
4 changed files
with
105 additions
and
11 deletions.
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
75 changes: 75 additions & 0 deletions
75
json-serde/src/test/java/org/openx/data/jsonserde/JsonMapTest.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,75 @@ | ||
/*======================================================================* | ||
* 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; | ||
|
||
import java.util.Properties; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.hive.serde.Constants; | ||
import org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector; | ||
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; | ||
import org.apache.hadoop.hive.serde2.objectinspector.StructField; | ||
import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector; | ||
import org.apache.hadoop.io.Text; | ||
import org.apache.hadoop.io.Writable; | ||
|
||
import static org.junit.Assert.*; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import static org.openx.data.jsonserde.NestedStructureTest.instance; | ||
import org.openx.data.jsonserde.json.JSONObject; | ||
|
||
/** | ||
* | ||
* @author rcongiu | ||
*/ | ||
public class JsonMapTest { | ||
static JsonSerDe instance; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
initialize(); | ||
} | ||
|
||
static public void initialize() throws Exception { | ||
instance = new JsonSerDe(); | ||
Configuration conf = null; | ||
Properties tbl = new Properties(); | ||
// from google video API | ||
tbl.setProperty(Constants.LIST_COLUMNS, "country,languages,religions"); | ||
tbl.setProperty(Constants.LIST_COLUMN_TYPES, "string,string,map<string,string>".toLowerCase()); | ||
|
||
instance.initialize(conf, tbl); | ||
} | ||
|
||
@Test | ||
public void testDeSerialize() throws Exception { | ||
// Test that timestamp object can be deserialized | ||
Writable w = new Text("{\"country\":\"Switzerland\",\"languages\":\"Italian\",\"religions\":\"\"}"); | ||
|
||
JSONObject result = (JSONObject) instance.deserialize(w); | ||
|
||
StructObjectInspector soi = (StructObjectInspector) instance.getObjectInspector(); | ||
|
||
StructField sfr = soi.getStructFieldRef("religions"); | ||
|
||
assertEquals(sfr.getFieldObjectInspector().getCategory(),ObjectInspector.Category.MAP); | ||
|
||
MapObjectInspector moi = (MapObjectInspector) sfr.getFieldObjectInspector(); | ||
|
||
Object val = soi.getStructFieldData(result, sfr) ; | ||
|
||
assertEquals(-1, moi.getMapSize(val)); | ||
|
||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
json-serde/src/test/java/org/openx/data/jsonserde/ProtobufJsonTest.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