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 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 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 new ArrowFormatPluginConfig(); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) ExcelFileConfig.getForFile(fileConfig); final ExcelFormatPluginConfig excelFormatPluginConfig = new ExcelFormatPluginConfig(); excelFormatPluginConfig.sheet = excelFileConfig.getSheetName(); excelFormatPluginConfig.extractHeader = excelFileConfig.getExtractHeader(); excelFormatPluginConfig.hasMergedCells = excelFileConfig.getHasMergedCells(); excelFormatPluginConfig.xls = false; return excelFormatPluginConfig;
final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString();
public ExcelFileConfig newMessage() { return new ExcelFileConfig(); }
@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); }
((ExcelFileConfig) file2Format).setExtractHeader(true); } else { ((XlsFileConfig) file2Format).setExtractHeader(true);
@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); }
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; }
return xlsFileConfig; } else { final ExcelFileConfig excelFileConfig = new ExcelFileConfig(); excelFileConfig.setExtractHeader(excelFormatPluginConfig.extractHeader); excelFileConfig.setHasMergedCells(excelFormatPluginConfig.hasMergedCells); excelFileConfig.setSheetName(excelFormatPluginConfig.sheet); return excelFileConfig;
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); }