Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -159,19 +160,26 @@ private static Object[] toCSVRecord(Object job, ImmutableList<String> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> 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();
}
}
Loading