private String runBigDecimalImport(List<String> extraArgs) throws IOException { String[] types = { "DECIMAL", "NUMERIC" }; String[] vals = { "0.000001", "0.0000001" }; createTableWithColTypes(types, vals); List<String> args = new ArrayList<String>(); CommonArgs.addHadoopFlags(args); if (extraArgs!=null) { args.addAll(extraArgs); } args.add("--table"); args.add(getTableName()); args.add("--warehouse-dir"); args.add(getWarehouseDir()); args.add("--connect"); args.add(getConnectString()); args.add("-m"); args.add("1"); runImport(args.toArray(new String[args.size()])); Path outputFile = getDataFilePath(); FileSystem fs = FileSystem.get(getConf()); DataInputStream stream = fs.open(outputFile); BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); String line = reader.readLine(); reader.close(); return line; }
@Test public void testBigDecimalNoFormat() throws IOException { List<String> args = new ArrayList<String>(); args.add("-Dsqoop.bigdecimal.format.string=false"); String line = runBigDecimalImport(args); assertEquals("0.000001,1E-7", line); }
@Test public void testBigDecimalDefault() throws IOException { String line = runBigDecimalImport(null); assertEquals("0.000001,0.0000001", line); }