Beispiel #1
0
 @Test
 public void testExcel97Multisheet() throws Exception {
   DateFormat dateFormat = new SimpleDateFormat("MM/dd/yy");
   dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
   String spaceName = "space1";
   SpaceDef spaceDef =
       SpaceDef.create(
           spaceName,
           0,
           Arrays.asList(
               FieldDef.create("Field1", FieldType.LONG),
               FieldDef.create("Field2", FieldType.DATETIME).setNullable(true),
               FieldDef.create("Field3", FieldType.CHAR).setNullable(true),
               FieldDef.create("Field4", FieldType.BOOLEAN).setNullable(true)));
   spaceDef.setKey("Field1");
   metaspace.defineSpace(spaceDef);
   Space space = metaspace.getSpace(spaceName, DistributionRole.SEEDER);
   space.waitForReady(1000);
   int batchSize = 1000;
   long size = 70000;
   List<Tuple> list = new ArrayList<Tuple>(batchSize);
   for (long index = 1; index <= size; index++) {
     Tuple tuple = Tuple.create();
     tuple.putLong("Field1", index);
     Date date = dateFormat.parse(MessageFormat.format("1/{0}/14", (index % 25) + 1));
     tuple.putDateTime("Field2", DateTime.create(date.getTime()));
     tuple.putChar("Field3", (char) index);
     tuple.putBoolean("Field4", index % 2 == 0);
     list.add(tuple);
     if (list.size() == batchSize) {
       space.putAll(list);
       list.clear();
     }
   }
   File file = new File(dir, "multisheet.xls");
   ExcelExporter exporter = new ExcelExporter(metaspace, file);
   ExcelExport export = new ExcelExport();
   export.setQueryLimit(-1L);
   export.setSpaceName(spaceName);
   export.setHeader(true);
   exporter.addTransfer(export);
   exporter.execute();
   Assert.assertEquals(size, space.size());
   space.closeAll();
   metaspace.dropSpace(spaceName);
   metaspace.defineSpace(spaceDef);
   space = metaspace.getSpace(spaceName, DistributionRole.SEEDER);
   Assert.assertEquals(0, space.size());
   ExcelImporter importer = new ExcelImporter(metaspace, file);
   ExcelImport config = new ExcelImport();
   config.setHeader(true);
   config.setDistributionRole(DistributionRole.SEEDER);
   importer.setDefaultTransfer(config);
   importer.execute();
   Assert.assertEquals(size, space.size());
 }
Beispiel #2
0
 @Test
 public void testXLSWithHeader() throws Exception {
   ExcelImport import1 = createExcelImport();
   import1.setHeader(true);
   testExcelImporter("ms.xls", import1);
   Space space1 = metaspace.getSpace("space1");
   Tuple tuple1 = Tuple.create();
   tuple1.putLong("Field1", 1);
   tuple1 = space1.get(tuple1);
   Assert.assertEquals("2", tuple1.getString("Field5"));
 }
Beispiel #3
0
 @Test
 public void testXLSXHeaderDefault() throws Exception {
   File file = copy("ms.xlsx", dir);
   ExcelImporter importer = new ExcelImporter(metaspace, file);
   ExcelImport defaultConfig = new ExcelImport();
   defaultConfig.setHeader(true);
   defaultConfig.setDistributionRole(DistributionRole.SEEDER);
   defaultConfig.setKeepSpaceOpen(true);
   importer.setDefaultTransfer(defaultConfig);
   importer.execute();
   assertSpace1("space1");
 }
Beispiel #4
0
 private void configure(ExcelImport config) {
   config.setFields(
       new Field("Field1", FieldType.LONG, true),
       new Field("Field2", FieldType.DATETIME, false, true),
       new Field("Field3", FieldType.CHAR, false, true),
       new Field("Field4", FieldType.BOOLEAN, false, true));
 }
Beispiel #5
0
 @Test
 public void testXLSXWithHeader() throws Exception {
   ExcelImport import1 = createExcelImport();
   import1.setHeader(true);
   testExcelImporter("ms.xlsx", import1);
 }