You can use the TypeDescription API to create the schema. Like:
TypeDescription schema = TypeDescription.createStruct()
.addField("time", TypeDescription.createTimestamp())
.addField("union", TypeDescription.createUnion()
.addUnionChild(TypeDescription.createInt())
.addUnionChild(TypeDescription.createString()))
.addField("decimal", TypeDescription.createDecimal()
.withPrecision(38)
.withScale(18));
TypeDescription.fromString lets you be a little more compact:
TypeDescription schema = TypeDescription.fromString(
"struct<time:timestamp,uniontype<int,string>,decimal:decimal(38,18)>");
.. Owen
On Mon, Aug 8, 2016 at 2:01 PM, praveen reddy <
[email protected]> wrote:
> i am on version 1.2. i am currently using
> ObjectInspectorFactory.getReflectionObjectInspector
> to build the schema. will try to use DateWritable and HiveDecimalWritable.
>
> for using TypeDescription.fromString(), do we need to hardcode the schema?
> if we need to hardcode i dont think that option will work for me. i am
> looking into api further.
>
>
> On Mon, Aug 8, 2016 at 3:14 PM, Owen O'Malley <[email protected]> wrote:
>
>> Which version are you using?
>>
>> If you are using Hive's ObjectInspectorFactory.getReflectionObjectInspector,
>> you want to use DateWritable and HiveDecimalWritable.
>>
>> For even more control, you can create a TypeDescription and provide it
>> via setSchema to the OrcFile.WriterOptions. In ORC 1.1 you can also use
>> TypeDescription.fromString() to build TypeDescription from the type name.
>>
>> .. Owen
>>
>> On Mon, Aug 8, 2016 at 3:58 AM, praveen reddy <
>> [email protected]> wrote:
>>
>>> Hi,
>>>
>>> i need to store Timestamp and Decimal datatype in ORC file. i declared
>>> them as Date and BigDecimal in java but when i save them in ORC file, they
>>> are storing as Struct type. i dont want to use Struct type.
>>>
>>> can you please help on what data type i need to choose in Java. i am
>>> kind of stuck on this.
>>>
>>> Thanks,
>>> Praveen
>>>
>>
>>
>