[ 
https://issues.apache.org/jira/browse/GOBBLIN-835?focusedWorklogId=292385&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-292385
 ]

ASF GitHub Bot logged work on GOBBLIN-835:
------------------------------------------

                Author: ASF GitHub Bot
            Created on: 10/Aug/19 01:22
            Start Date: 10/Aug/19 01:22
    Worklog Time Spent: 10m 
      Work Description: jhsenjaliya commented on pull request #2704: 
[GOBBLIN-835] Date Converter
URL: https://github.com/apache/incubator-gobblin/pull/2704#discussion_r312684855
 
 

 ##########
 File path: 
gobblin-core/src/main/java/org/apache/gobblin/converter/date/DateConverter.java
 ##########
 @@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+package org.apache.gobblin.converter.date;
+
+import com.google.common.base.Preconditions;
+import org.apache.gobblin.configuration.ConfigurationKeys;
+import org.apache.gobblin.configuration.WorkUnitState;
+import org.apache.gobblin.converter.Converter;
+import org.apache.gobblin.converter.DataConversionException;
+import org.apache.gobblin.converter.SchemaConversionException;
+import org.apache.gobblin.converter.SingleRecordIterable;
+import org.apache.gobblin.util.EmptyIterable;
+
+import java.lang.reflect.Method;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+
+public class DateConverter<SI, SO, DI, DO> extends Converter<SI, SO, DI, DO> {
+
+    private String inputTimezone;
+    private String inputTimeformat;
+    private String outputTimezone;
+    private String outputTimeformat;
+
+    private String date;
+
+    public String getDate() {
+        return date;
+    }
+
+    public void setDate(String date) {
+        this.date = date;
+    }
+
+    @Override
+    public Converter<SI, SO, DI, DO> init(WorkUnitState workUnit) {
+        Calendar cal = Calendar.getInstance();
+        TimeZone tz = cal.getTimeZone();
+
+        
Preconditions.checkArgument(workUnit.contains(ConfigurationKeys.CONVERTER_INPUT_TIMEZONE),
 "Cannot use "
+                + this.getClass().getName() + " without specifying " + 
ConfigurationKeys.CONVERTER_INPUT_TIMEZONE);
+        
Preconditions.checkArgument(workUnit.contains(ConfigurationKeys.CONVERTER_INPUT_TIMEFORMAT),
 "Cannot use "
+                + this.getClass().getName() + " without specifying " + 
ConfigurationKeys.CONVERTER_INPUT_TIMEFORMAT);
+
+        this.inputTimezone = 
workUnit.getProp(ConfigurationKeys.CONVERTER_INPUT_TIMEZONE);
+        this.inputTimeformat = 
workUnit.getProp(ConfigurationKeys.CONVERTER_INPUT_TIMEFORMAT);
+        this.outputTimezone = 
workUnit.contains(ConfigurationKeys.CONVERTER_OUTPUT_TIMEZONE) ? 
workUnit.getProp(ConfigurationKeys.CONVERTER_OUTPUT_TIMEZONE) : 
tz.toZoneId().toString();
+        this.outputTimeformat = 
workUnit.contains(ConfigurationKeys.CONVERTER_OUTPUT_TIMEFORMAT) ? 
workUnit.getProp(ConfigurationKeys.CONVERTER_OUTPUT_TIMEFORMAT) : "MM-dd-yyyy 
HH:mm:ss z";
+
+        return this;
+    }
+
+    @Override
+    public SO convertSchema(SI inputSchema, WorkUnitState workUnit) throws 
SchemaConversionException {
+        return (SO)inputSchema;
+    }
+
+    @Override
+    public Iterable<DO> convertRecord(SO outputSchema, DI iR, WorkUnitState 
workUnit)
+            throws DataConversionException {
+        String inputRecord = "";
+        try{
+            Class inputRecordClass = iR.getClass();
+            Method inputRecordClassGetDate = 
inputRecordClass.getMethod("getDate", null);
+            inputRecord = (String)inputRecordClassGetDate.invoke(iR, null);
 
 Review comment:
   inputField than inputRecord
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 292385)
    Time Spent: 1h 20m  (was: 1h 10m)

> add date transformation converter
> ---------------------------------
>
>                 Key: GOBBLIN-835
>                 URL: https://issues.apache.org/jira/browse/GOBBLIN-835
>             Project: Apache Gobblin
>          Issue Type: New Feature
>    Affects Versions: 0.14.0
>            Reporter: Jay Sen
>            Priority: Major
>             Fix For: 0.15.0
>
>          Time Spent: 1h 20m
>  Remaining Estimate: 0h
>
> create new convertor for date formatĀ 



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to