You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@gobblin.apache.org by Rodrigo Nicolas Garcia <ro...@despegar.com> on 2018/11/05 21:31:00 UTC

Re: Migrate from Camus to Apache Gobblin. Kaflka->S3 Partitioned

@PraTrick thanks for answer my mail.

I implemented a TimeBasedORCSerDeWriterPartitioner and create a new PR.

Also I’m compiling gobblin based on the master branch with the changes you
said before. But the problem still continues, if you see the gobblin logs
it tries to publish an entire directory on S3 (It only supports put
objects, not directories). Gobblin must put in a recursive way the entire
directory.
Logs:

2018-11-02 20:15:46 EDT INFO  [Task-committing-pool-0]
org.apache.gobblin.writer.FsDataWriter  257 - Moving data from
/home/despegar/data/sem-gobblin-installer/workdir/task-staging/kafkaToS3AvroPartition/job_kafkaToS3AvroPartition_1541204122618/error-event/event_date=2018-10-31/part.task_kafkaToS3AvroPartition_1541204122618_23_5.avro
to
/home/despegar/data/sem-gobblin-installer/workdir/task-output/kafkaToS3AvroPartition/job_kafkaToS3AvroPartition_1541204122618/error-event/event_date=2018-10-31/part.task_kafkaToS3AvroPartition_1541204122618_23_5.avro

...

2018-11-02 20:15:46 EDT INFO  [Commit-thread-0]
org.apache.gobblin.publisher.BaseDataPublisher  507 - Moving
file:/home/despegar/data/sem-gobblin-installer/workdir/task-output/kafkaToS3AvroPartition/job_kafkaToS3AvroPartition_1541204122618/error-event/event_date=2018-10-31
to /error-event/event_date=2018-10-31

...

2018-11-02 20:15:47 EDT WARN  [Commit-thread-0]
org.apache.gobblin.util.ParallelRunner  375 - Task failed: Move
file:/home/despegar/data/sem-gobblin-installer/workdir/task-output/kafkaToS3AvroPartition/job_kafkaToS3AvroPartition_1541204122618/error-event/event_date=2018-10-31
to /error-event/event_date=2018-10-31

…

java.io.IOException: com.amazonaws.AmazonClientException: Unable to
calculate MD5 hash:
/home/despegar/data/sem-gobblin-installer/workdir/task-output/kafkaToS3AvroPartition/job_kafkaToS3AvroPartition_1541204122618/error-conversion/event_date=2018-10-31
(Is a directory)

Do you have any leads on this issue?

Greetings.

El mié., 31 oct. 2018 a las 13:00, Prateek Gupta (<pr...@myntra.com>)
escribió:

> Hey Rodrigo,
>
> For publishing to s3 issue, we applied the below fix.
> I think, I opened a JIRA for the same but haven't created a PR for it yet.
> Will do it asap.
>
> *Replace*
>
> movePath(parallelRunner, state, writerOutputDir, publisherOutputDir,
> branchId);
> (
> https://github.com/apache/incubator-gobblin/blob/release-0.13.0/gobblin-core/src/main/java/org/apache/gobblin/publisher/BaseDataPublisher.java#L403
> )
>
> *With*
>
> addWriterOutputToExistingDir(writerOutputDir, publisherOutputDir, state,
> branchId, parallelRunner);
>
> Thanks & Regards,
> Prateek Gupta
>
>
> On Wed, Oct 31, 2018 at 9:07 PM Prateek Gupta <pr...@myntra.com>
> wrote:
>
>> Hey Everyone,
>>
>> May be it's too late to contribute, but here's how we've implemented it.
>>
>> public class TimeBasedOrcWriterPartitioner extends TimeBasedWriterPartitioner<Object> {
>>
>>   private static final Logger LOG = LoggerFactory.getLogger(TimeBasedOrcWriterPartitioner.class);
>>
>>   private static final String ORC_SERDE_ROW = "realRow";
>>   private static final String ORC_SERDE_INSPECTOR = "getInspector";
>>   private static final String WRITER_PARTITION_FIELD_NAME = ConfigurationKeys.WRITER_PREFIX + ".partition.field.name";
>>   private static final String WRITER_PARTITION_FIELD_PATTERN = ConfigurationKeys.WRITER_PREFIX + ".partition.field.pattern";
>>   private static final String DEFAULT_WRITER_PARTITION_FIELD_PATTERN = "yyyyMMdd";
>>   private static final String WRITER_PARTITION_FIELD_PARSE_AS_DATE =
>>           ConfigurationKeys.WRITER_PREFIX + ".partition.field.parse.as.date";
>>   private static final boolean DEFAULT_WRITER_PARTITION_FIELD_PARSE_AS_DATE = false;
>>
>>   private static String writerPartitionFieldName;
>>   private static String writerPartitionFieldPattern;
>>   private static Boolean writerPartitionFieldParseAsDate;
>>
>>   public TimeBasedOrcWriterPartitioner(gobblin.configuration.State state, int numBranches, int branchId) {
>>     super(state, numBranches, branchId);
>>     writerPartitionFieldName =
>>             getPropertyAsString(state, numBranches, branchId, WRITER_PARTITION_FIELD_NAME, StringUtils.EMPTY);
>>     writerPartitionFieldPattern =
>>             getPropertyAsString(state, numBranches, branchId,
>>                     WRITER_PARTITION_FIELD_PATTERN, DEFAULT_WRITER_PARTITION_FIELD_PATTERN);
>>     writerPartitionFieldParseAsDate =
>>             getPropertyAsBoolean(state, numBranches, branchId,
>>                     WRITER_PARTITION_FIELD_PARSE_AS_DATE, DEFAULT_WRITER_PARTITION_FIELD_PARSE_AS_DATE);
>>   }
>>
>>   private static String getPropertyAsString(State state, int numBranches, int branchId, String key, String defaultValue) {
>>     String propName = ForkOperatorUtils.getPropertyNameForBranch(key, numBranches, branchId);
>>     return state.getProp(propName, defaultValue);
>>   }
>>
>>   private static boolean getPropertyAsBoolean(State state, int numBranches, int branchId, String key, boolean defaultValue) {
>>     String propName = ForkOperatorUtils.getPropertyNameForBranch(key, numBranches, branchId);
>>     return state.getPropAsBoolean(propName, defaultValue);
>>   }
>>
>>   @Override
>>   public long getRecordTimestamp(Object orcRecord) {
>>     return getRecordTimestampUtil(orcRecord);
>>   }
>>
>>   private static ArrayList<Object> extractRealRow(Object orcRecord, Field f) throws IllegalAccessException {
>>     return (ArrayList<Object>) f.get(orcRecord);
>>   }
>>
>>   private static long getRecordTimestampUtil(Object orcRecord) {
>>     Class<?> clazz = orcRecord.getClass();
>>     ArrayList<Object> realRow;
>>     int timestampIndex;
>>     try {
>>       Field field = clazz.getDeclaredField(ORC_SERDE_ROW);
>>       Method method = clazz.getDeclaredMethod(ORC_SERDE_INSPECTOR, new Class[]{});
>>       field.setAccessible(true);
>>       method.setAccessible(true);
>>       ObjectInspector inspector = (ObjectInspector) method.invoke(clazz.cast(orcRecord));
>>       timestampIndex = ((StandardStructObjectInspector) inspector)
>>               .getStructFieldRef(writerPartitionFieldName).getFieldID();
>>       realRow = extractRealRow(orcRecord, field);
>>     } catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
>>       LOG.error("Error accessing field / method...");
>>       throw new RuntimeException(e);
>>     }
>>
>>     String timestampAsString = (String) realRow.get(timestampIndex);
>>     long timestamp;
>>     if (writerPartitionFieldParseAsDate) {
>>       try {
>>         SimpleDateFormat df = new SimpleDateFormat(writerPartitionFieldPattern);
>>         Date date = df.parse(timestampAsString);
>>         timestamp = date.getTime();
>>       } catch (ParseException e) {
>>         LOG.error("Error parsing timestamp...");
>>         throw new RuntimeException(e);
>>       }
>>     } else {
>>       timestamp = Long.parseLong(timestampAsString);
>>     }
>>     LOG.debug("Timestamp of the record {}", timestamp);
>>     return timestamp;
>>   }
>> }
>>
>> Thanks & Regards,
>> Prateek Gupta
>>
>> On Wed, Oct 31, 2018 at 2:54 AM Rodrigo Nicolas Garcia <
>> rodrigo.garcia@despegar.com> wrote:
>>
>>> @htran1 thanks for answer my mail.
>>>
>>> I wasn't abled to cast to OrcSerde$OrcSerdeRow because is a protected
>>> class of OrcSerde.
>>>
>>> I successfully implemented your solution it seems to work. I changed the
>>> partitioned class to Object and I use it like you proposed. I will try to
>>> generalize it for the community.
>>>
>>> I still have problems with publishing to S3. Do you know what might be
>>> happening?
>>>
>>> El lun., 29 oct. 2018 a las 13:49, Hung Tran (<hu...@linkedin.com>)
>>> escribió:
>>>
>>>> Hi Rodrigo,
>>>>
>>>>
>>>> I think the record type is of type OrcSerde$OrcSerdeRow, not OrcSerde.
>>>> Below is some sample code for a specific use case that shows extraction of
>>>> the underlying OrcSerdeRow and ObjectInspector. Maybe you can generalize it
>>>> and contribute it back to Gobblin.
>>>>
>>>>
>>>> The serializer and deserializer can be any hive serde, so you may not
>>>> need to convert to avro as an intermediate format. But one thing to be
>>>> careful with is not all hive serdes are thread-safe.
>>>>
>>>>
>>>> A couple issues you may run into with the ORC writer.
>>>>
>>>>
>>>>    1. The ORC serde is not threadsafe. There was a contribution
>>>>    introducing the OrcSerdeWrapper, but I'm not sure if that resolves the
>>>>    thread safety issue fully. The workaround if you are not using forks is to
>>>>    enable synchronous fork mode. gobblin.task.is.single.branch.synchronous=
>>>>    true.
>>>>    2. There is no time partitioner (as you have already found).
>>>>
>>>>
>>>> @Override
>>>>   public long getRecordTimestamp(Object orcRecord) {
>>>>     return getRecordTimestampUtil(orcRecord);
>>>>   }
>>>>
>>>>   private ArrayList<Object> extractRealRow(Object orcRecord,
>>>>       Field f) throws IllegalAccessException {
>>>>     return (ArrayList<Object>) f.get(orcRecord);
>>>>   }
>>>>
>>>>
>>>>   private int extractTimeStampIndex(Object orcRecord) {
>>>>     Class<?> clazz = orcRecord.getClass();
>>>>     try {
>>>>       Field f = clazz.getDeclaredField(ORC_SERDE_INSPECTOR);
>>>>       f.setAccessible(true);
>>>>       StructObjectInspector inspector = (StructObjectInspector)
>>>> f.get(orcRecord);
>>>>       for (int i = 0; i < inspector.getAllStructFieldRefs().size();
>>>> i++) {
>>>>         if
>>>> (inspector.getAllStructFieldRefs().get(i).getFieldName().equals(TIME_STAMP_FIELD_NAME))
>>>> {
>>>>           return i;
>>>>         }
>>>>       }
>>>>       throw new RuntimeException("Timestamp field doesn't exist");
>>>>     } catch (NoSuchFieldException | IllegalAccessException e) {
>>>>       throw new RuntimeException(e);
>>>>     }
>>>>   }
>>>>
>>>>   private long getRecordTimestampUtil(Object orcRecord) {
>>>>     Class<?> clazz = orcRecord.getClass();
>>>>     ArrayList<Object> realRow;
>>>>     try {
>>>>       if (this.timeStampIndex < 0) {
>>>>         this.timeStampIndex = extractTimeStampIndex(orcRecord);
>>>>       }
>>>>       Field f = clazz.getDeclaredField(ORC_SERDE_ROW);
>>>>       f.setAccessible(true);
>>>>       realRow = extractRealRow(orcRecord, f);
>>>>       if (realRow == null) {
>>>>         return 0;
>>>>       }
>>>>     } catch (NoSuchFieldException | IllegalAccessException e) {
>>>>       throw new RuntimeException(e);
>>>>     }
>>>>     try {
>>>>       if (realRow.size() <= timeStampIndex) {
>>>>         return 0;
>>>>       }
>>>>       long timestamp = (Long) realRow.get(timeStampIndex);
>>>>       return timestamp;
>>>>     } catch (Throwable e) {
>>>>       LOG.error("Exceptional record is: " +
>>>> ToStringBuilder.reflectionToString(orcRecord, ToStringStyle.JSON_STYLE));
>>>>       throw e;
>>>>     }
>>>>   }
>>>>
>>>> Hung.
>>>>
>>>> ------------------------------
>>>> *From:* Rodrigo Nicolas Garcia <ro...@despegar.com>
>>>> *Sent:* Monday, October 29, 2018 8:27:26 AM
>>>> *To:* user@gobblin.incubator.apache.org
>>>> *Cc:* Christian Engler; Adrian Musante; Sebastian Bevacqua
>>>> *Subject:* Fwd: Migrate from Camus to Apache Gobblin. Kaflka->S3
>>>> Partitioned
>>>>
>>>>
>>>> Hello,
>>>>
>>>> I would like to migrate from Camus <https://github.com/linkedin/camus>
>>>> to Apache Gobblin. I don’t want to create Hadoop clusters, I would like to
>>>> use it in Standalone execution mode.
>>>>
>>>> My current flow is:
>>>>
>>>> Azkaban flow runs camus one time per hour:
>>>>
>>>> 1. Move data from Kafka to HDFS on Json unpartitioned
>>>>
>>>> 2. Hive query like insert into from select, with that I partitioned
>>>> data and change format to TSV on ORC with location in S3 (using s3a on
>>>> hive).
>>>>
>>>> 3. Azkaban flow update metastore (msck repair).
>>>>
>>>> At the end of day, another workflow runs on Azkaban:
>>>>
>>>> Hive runs data compaction (to prevent data duplication in Kafka or
>>>> Camus)
>>>>
>>>> What I want to do:
>>>>
>>>> On the first implementation We don’t want to use Gobblin compaction,
>>>> because we will need a Hadoop Cluster and we won't like to do that.
>>>>
>>>> I would like to implement the new flow all on Gobblin Standalone
>>>> running one job per hour:
>>>>
>>>> 1. Kafka Extractor (we hold json on kafka like byte array)
>>>>
>>>> 2. Convert Json to Columnar tsv -> Partition by time (field on json) ->
>>>> Compact on ORC. (We use only ORC for compact data and can use it in hive.)
>>>>
>>>> 3. Publish data on S3. Also we can use that on EMR.
>>>>
>>>> We tried to implement this flow, but we have troubles with Gobblin. For
>>>> the partitioned data and ORC, Gobblin only accepts AVRO format.
>>>>
>>>> ¿Do you know if there is something missing in the flow?
>>>>
>>>> That’s why I changed the flow to this:
>>>>
>>>> 1. Kafka Extractor.
>>>>
>>>> 2. Convert Json to AVRO
>>>>
>>>> 3. AVRO convert to OrcSerdeRow for HiveWritableHdfsDataWriter can write
>>>> OrcFile.
>>>>
>>>> 3. Publish data on S3. Also we would using on EMR.
>>>>
>>>> Now I have two problems to solve:
>>>>
>>>> The first one: if I use ORC when I try to partition I’ve got this
>>>> exception:
>>>>
>>>> 2018-10-18 10:32:57 EDT INFO  [ForkExecutor-0]
>>>> org.apache.gobblin.runtime.fork.Fork  535 - Wrapping writer
>>>> org.apache.gobblin.writer.PartitionedDataWriter@2f511cc2
>>>>
>>>> 2018-10-18 10:32:57 EDT WARN  [ForkExecutor-0]
>>>> org.apache.gobblin.writer.RetryWriter$1  98 - Caught exception. This may be
>>>> retried.
>>>>
>>>> java.lang.ClassCastException:
>>>> org.apache.hadoop.hive.ql.io.orc.OrcSerde$OrcSerdeRow cannot be cast to
>>>> org.apache.hadoop.hive.ql.io.orc.OrcSerde
>>>>
>>>>    at
>>>> com.despegar.sem.gobblin.partitioner.OrcSerdeTimePartitioner.getRecordTimestamp(OrcSerdeTimePartitioner.java:15)
>>>>
>>>>    at
>>>> org.apache.gobblin.writer.partitioner.TimeBasedWriterPartitioner.partitionForRecord(TimeBasedWriterPartitioner.java:135)
>>>>
>>>>    at
>>>> org.apache.gobblin.writer.PartitionedDataWriter.getDataWriterForRecord(PartitionedDataWriter.java:170)
>>>>
>>>>
>>>> The second one, If I disable ORC and try to publish to S3, I’ve got
>>>> these errors:
>>>>
>>>> 2018-10-18 10:17:41 EDT WARN  [Commit-thread-0]
>>>> org.apache.gobblin.util.ParallelRunner  375 - Task failed: Move
>>>> /home/despegar/data/sem-gobblin-installer/workdir/task-output/kafkaToS3AvroPartition/job_kafkaToS3AvroPartition_1539872203735/error-event/
>>>> to /error-event/
>>>>
>>>> com.amazonaws.AmazonClientException: Unable to calculate MD5 hash:
>>>> /home/despegar/data/sem-gobblin-installer/workdir/task-output/kafkaToS3AvroPartition/job_kafkaToS3AvroPartition_1539872203735/error-event/
>>>> (Is a directory)
>>>>
>>>>    at
>>>> com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1298)
>>>>
>>>> In the last case, If I don’t enable partitioning It works.
>>>>
>>>> I attached the class and config jobs.
>>>>
>>>> Greetings.
>>>>
>>>> --
>>>>
>>>> *Ing. Rodrigo Nicolás García*
>>>> Líder Técnico - Trackeame - Marketing Online Tools
>>>> Juana Manso N° 999/1069 - piso 2° - C.A.B.A.
>>>> <https://maps.google.com/?q=Juana+Manso+N%C2%B0+999/1069+-+piso+2%C2%B0+-+C.A.B.A.&entry=gmail&source=g>
>>>> (C1107CBS)
>>>> -----
>>>> Este mensaje es confidencial y puede contener información amparada por
>>>> el secreto profesional.
>>>> Si usted ha recibido este e-mail por error, por favor comuníquenoslo
>>>> inmediatamente respondiendo a este e-mail y luego eliminándolo de su
>>>> sistema.
>>>> El contenido de este mensaje no deberá ser copiado ni divulgado a
>>>> ninguna persona.
>>>>
>>>
>>>
>>> --
>>>
>>> *Ing. Rodrigo Nicolás García*
>>> Líder Técnico - Trackeame - Marketing Online Tools
>>> Juana Manso N° 999/1069 - piso 2° - C.A.B.A.
>>> <https://maps.google.com/?q=Juana+Manso+N%C2%B0+999/1069+-+piso+2%C2%B0+-+C.A.B.A.&entry=gmail&source=g>
>>> (C1107CBS)
>>> -----
>>> Este mensaje es confidencial y puede contener información amparada por
>>> el secreto profesional.
>>> Si usted ha recibido este e-mail por error, por favor comuníquenoslo
>>> inmediatamente respondiendo a este e-mail y luego eliminándolo de su
>>> sistema.
>>> El contenido de este mensaje no deberá ser copiado ni divulgado a
>>> ninguna persona.
>>>
>>

-- 

*Ing. Rodrigo Nicolás García*
Líder Técnico - Trackeame - Marketing Online Tools
Juana Manso N° 999/1069 - piso 2° - C.A.B.A.
<https://maps.google.com/?q=Juana+Manso+N%C2%B0+999/1069+-+piso+2%C2%B0+-+C.A.B.A.&entry=gmail&source=g>
(C1107CBS)
-----
Este mensaje es confidencial y puede contener información amparada por el
secreto profesional.
Si usted ha recibido este e-mail por error, por favor comuníquenoslo
inmediatamente respondiendo a este e-mail y luego eliminándolo de su
sistema.
El contenido de este mensaje no deberá ser copiado ni divulgado a ninguna
persona.

Re: Migrate from Camus to Apache Gobblin. Kaflka->S3 Partitioned

Posted by Rodrigo Nicolas Garcia <ro...@despegar.com>.
Hello, I’ve updates to this problem.

I’ve solved the S3 issue using the s3n driver for the publisher but now I’m
having new problems.

If I don’t have data to publish, gobblin fails.

I have a cron job per hour, the first time it runs, publish data in this
location:  event/event_date=2018-11-09/

But in the second run, It publish data in this wrong location:
event/event_date=2018-11-09/event_date=2018-11-09/

(Instead of publishing event/event_date=2018-11-09)

Config:

topic.whitelist=error-event

job.schedule=0 0/60 * * * ?

writer.partitioner.class=org.apache.gobblin.writer.partitioner.TimeBasedAvroWriterPartitioner

writer.partition.granularity=day

writer.partition.pattern='event_date='YYYY-MM-dd

fs.s3n.buffer.dir=${env:GOBBLIN_WORK_DIR}/s3n

fs.s3n.awsAccessKeyId=${env:AWS_ACCESS_KEY_ID}

fs.s3n.awsSecretAccessKey=${env:AWS_SECRET_KEY}

data.publisher.type=org.apache.gobblin.publisher.BaseDataPublisher

data.publisher.overwrite.enabled=true

data.publisher.fs.uri=s3n://bucket

data.publisher.replace.final.dir=false

data.publisher.final.dir=/

Greetings

El lun., 5 nov. 2018 a las 18:31, Rodrigo Nicolas Garcia (<
rodrigo.garcia@despegar.com>) escribió:

> @PraTrick thanks for answer my mail.
>
> I implemented a TimeBasedORCSerDeWriterPartitioner and create a new PR.
>
> Also I’m compiling gobblin based on the master branch with the changes you
> said before. But the problem still continues, if you see the gobblin logs
> it tries to publish an entire directory on S3 (It only supports put
> objects, not directories). Gobblin must put in a recursive way the entire
> directory.
> Logs:
>
> 2018-11-02 20:15:46 EDT INFO  [Task-committing-pool-0]
> org.apache.gobblin.writer.FsDataWriter  257 - Moving data from
> /home/despegar/data/sem-gobblin-installer/workdir/task-staging/kafkaToS3AvroPartition/job_kafkaToS3AvroPartition_1541204122618/error-event/event_date=2018-10-31/part.task_kafkaToS3AvroPartition_1541204122618_23_5.avro
> to
> /home/despegar/data/sem-gobblin-installer/workdir/task-output/kafkaToS3AvroPartition/job_kafkaToS3AvroPartition_1541204122618/error-event/event_date=2018-10-31/part.task_kafkaToS3AvroPartition_1541204122618_23_5.avro
>
> ...
>
> 2018-11-02 20:15:46 EDT INFO  [Commit-thread-0]
> org.apache.gobblin.publisher.BaseDataPublisher  507 - Moving
> file:/home/despegar/data/sem-gobblin-installer/workdir/task-output/kafkaToS3AvroPartition/job_kafkaToS3AvroPartition_1541204122618/error-event/event_date=2018-10-31
> to /error-event/event_date=2018-10-31
>
> ...
>
> 2018-11-02 20:15:47 EDT WARN  [Commit-thread-0]
> org.apache.gobblin.util.ParallelRunner  375 - Task failed: Move
> file:/home/despegar/data/sem-gobblin-installer/workdir/task-output/kafkaToS3AvroPartition/job_kafkaToS3AvroPartition_1541204122618/error-event/event_date=2018-10-31
> to /error-event/event_date=2018-10-31
>
> …
>
> java.io.IOException: com.amazonaws.AmazonClientException: Unable to
> calculate MD5 hash:
> /home/despegar/data/sem-gobblin-installer/workdir/task-output/kafkaToS3AvroPartition/job_kafkaToS3AvroPartition_1541204122618/error-conversion/event_date=2018-10-31
> (Is a directory)
>
> Do you have any leads on this issue?
>
> Greetings.
>
> El mié., 31 oct. 2018 a las 13:00, Prateek Gupta (<
> prateek.gupta3@myntra.com>) escribió:
>
>> Hey Rodrigo,
>>
>> For publishing to s3 issue, we applied the below fix.
>> I think, I opened a JIRA for the same but haven't created a PR for it
>> yet. Will do it asap.
>>
>> *Replace*
>>
>> movePath(parallelRunner, state, writerOutputDir, publisherOutputDir,
>> branchId);
>> (
>> https://github.com/apache/incubator-gobblin/blob/release-0.13.0/gobblin-core/src/main/java/org/apache/gobblin/publisher/BaseDataPublisher.java#L403
>> )
>>
>> *With*
>>
>> addWriterOutputToExistingDir(writerOutputDir, publisherOutputDir, state,
>> branchId, parallelRunner);
>>
>> Thanks & Regards,
>> Prateek Gupta
>>
>>
>> On Wed, Oct 31, 2018 at 9:07 PM Prateek Gupta <pr...@myntra.com>
>> wrote:
>>
>>> Hey Everyone,
>>>
>>> May be it's too late to contribute, but here's how we've implemented it.
>>>
>>> public class TimeBasedOrcWriterPartitioner extends TimeBasedWriterPartitioner<Object> {
>>>
>>>   private static final Logger LOG = LoggerFactory.getLogger(TimeBasedOrcWriterPartitioner.class);
>>>
>>>   private static final String ORC_SERDE_ROW = "realRow";
>>>   private static final String ORC_SERDE_INSPECTOR = "getInspector";
>>>   private static final String WRITER_PARTITION_FIELD_NAME = ConfigurationKeys.WRITER_PREFIX + ".partition.field.name";
>>>   private static final String WRITER_PARTITION_FIELD_PATTERN = ConfigurationKeys.WRITER_PREFIX + ".partition.field.pattern";
>>>   private static final String DEFAULT_WRITER_PARTITION_FIELD_PATTERN = "yyyyMMdd";
>>>   private static final String WRITER_PARTITION_FIELD_PARSE_AS_DATE =
>>>           ConfigurationKeys.WRITER_PREFIX + ".partition.field.parse.as.date";
>>>   private static final boolean DEFAULT_WRITER_PARTITION_FIELD_PARSE_AS_DATE = false;
>>>
>>>   private static String writerPartitionFieldName;
>>>   private static String writerPartitionFieldPattern;
>>>   private static Boolean writerPartitionFieldParseAsDate;
>>>
>>>   public TimeBasedOrcWriterPartitioner(gobblin.configuration.State state, int numBranches, int branchId) {
>>>     super(state, numBranches, branchId);
>>>     writerPartitionFieldName =
>>>             getPropertyAsString(state, numBranches, branchId, WRITER_PARTITION_FIELD_NAME, StringUtils.EMPTY);
>>>     writerPartitionFieldPattern =
>>>             getPropertyAsString(state, numBranches, branchId,
>>>                     WRITER_PARTITION_FIELD_PATTERN, DEFAULT_WRITER_PARTITION_FIELD_PATTERN);
>>>     writerPartitionFieldParseAsDate =
>>>             getPropertyAsBoolean(state, numBranches, branchId,
>>>                     WRITER_PARTITION_FIELD_PARSE_AS_DATE, DEFAULT_WRITER_PARTITION_FIELD_PARSE_AS_DATE);
>>>   }
>>>
>>>   private static String getPropertyAsString(State state, int numBranches, int branchId, String key, String defaultValue) {
>>>     String propName = ForkOperatorUtils.getPropertyNameForBranch(key, numBranches, branchId);
>>>     return state.getProp(propName, defaultValue);
>>>   }
>>>
>>>   private static boolean getPropertyAsBoolean(State state, int numBranches, int branchId, String key, boolean defaultValue) {
>>>     String propName = ForkOperatorUtils.getPropertyNameForBranch(key, numBranches, branchId);
>>>     return state.getPropAsBoolean(propName, defaultValue);
>>>   }
>>>
>>>   @Override
>>>   public long getRecordTimestamp(Object orcRecord) {
>>>     return getRecordTimestampUtil(orcRecord);
>>>   }
>>>
>>>   private static ArrayList<Object> extractRealRow(Object orcRecord, Field f) throws IllegalAccessException {
>>>     return (ArrayList<Object>) f.get(orcRecord);
>>>   }
>>>
>>>   private static long getRecordTimestampUtil(Object orcRecord) {
>>>     Class<?> clazz = orcRecord.getClass();
>>>     ArrayList<Object> realRow;
>>>     int timestampIndex;
>>>     try {
>>>       Field field = clazz.getDeclaredField(ORC_SERDE_ROW);
>>>       Method method = clazz.getDeclaredMethod(ORC_SERDE_INSPECTOR, new Class[]{});
>>>       field.setAccessible(true);
>>>       method.setAccessible(true);
>>>       ObjectInspector inspector = (ObjectInspector) method.invoke(clazz.cast(orcRecord));
>>>       timestampIndex = ((StandardStructObjectInspector) inspector)
>>>               .getStructFieldRef(writerPartitionFieldName).getFieldID();
>>>       realRow = extractRealRow(orcRecord, field);
>>>     } catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
>>>       LOG.error("Error accessing field / method...");
>>>       throw new RuntimeException(e);
>>>     }
>>>
>>>     String timestampAsString = (String) realRow.get(timestampIndex);
>>>     long timestamp;
>>>     if (writerPartitionFieldParseAsDate) {
>>>       try {
>>>         SimpleDateFormat df = new SimpleDateFormat(writerPartitionFieldPattern);
>>>         Date date = df.parse(timestampAsString);
>>>         timestamp = date.getTime();
>>>       } catch (ParseException e) {
>>>         LOG.error("Error parsing timestamp...");
>>>         throw new RuntimeException(e);
>>>       }
>>>     } else {
>>>       timestamp = Long.parseLong(timestampAsString);
>>>     }
>>>     LOG.debug("Timestamp of the record {}", timestamp);
>>>     return timestamp;
>>>   }
>>> }
>>>
>>> Thanks & Regards,
>>> Prateek Gupta
>>>
>>> On Wed, Oct 31, 2018 at 2:54 AM Rodrigo Nicolas Garcia <
>>> rodrigo.garcia@despegar.com> wrote:
>>>
>>>> @htran1 thanks for answer my mail.
>>>>
>>>> I wasn't abled to cast to OrcSerde$OrcSerdeRow because is a protected
>>>> class of OrcSerde.
>>>>
>>>> I successfully implemented your solution it seems to work. I changed
>>>> the partitioned class to Object and I use it like you proposed. I will try
>>>> to generalize it for the community.
>>>>
>>>> I still have problems with publishing to S3. Do you know what might be
>>>> happening?
>>>>
>>>> El lun., 29 oct. 2018 a las 13:49, Hung Tran (<hu...@linkedin.com>)
>>>> escribió:
>>>>
>>>>> Hi Rodrigo,
>>>>>
>>>>>
>>>>> I think the record type is of type OrcSerde$OrcSerdeRow, not OrcSerde.
>>>>> Below is some sample code for a specific use case that shows extraction of
>>>>> the underlying OrcSerdeRow and ObjectInspector. Maybe you can generalize it
>>>>> and contribute it back to Gobblin.
>>>>>
>>>>>
>>>>> The serializer and deserializer can be any hive serde, so you may not
>>>>> need to convert to avro as an intermediate format. But one thing to be
>>>>> careful with is not all hive serdes are thread-safe.
>>>>>
>>>>>
>>>>> A couple issues you may run into with the ORC writer.
>>>>>
>>>>>
>>>>>    1. The ORC serde is not threadsafe. There was a contribution
>>>>>    introducing the OrcSerdeWrapper, but I'm not sure if that resolves the
>>>>>    thread safety issue fully. The workaround if you are not using forks is to
>>>>>    enable synchronous fork mode. gobblin.task.is.single.branch.synchronous=
>>>>>    true.
>>>>>    2. There is no time partitioner (as you have already found).
>>>>>
>>>>>
>>>>> @Override
>>>>>   public long getRecordTimestamp(Object orcRecord) {
>>>>>     return getRecordTimestampUtil(orcRecord);
>>>>>   }
>>>>>
>>>>>   private ArrayList<Object> extractRealRow(Object orcRecord,
>>>>>       Field f) throws IllegalAccessException {
>>>>>     return (ArrayList<Object>) f.get(orcRecord);
>>>>>   }
>>>>>
>>>>>
>>>>>   private int extractTimeStampIndex(Object orcRecord) {
>>>>>     Class<?> clazz = orcRecord.getClass();
>>>>>     try {
>>>>>       Field f = clazz.getDeclaredField(ORC_SERDE_INSPECTOR);
>>>>>       f.setAccessible(true);
>>>>>       StructObjectInspector inspector = (StructObjectInspector)
>>>>> f.get(orcRecord);
>>>>>       for (int i = 0; i < inspector.getAllStructFieldRefs().size();
>>>>> i++) {
>>>>>         if
>>>>> (inspector.getAllStructFieldRefs().get(i).getFieldName().equals(TIME_STAMP_FIELD_NAME))
>>>>> {
>>>>>           return i;
>>>>>         }
>>>>>       }
>>>>>       throw new RuntimeException("Timestamp field doesn't exist");
>>>>>     } catch (NoSuchFieldException | IllegalAccessException e) {
>>>>>       throw new RuntimeException(e);
>>>>>     }
>>>>>   }
>>>>>
>>>>>   private long getRecordTimestampUtil(Object orcRecord) {
>>>>>     Class<?> clazz = orcRecord.getClass();
>>>>>     ArrayList<Object> realRow;
>>>>>     try {
>>>>>       if (this.timeStampIndex < 0) {
>>>>>         this.timeStampIndex = extractTimeStampIndex(orcRecord);
>>>>>       }
>>>>>       Field f = clazz.getDeclaredField(ORC_SERDE_ROW);
>>>>>       f.setAccessible(true);
>>>>>       realRow = extractRealRow(orcRecord, f);
>>>>>       if (realRow == null) {
>>>>>         return 0;
>>>>>       }
>>>>>     } catch (NoSuchFieldException | IllegalAccessException e) {
>>>>>       throw new RuntimeException(e);
>>>>>     }
>>>>>     try {
>>>>>       if (realRow.size() <= timeStampIndex) {
>>>>>         return 0;
>>>>>       }
>>>>>       long timestamp = (Long) realRow.get(timeStampIndex);
>>>>>       return timestamp;
>>>>>     } catch (Throwable e) {
>>>>>       LOG.error("Exceptional record is: " +
>>>>> ToStringBuilder.reflectionToString(orcRecord, ToStringStyle.JSON_STYLE));
>>>>>       throw e;
>>>>>     }
>>>>>   }
>>>>>
>>>>> Hung.
>>>>>
>>>>> ------------------------------
>>>>> *From:* Rodrigo Nicolas Garcia <ro...@despegar.com>
>>>>> *Sent:* Monday, October 29, 2018 8:27:26 AM
>>>>> *To:* user@gobblin.incubator.apache.org
>>>>> *Cc:* Christian Engler; Adrian Musante; Sebastian Bevacqua
>>>>> *Subject:* Fwd: Migrate from Camus to Apache Gobblin. Kaflka->S3
>>>>> Partitioned
>>>>>
>>>>>
>>>>> Hello,
>>>>>
>>>>> I would like to migrate from Camus <https://github.com/linkedin/camus>
>>>>> to Apache Gobblin. I don’t want to create Hadoop clusters, I would like to
>>>>> use it in Standalone execution mode.
>>>>>
>>>>> My current flow is:
>>>>>
>>>>> Azkaban flow runs camus one time per hour:
>>>>>
>>>>> 1. Move data from Kafka to HDFS on Json unpartitioned
>>>>>
>>>>> 2. Hive query like insert into from select, with that I partitioned
>>>>> data and change format to TSV on ORC with location in S3 (using s3a on
>>>>> hive).
>>>>>
>>>>> 3. Azkaban flow update metastore (msck repair).
>>>>>
>>>>> At the end of day, another workflow runs on Azkaban:
>>>>>
>>>>> Hive runs data compaction (to prevent data duplication in Kafka or
>>>>> Camus)
>>>>>
>>>>> What I want to do:
>>>>>
>>>>> On the first implementation We don’t want to use Gobblin compaction,
>>>>> because we will need a Hadoop Cluster and we won't like to do that.
>>>>>
>>>>> I would like to implement the new flow all on Gobblin Standalone
>>>>> running one job per hour:
>>>>>
>>>>> 1. Kafka Extractor (we hold json on kafka like byte array)
>>>>>
>>>>> 2. Convert Json to Columnar tsv -> Partition by time (field on json)
>>>>> -> Compact on ORC. (We use only ORC for compact data and can use it in
>>>>> hive.)
>>>>>
>>>>> 3. Publish data on S3. Also we can use that on EMR.
>>>>>
>>>>> We tried to implement this flow, but we have troubles with Gobblin.
>>>>> For the partitioned data and ORC, Gobblin only accepts AVRO format.
>>>>>
>>>>> ¿Do you know if there is something missing in the flow?
>>>>>
>>>>> That’s why I changed the flow to this:
>>>>>
>>>>> 1. Kafka Extractor.
>>>>>
>>>>> 2. Convert Json to AVRO
>>>>>
>>>>> 3. AVRO convert to OrcSerdeRow for HiveWritableHdfsDataWriter can
>>>>> write OrcFile.
>>>>>
>>>>> 3. Publish data on S3. Also we would using on EMR.
>>>>>
>>>>> Now I have two problems to solve:
>>>>>
>>>>> The first one: if I use ORC when I try to partition I’ve got this
>>>>> exception:
>>>>>
>>>>> 2018-10-18 10:32:57 EDT INFO  [ForkExecutor-0]
>>>>> org.apache.gobblin.runtime.fork.Fork  535 - Wrapping writer
>>>>> org.apache.gobblin.writer.PartitionedDataWriter@2f511cc2
>>>>>
>>>>> 2018-10-18 10:32:57 EDT WARN  [ForkExecutor-0]
>>>>> org.apache.gobblin.writer.RetryWriter$1  98 - Caught exception. This may be
>>>>> retried.
>>>>>
>>>>> java.lang.ClassCastException:
>>>>> org.apache.hadoop.hive.ql.io.orc.OrcSerde$OrcSerdeRow cannot be cast to
>>>>> org.apache.hadoop.hive.ql.io.orc.OrcSerde
>>>>>
>>>>>    at
>>>>> com.despegar.sem.gobblin.partitioner.OrcSerdeTimePartitioner.getRecordTimestamp(OrcSerdeTimePartitioner.java:15)
>>>>>
>>>>>    at
>>>>> org.apache.gobblin.writer.partitioner.TimeBasedWriterPartitioner.partitionForRecord(TimeBasedWriterPartitioner.java:135)
>>>>>
>>>>>    at
>>>>> org.apache.gobblin.writer.PartitionedDataWriter.getDataWriterForRecord(PartitionedDataWriter.java:170)
>>>>>
>>>>>
>>>>> The second one, If I disable ORC and try to publish to S3, I’ve got
>>>>> these errors:
>>>>>
>>>>> 2018-10-18 10:17:41 EDT WARN  [Commit-thread-0]
>>>>> org.apache.gobblin.util.ParallelRunner  375 - Task failed: Move
>>>>> /home/despegar/data/sem-gobblin-installer/workdir/task-output/kafkaToS3AvroPartition/job_kafkaToS3AvroPartition_1539872203735/error-event/
>>>>> to /error-event/
>>>>>
>>>>> com.amazonaws.AmazonClientException: Unable to calculate MD5 hash:
>>>>> /home/despegar/data/sem-gobblin-installer/workdir/task-output/kafkaToS3AvroPartition/job_kafkaToS3AvroPartition_1539872203735/error-event/
>>>>> (Is a directory)
>>>>>
>>>>>    at
>>>>> com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1298)
>>>>>
>>>>> In the last case, If I don’t enable partitioning It works.
>>>>>
>>>>> I attached the class and config jobs.
>>>>>
>>>>> Greetings.
>>>>>
>>>>> --
>>>>>
>>>>> *Ing. Rodrigo Nicolás García*
>>>>> Líder Técnico - Trackeame - Marketing Online Tools
>>>>> Juana Manso N° 999/1069 - piso 2° - C.A.B.A.
>>>>> <https://maps.google.com/?q=Juana+Manso+N%C2%B0+999/1069+-+piso+2%C2%B0+-+C.A.B.A.&entry=gmail&source=g>
>>>>> (C1107CBS)
>>>>> -----
>>>>> Este mensaje es confidencial y puede contener información amparada por
>>>>> el secreto profesional.
>>>>> Si usted ha recibido este e-mail por error, por favor comuníquenoslo
>>>>> inmediatamente respondiendo a este e-mail y luego eliminándolo de su
>>>>> sistema.
>>>>> El contenido de este mensaje no deberá ser copiado ni divulgado a
>>>>> ninguna persona.
>>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> *Ing. Rodrigo Nicolás García*
>>>> Líder Técnico - Trackeame - Marketing Online Tools
>>>> Juana Manso N° 999/1069 - piso 2° - C.A.B.A.
>>>> <https://maps.google.com/?q=Juana+Manso+N%C2%B0+999/1069+-+piso+2%C2%B0+-+C.A.B.A.&entry=gmail&source=g>
>>>> (C1107CBS)
>>>> -----
>>>> Este mensaje es confidencial y puede contener información amparada por
>>>> el secreto profesional.
>>>> Si usted ha recibido este e-mail por error, por favor comuníquenoslo
>>>> inmediatamente respondiendo a este e-mail y luego eliminándolo de su
>>>> sistema.
>>>> El contenido de este mensaje no deberá ser copiado ni divulgado a
>>>> ninguna persona.
>>>>
>>>
>
> --
>
> *Ing. Rodrigo Nicolás García*
> Líder Técnico - Trackeame - Marketing Online Tools
> Juana Manso N° 999/1069 - piso 2° - C.A.B.A.
> <https://maps.google.com/?q=Juana+Manso+N%C2%B0+999/1069+-+piso+2%C2%B0+-+C.A.B.A.&entry=gmail&source=g>
> (C1107CBS)
> -----
> Este mensaje es confidencial y puede contener información amparada por el
> secreto profesional.
> Si usted ha recibido este e-mail por error, por favor comuníquenoslo
> inmediatamente respondiendo a este e-mail y luego eliminándolo de su
> sistema.
> El contenido de este mensaje no deberá ser copiado ni divulgado a ninguna
> persona.
>


-- 

*Ing. Rodrigo Nicolás García*
Líder Técnico - Trackeame - Marketing Online Tools
Juana Manso N° 999/1069 - piso 2° - C.A.B.A.
<https://maps.google.com/?q=Juana+Manso+N%C2%B0+999/1069+-+piso+2%C2%B0+-+C.A.B.A.&entry=gmail&source=g>
(C1107CBS)
-----
Este mensaje es confidencial y puede contener información amparada por el
secreto profesional.
Si usted ha recibido este e-mail por error, por favor comuníquenoslo
inmediatamente respondiendo a este e-mail y luego eliminándolo de su
sistema.
El contenido de este mensaje no deberá ser copiado ni divulgado a ninguna
persona.