-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for String to Boolean conversion
- Loading branch information
Showing
4 changed files
with
75 additions
and
4 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
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
67 changes: 67 additions & 0 deletions
67
.../org/openx/data/jsonserde/objectinspector/primitive/JavaStringBooleanObjectInspector.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,67 @@ | ||
/*======================================================================* | ||
* 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.SettableBooleanObjectInspector; | ||
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; | ||
import org.apache.hadoop.io.BooleanWritable; | ||
|
||
/** | ||
* | ||
* @author rajat.85@gmail.com | ||
*/ | ||
public class JavaStringBooleanObjectInspector extends AbstractPrimitiveJavaObjectInspector | ||
implements SettableBooleanObjectInspector { | ||
|
||
public JavaStringBooleanObjectInspector() { | ||
super(TypeEntryShim.booleanType); | ||
} | ||
|
||
@Override | ||
public Object getPrimitiveWritableObject(Object o) { | ||
if(o == null) return null; | ||
|
||
if(o instanceof String) { | ||
return new BooleanWritable(Boolean.parseBoolean((String) o)); | ||
} else { | ||
return new BooleanWritable(((Boolean) o)); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean get(Object o) { | ||
|
||
if(o instanceof String) { | ||
return Boolean.parseBoolean((String) o); | ||
} else { | ||
return (((Boolean) o)); | ||
} | ||
} | ||
|
||
@Override | ||
public Object getPrimitiveJavaObject(Object o) { | ||
return get(o); | ||
} | ||
|
||
@Override | ||
public Object create(boolean value) { | ||
return value; | ||
} | ||
|
||
@Override | ||
public Object set(Object o, boolean value) { | ||
return 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