SQOOP-3380: parquet-configurator-implementation is not recognized as an option
authorSzabolcs Vasas <vasas@apache.org>
Wed, 12 Sep 2018 02:19:09 +0000 (09:19 +0700)
committerSzabolcs Vasas <vasas@apache.org>
Wed, 12 Sep 2018 02:19:09 +0000 (09:19 +0700)
(Szabolcs Vasas)

src/java/org/apache/sqoop/tool/BaseSqoopTool.java
src/test/org/apache/sqoop/tool/TestBaseSqoopTool.java

index b47be72..955d3a6 100644 (file)
@@ -547,6 +547,11 @@ public abstract class BaseSqoopTool extends org.apache.sqoop.tool.SqoopTool {
         .hasArg()
         .withArgName("boolean")
         .create());
+    commonOpts.addOption(OptionBuilder
+        .hasArg()
+        .withDescription("The implementation used during Parquet reading/writing")
+        .withLongOpt(PARQUET_CONFIGURATOR_IMPLEMENTATION)
+        .create());
 
     return commonOpts;
   }
index 5571b25..aecfa8b 100644 (file)
@@ -19,7 +19,9 @@
 package org.apache.sqoop.tool;
 
 import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
 import org.apache.sqoop.SqoopOptions;
+import org.apache.sqoop.cli.RelatedOptions;
 import org.apache.sqoop.mapreduce.parquet.ParquetJobConfiguratorImplementation;
 import org.junit.Before;
 import org.junit.Rule;
@@ -30,11 +32,14 @@ import org.mockito.Mockito;
 import static org.apache.sqoop.mapreduce.parquet.ParquetJobConfiguratorImplementation.HADOOP;
 import static org.hamcrest.CoreMatchers.sameInstance;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 public class TestBaseSqoopTool {
 
+  private static final String PARQUET_CONFIGURATOR_IMPLEMENTATION = "parquet-configurator-implementation";
+
   @Rule
   public ExpectedException exception = ExpectedException.none();
 
@@ -80,7 +85,7 @@ public class TestBaseSqoopTool {
   public void testApplyCommonOptionsSetsParquetJobConfigurationImplementationFromCommandLine() throws Exception {
     ParquetJobConfiguratorImplementation expectedValue = HADOOP;
 
-    when(mockCommandLine.getOptionValue("parquet-configurator-implementation")).thenReturn(expectedValue.toString());
+    when(mockCommandLine.getOptionValue(PARQUET_CONFIGURATOR_IMPLEMENTATION)).thenReturn(expectedValue.toString());
 
     testBaseSqoopTool.applyCommonOptions(mockCommandLine, testSqoopOptions);
 
@@ -91,7 +96,7 @@ public class TestBaseSqoopTool {
   public void testApplyCommonOptionsSetsParquetJobConfigurationImplementationFromCommandLineCaseInsensitively() throws Exception {
     String hadoopImplementationLowercase = "haDooP";
 
-    when(mockCommandLine.getOptionValue("parquet-configurator-implementation")).thenReturn(hadoopImplementationLowercase);
+    when(mockCommandLine.getOptionValue(PARQUET_CONFIGURATOR_IMPLEMENTATION)).thenReturn(hadoopImplementationLowercase);
 
     testBaseSqoopTool.applyCommonOptions(mockCommandLine, testSqoopOptions);
 
@@ -112,7 +117,7 @@ public class TestBaseSqoopTool {
   public void testApplyCommonOptionsPrefersParquetJobConfigurationImplementationFromCommandLine() throws Exception {
     ParquetJobConfiguratorImplementation expectedValue = HADOOP;
     testSqoopOptions.getConf().set("parquetjob.configurator.implementation", "kite");
-    when(mockCommandLine.getOptionValue("parquet-configurator-implementation")).thenReturn(expectedValue.toString());
+    when(mockCommandLine.getOptionValue(PARQUET_CONFIGURATOR_IMPLEMENTATION)).thenReturn(expectedValue.toString());
 
     testBaseSqoopTool.applyCommonOptions(mockCommandLine, testSqoopOptions);
 
@@ -121,7 +126,7 @@ public class TestBaseSqoopTool {
 
   @Test
   public void testApplyCommonOptionsThrowsWhenInvalidParquetJobConfigurationImplementationIsSet() throws Exception {
-    when(mockCommandLine.getOptionValue("parquet-configurator-implementation")).thenReturn("this_is_definitely_not_valid");
+    when(mockCommandLine.getOptionValue(PARQUET_CONFIGURATOR_IMPLEMENTATION)).thenReturn("this_is_definitely_not_valid");
 
     exception.expectMessage("Invalid Parquet job configurator implementation is set: this_is_definitely_not_valid. Supported values are: [HADOOP]");
     testBaseSqoopTool.applyCommonOptions(mockCommandLine, testSqoopOptions);
@@ -133,4 +138,19 @@ public class TestBaseSqoopTool {
 
     assertEquals(HADOOP, testSqoopOptions.getParquetConfiguratorImplementation());
   }
+
+  @Test
+  public void testGetCommonOptionsAddsParquetJobConfigurationImplementation() {
+    RelatedOptions commonOptions = testBaseSqoopTool.getCommonOptions();
+
+    assertTrue(commonOptions.hasOption(PARQUET_CONFIGURATOR_IMPLEMENTATION));
+  }
+
+  @Test
+  public void testParquetJobConfigurationImplementationOptionHasAnArg() {
+    RelatedOptions commonOptions = testBaseSqoopTool.getCommonOptions();
+
+    Option implementationOption = commonOptions.getOption(PARQUET_CONFIGURATOR_IMPLEMENTATION);
+    assertTrue(implementationOption.hasArg());
+  }
 }