public ExcelFileConfig newMessage() { return new ExcelFileConfig(); }
public static FileFormat getEmptyConfig(FileType type) { switch (type) { case TEXT: case CSV: case TSV: case PSV: return new TextFileConfig(); case JSON: return new JsonFileConfig(); case PARQUET: return new ParquetFileConfig(); case AVRO: return new AvroFileConfig(); case HTTP_LOG: return new HttpLogFileConfig(); case EXCEL: return new ExcelFileConfig(); case XLS: return new XlsFileConfig(); case UNKNOWN: break; default: break; } return null; }
private Invocation getExcelTestQueryInvocation(String filePath, String sheet, boolean extractHeader, boolean hasMergedCells) throws Exception { ExcelFileConfig fileConfig = new ExcelFileConfig(); fileConfig.setSheetName(sheet); if (extractHeader) { fileConfig.setExtractHeader(true); } // false is the default value if (hasMergedCells) { fileConfig.setHasMergedCells(true); } // false is the default value return getBuilder(getAPIv2().path("/source/dacfs_test/file_preview" + filePath)) .buildPost(Entity.json(fileConfig)); }
@Test public void testDefaultExcelFileFormatOptions() throws Exception { ExcelFileConfig fileFormat = new ExcelFileConfig(); String tableOptions = fileFormat.toTableOptions(); assertContains("type => 'excel'", tableOptions); assertContains("extractHeader => false", tableOptions); assertContains("hasMergedCells => false", tableOptions); assertContains("xls => false", tableOptions); }
@Test public void testSheetExcelFile() throws Exception { ExcelFileConfig fileFormat = new ExcelFileConfig(); fileFormat.setSheetName("foo"); String tableOptions = fileFormat.toTableOptions(); assertContains("type => 'excel'", tableOptions); assertContains("xls => false", tableOptions); assertContains("sheet => 'foo'", tableOptions); }
@Test public void testSheetExcelFileWithSingleQuote() throws Exception { ExcelFileConfig fileFormat = new ExcelFileConfig(); fileFormat.setSheetName("fo'o"); String tableOptions = fileFormat.toTableOptions(); assertContains("type => 'excel'", tableOptions); assertContains("xls => false", tableOptions); assertContains("sheet => 'fo''o'", tableOptions); }
@Test public void testExtractHeaderExcelFile() throws Exception { ExcelFileConfig fileFormat = new ExcelFileConfig(); fileFormat.setExtractHeader(true); String tableOptions = fileFormat.toTableOptions(); assertContains("type => 'excel'", tableOptions); assertContains("xls => false", tableOptions); assertContains("extractHeader => true", tableOptions); }
@Test public void testHasMergedCellsExcelFile() throws Exception { ExcelFileConfig fileFormat = new ExcelFileConfig(); fileFormat.setHasMergedCells(true); String tableOptions = fileFormat.toTableOptions(); assertContains("type => 'excel'", tableOptions); assertContains("xls => false", tableOptions); assertContains("hasMergedCells => true", tableOptions); }
return xlsFileConfig; } else { final ExcelFileConfig excelFileConfig = new ExcelFileConfig(); excelFileConfig.setExtractHeader(excelFormatPluginConfig.extractHeader); excelFileConfig.setHasMergedCells(excelFormatPluginConfig.hasMergedCells);
private static void runTests(HomeFileConf homeFileStore) throws Exception { // text file Path textFile = new Path(FileUtils.getResourceAsFile("/datasets/text/comma.txt").getAbsolutePath()); uploadFile(homeFileStore, textFile, "comma", "txt", new TextFileConfig().setFieldDelimiter(","), null); Path csvFile = new Path(FileUtils.getResourceAsFile("/datasets/csv/comma.csv").getAbsolutePath()); uploadFile(homeFileStore, csvFile, "comma1", "csv", new TextFileConfig().setFieldDelimiter(","), null); Path jsonFile = new Path(FileUtils.getResourceAsFile("/datasets/users.json").getAbsolutePath()); uploadFile(homeFileStore, jsonFile, "users", "json", new JsonFileConfig(), null); Path excelFile = new Path(FileUtils.getResourceAsFile("/testfiles/excel.xlsx").getAbsolutePath()); uploadFile(homeFileStore, excelFile, "excel", "xlsx", new ExcelFileConfig(), null); // query files runQuery("comma", 4, 3, null); runQuery("comma1", 4, 3, null); runQuery("users", 3, 2, null); runQuery("excel", 6, 5, null); // add file to folder FolderPath folderPath = new FolderPath(ImmutableList.of(HomeName.getUserHomePath(DEFAULT_USER_NAME).getName(), "testupload")); newNamespaceService().addOrUpdateFolder(folderPath.toNamespaceKey(), new FolderConfig() .setName("testupload") .setFullPathList(folderPath.toPathList())); uploadFile(homeFileStore, textFile, "comma", "txt", new TextFileConfig().setFieldDelimiter(","), folderPath); runQuery("comma", 4, 3, folderPath); }