Esempio n. 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());
 }
Esempio n. 2
0
 private void assertSpace1(String spaceName) throws ASException, ParseException {
   Space space1 = metaspace.getSpace(spaceName);
   Assert.assertEquals(17, space1.size());
   Tuple tuple18 = Tuple.create();
   tuple18.putLong("Field1", 18);
   tuple18 = space1.get(tuple18);
   SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yy");
   Date date18 = dateFormat.parse("1/18/14");
   Assert.assertEquals(DateTime.create(date18.getTime()), tuple18.getDateTime("Field2"));
   Assert.assertEquals(null, tuple18.getBoolean("Field4"));
   Assert.assertEquals('q', tuple18.getChar("Field3").charValue());
 }