-
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.
Completed all the Primitive OI for all numeric types, with unit tests.
- Loading branch information
Roberto Congiu
committed
Jan 22, 2014
1 parent
002c53a
commit 3788ede
Showing
8 changed files
with
328 additions
and
15 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
61 changes: 61 additions & 0 deletions
61
...ava/org/openx/data/jsonserde/objectinspector/primitive/JavaStringByteObjectInspector.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,61 @@ | ||
/*======================================================================* | ||
* 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.primitive; | ||
|
||
import org.apache.hadoop.hive.serde2.objectinspector.primitive.AbstractPrimitiveJavaObjectInspector; | ||
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils; | ||
import org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableByteObjectInspector; | ||
import org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableIntObjectInspector; | ||
import org.apache.hadoop.io.IntWritable; | ||
|
||
/** | ||
* | ||
* @author rcongiu | ||
*/ | ||
public class JavaStringByteObjectInspector extends AbstractPrimitiveJavaObjectInspector | ||
implements SettableByteObjectInspector { | ||
|
||
public JavaStringByteObjectInspector() { | ||
super(PrimitiveObjectInspectorUtils.longTypeEntry); | ||
} | ||
|
||
@Override | ||
public Object getPrimitiveWritableObject(Object o) { | ||
if(o == null) return null; | ||
|
||
if(o instanceof String) { | ||
return new IntWritable(Integer.parseInt((String)o)); | ||
} else { | ||
return new IntWritable(((Integer) o).intValue()); | ||
} | ||
} | ||
|
||
@Override | ||
public byte get(Object o) { | ||
if(o instanceof String) { | ||
return Byte.parseByte((String)o); | ||
} else { | ||
return ((Byte) o).byteValue(); | ||
} | ||
} | ||
|
||
@Override | ||
public Object create(byte value) { | ||
return Byte.valueOf(value); | ||
} | ||
|
||
@Override | ||
public Object set(Object o, byte value) { | ||
return Byte.valueOf(value); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...a/org/openx/data/jsonserde/objectinspector/primitive/JavaStringDoubleObjectInspector.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,62 @@ | ||
/*======================================================================* | ||
* 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.primitive; | ||
|
||
import org.apache.hadoop.hive.serde2.objectinspector.primitive.AbstractPrimitiveJavaObjectInspector; | ||
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils; | ||
import org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableDoubleObjectInspector; | ||
import org.apache.hadoop.io.DoubleWritable; | ||
|
||
/** | ||
* | ||
* @author rcongiu | ||
*/ | ||
public class JavaStringDoubleObjectInspector extends AbstractPrimitiveJavaObjectInspector | ||
implements SettableDoubleObjectInspector { | ||
|
||
public JavaStringDoubleObjectInspector() { | ||
super(PrimitiveObjectInspectorUtils.doubleTypeEntry); | ||
} | ||
|
||
@Override | ||
public Object getPrimitiveWritableObject(Object o) { | ||
if(o == null) return null; | ||
|
||
if(o instanceof String) { | ||
return new DoubleWritable(Double.parseDouble((String)o)); | ||
} else { | ||
return new DoubleWritable(((Double) o).doubleValue()); | ||
} | ||
} | ||
|
||
@Override | ||
public double get(Object o) { | ||
|
||
if(o instanceof String) { | ||
return Double.parseDouble((String)o); | ||
} else { | ||
return (((Double) o).doubleValue()); | ||
} | ||
} | ||
|
||
@Override | ||
public Object create(double value) { | ||
return Double.valueOf(value); | ||
} | ||
|
||
@Override | ||
public Object set(Object o, double value) { | ||
return Double.valueOf(value); | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
...va/org/openx/data/jsonserde/objectinspector/primitive/JavaStringFloatObjectInspector.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,62 @@ | ||
/*======================================================================* | ||
* 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.primitive; | ||
|
||
import org.apache.hadoop.hive.serde2.objectinspector.primitive.AbstractPrimitiveJavaObjectInspector; | ||
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils; | ||
import org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableFloatObjectInspector; | ||
import org.apache.hadoop.io.FloatWritable; | ||
|
||
/** | ||
* | ||
* @author rcongiu | ||
*/ | ||
public class JavaStringFloatObjectInspector extends AbstractPrimitiveJavaObjectInspector | ||
implements SettableFloatObjectInspector { | ||
|
||
public JavaStringFloatObjectInspector() { | ||
super(PrimitiveObjectInspectorUtils.floatTypeEntry); | ||
} | ||
|
||
@Override | ||
public Object getPrimitiveWritableObject(Object o) { | ||
if(o == null) return null; | ||
|
||
if(o instanceof String) { | ||
return new FloatWritable(Float.parseFloat((String)o)); | ||
} else { | ||
return new FloatWritable(((Float) o).floatValue()); | ||
} | ||
} | ||
|
||
@Override | ||
public float get(Object o) { | ||
|
||
if(o instanceof String) { | ||
return Float.parseFloat((String)o); | ||
} else { | ||
return (((Float) o).floatValue()); | ||
} | ||
} | ||
|
||
@Override | ||
public Object create(float value) { | ||
return Float.valueOf(value); | ||
} | ||
|
||
@Override | ||
public Object set(Object o, float value) { | ||
return Float.valueOf(value); | ||
} | ||
|
||
} |
17 changes: 12 additions & 5 deletions
17
...java/org/openx/data/jsonserde/objectinspector/primitive/JavaStringIntObjectInspector.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
17 changes: 12 additions & 5 deletions
17
...ava/org/openx/data/jsonserde/objectinspector/primitive/JavaStringLongObjectInspector.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
62 changes: 62 additions & 0 deletions
62
...va/org/openx/data/jsonserde/objectinspector/primitive/JavaStringShortObjectInspector.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,62 @@ | ||
/*======================================================================* | ||
* 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.primitive; | ||
|
||
import org.apache.hadoop.hive.serde2.io.ShortWritable; | ||
import org.apache.hadoop.hive.serde2.objectinspector.primitive.AbstractPrimitiveJavaObjectInspector; | ||
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils; | ||
import org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableShortObjectInspector; | ||
|
||
/** | ||
* | ||
* @author rcongiu | ||
*/ | ||
public class JavaStringShortObjectInspector | ||
extends AbstractPrimitiveJavaObjectInspector | ||
implements SettableShortObjectInspector { | ||
|
||
public JavaStringShortObjectInspector() { | ||
super(PrimitiveObjectInspectorUtils.shortTypeEntry); | ||
} | ||
|
||
@Override | ||
public Object getPrimitiveWritableObject(Object o) { | ||
if(o == null) return null; | ||
|
||
if(o instanceof String) { | ||
return new ShortWritable(Short.parseShort((String)o)); | ||
} else { | ||
return new ShortWritable(((Short) o).shortValue()); | ||
} | ||
} | ||
|
||
@Override | ||
public short get(Object o) { | ||
|
||
if(o instanceof String) { | ||
return Short.parseShort((String)o); | ||
} else { | ||
return (((Short) o).shortValue()); | ||
} | ||
} | ||
|
||
@Override | ||
public Object create(short value) { | ||
return Short.valueOf(value); | ||
} | ||
|
||
@Override | ||
public Object set(Object o, short value) { | ||
return Short.valueOf(value); | ||
} | ||
} |
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