This is an automated email from the ASF dual-hosted git repository.
vasas pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/sqoop.git
The following commit(s) were added to refs/heads/trunk by this push:
new 1a04d20 SQOOP-3134: --class-name should override default Avro schema
name
1a04d20 is described below
commit 1a04d2007d7e4e111d9cde9efbe3485547075fc6
Author: daniel voros <[email protected]>
AuthorDate: Fri Apr 5 16:15:15 2019 +0200
SQOOP-3134: --class-name should override default Avro schema name
---
src/docs/user/import.txt | 8 ++++++
.../org/apache/sqoop/orm/AvroSchemaGenerator.java | 2 +-
src/test/org/apache/sqoop/TestAvroImport.java | 29 ++++++++++++++++++++--
3 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/src/docs/user/import.txt b/src/docs/user/import.txt
index ae7c7ed..d58e90c 100644
--- a/src/docs/user/import.txt
+++ b/src/docs/user/import.txt
@@ -348,6 +348,11 @@ For example _AVRO will be converted to __AVRO.
In the case of HCatalog imports, column names are converted to lower case when
mapped to HCatalog columns. This may change in future.
+During Avro imports the table's schema is saved in an +.avsc+ file under the
+output directory (configured via +\--bindir+). The +\--class-name+ option can
+be used to change the resulting file's name, which defaults to the table name
+or in case of +\--query+ imports to +AutoGeneratedSchema+.
+
Incremental Imports
^^^^^^^^^^^^^^^^^^^
@@ -702,6 +707,9 @@ $ sqoop import --table SomeTable --jar-file mydatatypes.jar
\
This command will load the +SomeTableType+ class out of +mydatatypes.jar+.
+NOTE: The +\--class-name+ option also affects the +.avsc+ file's name
+generated during Avro imports.
+
Additional Import Configuration Properties
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
There are some additional properties which can be configured by modifying
diff --git a/src/java/org/apache/sqoop/orm/AvroSchemaGenerator.java
b/src/java/org/apache/sqoop/orm/AvroSchemaGenerator.java
index 05ac46c..4df3ef8 100644
--- a/src/java/org/apache/sqoop/orm/AvroSchemaGenerator.java
+++ b/src/java/org/apache/sqoop/orm/AvroSchemaGenerator.java
@@ -104,7 +104,7 @@ public class AvroSchemaGenerator {
}
TableClassName tableClassName = new TableClassName(options);
- String shortClassName = tableName == null ? DEFAULT_SCHEMA_NAME :
tableClassName.getShortClassForTable(tableName);
+ String shortClassName = (tableName == null && options.getClassName() ==
null) ? DEFAULT_SCHEMA_NAME : tableClassName.getShortClassForTable(tableName);
String avroTableName = (tableName == null ? TableClassName.QUERY_RESULT :
tableName);
String avroName = schemaNameOverride != null ? schemaNameOverride :
(shortClassName == null ? avroTableName : shortClassName);
diff --git a/src/test/org/apache/sqoop/TestAvroImport.java
b/src/test/org/apache/sqoop/TestAvroImport.java
index 2666f50..3aded59 100644
--- a/src/test/org/apache/sqoop/TestAvroImport.java
+++ b/src/test/org/apache/sqoop/TestAvroImport.java
@@ -38,6 +38,7 @@ import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
+import org.apache.sqoop.testutil.ArgumentArrayBuilder;
import org.apache.sqoop.testutil.AvroTestUtils;
import org.apache.sqoop.testutil.CommonArgs;
import org.apache.sqoop.testutil.HsqldbTestServer;
@@ -95,6 +96,25 @@ public class TestAvroImport extends ImportJobTestCase {
}
@Test
+ public void testAvroFileNameWithQueryImport() throws IOException {
+ setCurTableName("AVRO_FILE_NAME_QUERY_IMPORT");
+ createTableWithColTypes(new String[] {"int"}, new String[] {"1"});
+ ArgumentArrayBuilder builder = new ArgumentArrayBuilder();
+ String[] args = builder
+ .withOption("connect", HsqldbTestServer.getUrl())
+ .withOption("query", "select * from AVRO_FILE_NAME_QUERY_IMPORT where
$CONDITIONS")
+ .withOption("as-avrodatafile")
+ .withOption("m", "1")
+ .withOption("target-dir", getWarehouseDir() +
"/AVRO_FILE_NAME_QUERY_IMPORT")
+ .withOption("class-name", "customAvroFile")
+ .build();
+
+ runImport(args);
+
+ verifySchemaFileName("customAvroFile.avsc");
+ }
+
+ @Test
public void testDeflateCompressedAvroImport() throws IOException {
this.setCurTableName("Deflate_Compressed_Avro_Import_Test_1");
avroImportTestHelper(new String[] {"--compression-codec",
@@ -366,8 +386,13 @@ public class TestAvroImport extends ImportJobTestCase {
}
protected void checkSchemaFile(final Schema schema) throws IOException {
- final File schemaFile = new File(schema.getName() + ".avsc");
+ String schemaFileName = schema.getName() + ".avsc";
+ verifySchemaFileName(schemaFileName);
+ assertEquals(schema, new Schema.Parser().parse(new File(schemaFileName)));
+ }
+
+ protected void verifySchemaFileName(String expectedFileName) {
+ final File schemaFile = new File(expectedFileName);
assertTrue(schemaFile.exists());
- assertEquals(schema, new Schema.Parser().parse(schemaFile));
}
}