From 005e5d6af82679b64a9683366aa5ae67e216f18d Mon Sep 17 00:00:00 2001 From: Szabolcs Vasas Date: Thu, 16 Aug 2018 11:58:31 +0200 Subject: [PATCH] SQOOP-3362: Fix toString() methods of OraOopOracleDataChunk (Nguyen Truong via Szabolcs Vasas) --- .../manager/oracle/OraOopDBInputSplit.java | 3 +- .../manager/oracle/OraOopOracleDataChunk.java | 20 ---- .../oracle/OraOopOracleDataChunkExtent.java | 9 ++ .../OraOopOracleDataChunkPartition.java | 7 ++ ...TestOraOopDBInputSplitGetDebugDetails.java | 104 ++++++++++++++++++ 5 files changed, 122 insertions(+), 21 deletions(-) create mode 100644 src/test/org/apache/sqoop/manager/oracle/TestOraOopDBInputSplitGetDebugDetails.java diff --git a/src/java/org/apache/sqoop/manager/oracle/OraOopDBInputSplit.java b/src/java/org/apache/sqoop/manager/oracle/OraOopDBInputSplit.java index 948bdbb7..d3675b2b 100644 --- a/src/java/org/apache/sqoop/manager/oracle/OraOopDBInputSplit.java +++ b/src/java/org/apache/sqoop/manager/oracle/OraOopDBInputSplit.java @@ -167,8 +167,9 @@ public String getDebugDetails() { "Split[%s] does not contain any Oracle data-chunks.", this.splitId)); } else { result.append(String.format( - "Split[%s] includes the Oracle data-chunks:\n", this.splitId)); + "Split[%s] includes the Oracle data-chunks:", this.splitId)); for (OraOopOracleDataChunk dataChunk : getDataChunks()) { + result.append("\n\t Data chunk info:"); result.append(dataChunk.toString()); } } diff --git a/src/java/org/apache/sqoop/manager/oracle/OraOopOracleDataChunk.java b/src/java/org/apache/sqoop/manager/oracle/OraOopOracleDataChunk.java index eb67fd2e..f65e8836 100644 --- a/src/java/org/apache/sqoop/manager/oracle/OraOopOracleDataChunk.java +++ b/src/java/org/apache/sqoop/manager/oracle/OraOopOracleDataChunk.java @@ -18,8 +18,6 @@ package org.apache.sqoop.manager.oracle; -import java.lang.reflect.Field; - import org.apache.hadoop.io.Writable; /** @@ -39,24 +37,6 @@ public String getPartitionClause() { return ""; } - @Override - public String toString() { - - String result = super.toString(); - for (Field field : this.getClass().getDeclaredFields()) { - try { - Object fieldValue = field.get(this); - result += - String.format("\n\t%s = %s", field.getName(), - (fieldValue == null ? "null" : fieldValue.toString())); - } catch (IllegalAccessException ex) { - // Ignore this exception. - } - } - - return result; - } - public String getId() { return id; } diff --git a/src/java/org/apache/sqoop/manager/oracle/OraOopOracleDataChunkExtent.java b/src/java/org/apache/sqoop/manager/oracle/OraOopOracleDataChunkExtent.java index 20b39eea..95917422 100644 --- a/src/java/org/apache/sqoop/manager/oracle/OraOopOracleDataChunkExtent.java +++ b/src/java/org/apache/sqoop/manager/oracle/OraOopOracleDataChunkExtent.java @@ -90,4 +90,13 @@ public long getNumberOfBlocks() { } } + public String toString(){ + StringBuilder result = new StringBuilder(); + result.append("\n\t\t id = ").append(getId()); + result.append("\n\t\t oracleDataObjectId = ").append(oracleDataObjectId); + result.append("\n\t\t relativeDatafileNumber = ").append(relativeDatafileNumber); + result.append("\n\t\t startBlockNumber = ").append(startBlockNumber); + result.append("\n\t\t finishBlockNumber = ").append(finishBlockNumber); + return result.toString(); + } } diff --git a/src/java/org/apache/sqoop/manager/oracle/OraOopOracleDataChunkPartition.java b/src/java/org/apache/sqoop/manager/oracle/OraOopOracleDataChunkPartition.java index 59889b82..ea1a3881 100644 --- a/src/java/org/apache/sqoop/manager/oracle/OraOopOracleDataChunkPartition.java +++ b/src/java/org/apache/sqoop/manager/oracle/OraOopOracleDataChunkPartition.java @@ -75,4 +75,11 @@ public String getPartitionClause() { return sb.toString(); } + public String toString(){ + StringBuilder result = new StringBuilder(); + result.append("\n\t\t id = ").append(getId()); + result.append("\n\t\t isSubPartition = ").append(isSubPartition); + result.append("\n\t\t blocks = ").append(blocks); + return result.toString(); + } } diff --git a/src/test/org/apache/sqoop/manager/oracle/TestOraOopDBInputSplitGetDebugDetails.java b/src/test/org/apache/sqoop/manager/oracle/TestOraOopDBInputSplitGetDebugDetails.java new file mode 100644 index 00000000..6f33ad3b --- /dev/null +++ b/src/test/org/apache/sqoop/manager/oracle/TestOraOopDBInputSplitGetDebugDetails.java @@ -0,0 +1,104 @@ +/** + * 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.sqoop.manager.oracle; + +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class TestOraOopDBInputSplitGetDebugDetails { + private OraOopDBInputSplit firstSplit; + private OraOopDBInputSplit secondSplit; + private String firstSplitResult; + + @Before + public void initialize() { + List dataChunkList = new ArrayList<>(); + OraOopOracleDataChunkExtent firstDataChunkExtent = new OraOopOracleDataChunkExtent("firstExtent", + 666,1, 10500, 10507); + OraOopOracleDataChunkExtent secondDataChunkExtent = new OraOopOracleDataChunkExtent("secondExtent", + 666,1, 10508, 10515); + OraOopOracleDataChunkExtent thirdDataChunkExtent = new OraOopOracleDataChunkExtent("thirdExtent", + 666,1, 10516, 10523); + OraOopOracleDataChunkExtent fourthDataChunkExtent = new OraOopOracleDataChunkExtent("fourthExtent", + 787,2, 11434, 11450); + OraOopOracleDataChunkPartition firstDataChunkPartition = new OraOopOracleDataChunkPartition("firstPartition", + true, 14); + OraOopOracleDataChunkPartition secondDataChunkPartition = new OraOopOracleDataChunkPartition("secondPartition", + false, 4); + OraOopOracleDataChunkPartition thirdDataChunkPartition = new OraOopOracleDataChunkPartition("thirdPartition", + false, 43); + dataChunkList.addAll(Arrays.asList(firstDataChunkExtent, secondDataChunkExtent, thirdDataChunkExtent, + fourthDataChunkExtent, firstDataChunkPartition, secondDataChunkPartition, thirdDataChunkPartition)); + firstSplit = new OraOopDBInputSplit(dataChunkList); + secondSplit = new OraOopDBInputSplit(); + firstSplitResult = "Split[0] includes the Oracle data-chunks:" + + "\n\t Data chunk info:" + + "\n\t\t id = firstExtent" + + "\n\t\t oracleDataObjectId = 666" + + "\n\t\t relativeDatafileNumber = 1" + + "\n\t\t startBlockNumber = 10500" + + "\n\t\t finishBlockNumber = 10507" + + "\n\t Data chunk info:" + + "\n\t\t id = secondExtent" + + "\n\t\t oracleDataObjectId = 666" + + "\n\t\t relativeDatafileNumber = 1" + + "\n\t\t startBlockNumber = 10508" + + "\n\t\t finishBlockNumber = 10515" + + "\n\t Data chunk info:" + + "\n\t\t id = thirdExtent" + + "\n\t\t oracleDataObjectId = 666" + + "\n\t\t relativeDatafileNumber = 1" + + "\n\t\t startBlockNumber = 10516" + + "\n\t\t finishBlockNumber = 10523" + + "\n\t Data chunk info:" + + "\n\t\t id = fourthExtent" + + "\n\t\t oracleDataObjectId = 787" + + "\n\t\t relativeDatafileNumber = 2" + + "\n\t\t startBlockNumber = 11434" + + "\n\t\t finishBlockNumber = 11450" + + "\n\t Data chunk info:" + + "\n\t\t id = firstPartition" + + "\n\t\t isSubPartition = true" + + "\n\t\t blocks = 14" + + "\n\t Data chunk info:" + + "\n\t\t id = secondPartition" + + "\n\t\t isSubPartition = false" + + "\n\t\t blocks = 4" + + "\n\t Data chunk info:" + + "\n\t\t id = thirdPartition" + + "\n\t\t isSubPartition = false" + + "\n\t\t blocks = 43"; + } + + @Test + public void testGetDebugDetails() { + assertEquals(firstSplitResult, firstSplit.getDebugDetails()); + } + + @Test + public void testEmptySplitDebugDetails(){ + assertEquals("Split[-1] does not contain any Oracle data-chunks.", secondSplit.getDebugDetails()); + } +}