@Test public void testAvroWithUpsert() throws IOException, SQLException { String[] argv = { "--update-key", "ID", "--update-mode", "allowinsert" }; final int TOTAL_RECORDS = 2; // ColumnGenerator gen = colGenerator("100", // Schema.create(Schema.Type.STRING), null, "VARCHAR(64)"); createAvroFile(0, TOTAL_RECORDS); createTableWithInsert(); thrown.expect(Exception.class); thrown.reportMissingExceptionWithMessage("Expected Exception during Avro export with --update-mode"); runExport(getArgv(true, 10, 10, newStrArray(argv, "-m", "" + 1))); }
@Test public void testAvroWithUpdateKey() throws IOException, SQLException { String[] argv = { "--update-key", "ID" }; final int TOTAL_RECORDS = 1; // ColumnGenerator gen = colGenerator("100", // Schema.create(Schema.Type.STRING), null, "VARCHAR(64)"); createAvroFile(0, TOTAL_RECORDS); createTableWithInsert(); runExport(getArgv(true, 10, 10, newStrArray(argv, "-m", "" + 1))); verifyExport(getMsgPrefix() + "0"); }
@Test public void testNullableField() throws IOException, SQLException { String[] argv = {}; final int TOTAL_RECORDS = 1 * 10; List<Schema> childSchemas = new ArrayList<Schema>(); childSchemas.add(Schema.create(Schema.Type.NULL)); childSchemas.add(Schema.create(Schema.Type.STRING)); Schema schema = Schema.createUnion(childSchemas); ColumnGenerator gen0 = colGenerator(null, schema, null, "VARCHAR(64)"); ColumnGenerator gen1 = colGenerator("s", schema, "s", "VARCHAR(64)"); createAvroFile(0, TOTAL_RECORDS, gen0, gen1); createTable(gen0, gen1); runExport(getArgv(true, 10, 10, newStrArray(argv, "-m", "" + 1))); verifyExport(TOTAL_RECORDS); assertColMinAndMax(forIdx(0), gen0); assertColMinAndMax(forIdx(1), gen1); }
@Test public void testAvroRecordsNotSupported() throws IOException, SQLException { String[] argv = {}; final int TOTAL_RECORDS = 1; Schema schema = Schema.createRecord("nestedrecord", null, null, false); schema.setFields(Lists.newArrayList(buildAvroField("myint", Schema.Type.INT))); GenericRecord record = new GenericData.Record(schema); record.put("myint", 100); // DB type is not used so can be anything: ColumnGenerator gen = colGenerator(record, schema, null, "VARCHAR(64)"); createAvroFile(0, TOTAL_RECORDS, gen); createTable(gen); thrown.expect(Exception.class); thrown.reportMissingExceptionWithMessage("Expected Exception as Avro records are not supported"); runExport(getArgv(true, 10, 10, newStrArray(argv, "-m", "" + 1))); }
@Test public void testMissingAvroFields() throws IOException, SQLException { String[] argv = {}; final int TOTAL_RECORDS = 1; // null Avro schema means don't create an Avro field ColumnGenerator gen = colGenerator(null, null, null, "VARCHAR(64)"); createAvroFile(0, TOTAL_RECORDS, gen); createTable(gen); thrown.expect(Exception.class); thrown.reportMissingExceptionWithMessage("Expected Exception on missing Avro fields"); runExport(getArgv(true, 10, 10, newStrArray(argv, "-m", "" + 1))); }
@Test public void testMissingDatabaseFields() throws IOException, SQLException { String[] argv = {}; final int TOTAL_RECORDS = 1; // null column type means don't create a database column // the Avro value will not be exported ColumnGenerator gen = colGenerator(100, Schema.create(Schema.Type.INT), null, null); createAvroFile(0, TOTAL_RECORDS, gen); createTable(gen); runExport(getArgv(true, 10, 10, newStrArray(argv, "-m", "" + 1))); verifyExport(TOTAL_RECORDS); }
createAvroFile(0, TOTAL_RECORDS, gens); createTable(gens); runExport(getArgv(true, 10, 10, newStrArray(argv, "-m", "" + 1))); verifyExport(TOTAL_RECORDS); for (int i = 0; i < gens.length; i++) {
@Test public void testSpecifiedColumnsAsAvroFields() throws IOException, SQLException { final int TOTAL_RECORDS = 10; ColumnGenerator[] gens = new ColumnGenerator[] { colGenerator(000, Schema.create(Schema.Type.INT), 100, "INTEGER"), //col0 colGenerator(111, Schema.create(Schema.Type.INT), 100, "INTEGER"), //col1 colGenerator(222, Schema.create(Schema.Type.INT), 100, "INTEGER"), //col2 colGenerator(333, Schema.create(Schema.Type.INT), 100, "INTEGER") //col3 }; createAvroFile(0, TOTAL_RECORDS, gens); createTable(gens); runExport(getArgv(true, 10, 10, newStrArray(null, "-m", "" + 1, "--columns", "ID,MSG,COL1,COL2"))); verifyExport(TOTAL_RECORDS); assertColValForRowId(0, "col0", null); assertColValForRowId(0, "col1", 111); assertColValForRowId(0, "col2", 222); assertColValForRowId(0, "col3", null); assertColValForRowId(9, "col0", null); assertColValForRowId(9, "col1", 111); assertColValForRowId(9, "col2", 222); assertColValForRowId(9, "col3", null); }