5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-02 15:49:24 +08:00

A test is implemented for setting Avro schema file name.

This commit is contained in:
Szabolcs Vasas 2019-04-05 11:53:18 +02:00 committed by daniel voros
parent 83d40868c8
commit 43aedab8d4

View File

@ -38,6 +38,7 @@
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;
@ -94,6 +95,25 @@ public void testAvroImport() throws IOException {
avroImportTestHelper(null, null);
}
@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");
@ -366,8 +386,13 @@ protected DataFileReader<GenericRecord> read(Path filename) throws IOException {
}
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));
}
}