diff --git a/dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/connector/hadoop/oozie/AbstractOozieJobsTask.java b/dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/connector/hadoop/oozie/AbstractOozieJobsTask.java index 39e51f865..082e87776 100644 --- a/dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/connector/hadoop/oozie/AbstractOozieJobsTask.java +++ b/dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/connector/hadoop/oozie/AbstractOozieJobsTask.java @@ -18,6 +18,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; @@ -159,19 +160,26 @@ private static Object[] toCSVRecord(Object job, ImmutableList header) th Object[] record = new Object[header.size()]; BeanWrapper jobObjectWrapper = new BeanWrapperImpl(job); for (int i = 0; i < header.size(); i++) { - record[i] = jobObjectWrapper.getPropertyValue(header.get(i)); - if (record[i] != null && record[i] instanceof Date) { - // avoid date formats complexity and use milliseconds - record[i] = ((Date) record[i]).getTime(); - } - if (record[i] != null && record[i] instanceof List) { - // write Actions arrays as json string in csv - record[i] = objectMapper.writeValueAsString(record[i]); + Object property = jobObjectWrapper.getPropertyValue(header.get(i)); + if (property != null) { + record[i] = toRecordProperty(property); } } return record; } + static Object toRecordProperty(Object property) throws JsonProcessingException { + if (property instanceof Date) { + // avoid date formats complexity and use milliseconds + return ((Date) property).getTime(); + } else if (property instanceof List) { + // write Actions arrays as json string in csv + return objectMapper.writeValueAsString(property); + } else { + return property; + } + } + @VisibleForTesting ZonedDateTime getStartDate() { return startDate; diff --git a/dumper/app/src/test/java/com/google/edwmigration/dumper/application/dumper/connector/hadoop/oozie/AbstractOozieJobsTaskTest.java b/dumper/app/src/test/java/com/google/edwmigration/dumper/application/dumper/connector/hadoop/oozie/AbstractOozieJobsTaskTest.java new file mode 100644 index 000000000..85e534a82 --- /dev/null +++ b/dumper/app/src/test/java/com/google/edwmigration/dumper/application/dumper/connector/hadoop/oozie/AbstractOozieJobsTaskTest.java @@ -0,0 +1,67 @@ +/* + * Copyright 2022-2025 Google LLC + * Copyright 2013-2021 CompilerWorks + * + * Licensed 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 com.google.edwmigration.dumper.application.dumper.connector.hadoop.oozie; + +import static org.junit.Assert.assertEquals; + +import com.google.common.collect.ImmutableList; +import java.text.SimpleDateFormat; +import java.util.Date; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class AbstractOozieJobsTaskTest { + + static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + + @Test + public void toRecordProperty_dateArgument_convertsToLong() throws Exception { + Date christmas = dateFormat.parse("2025-12-25"); + + Object result = AbstractOozieJobsTask.toRecordProperty(christmas); + + assertEquals(Long.class, result.getClass()); + assertEquals("2025-12-25", convertDate(result)); + } + + @Test + public void toRecordProperty_listArgument_success() throws Exception { + ImmutableList list = ImmutableList.of("abcde", "fghi"); + + Object result = AbstractOozieJobsTask.toRecordProperty(list); + + assertEquals("[\"abcde\",\"fghi\"]", result); + } + + @Test + public void toRecordProperty_otherArgument_nothingChanges() throws Exception { + Object value = new Object(); + + Object result = AbstractOozieJobsTask.toRecordProperty(value); + + assertEquals(value, result); + } + + private static String convertDate(Object date) { + if (date instanceof Long) { + return dateFormat.format(new Date((Long) date)); + } + throw new RuntimeException(); + } +}