CreateSchemaForCsvFilesApp extends CsvAppTemplate<CreateSchemaForCsvFilesApp.Parameters> { public static void fromParameters(MetadataStore mds, Collection<String> fileLocations, String schemaName, String fieldSeparator, String quoteChar, boolean hasHeader) throws Exception { fromParameters(mds, fileLocations, schemaName, fieldSeparator, quoteChar, hasHeader, null); } CreateSchemaForCsvFilesApp(final CreateSchemaForCsvFilesApp.Parameters parameters); static void fromParameters(MetadataStore mds,
                                      Collection<String> fileLocations,
                                      String schemaName,
                                      String fieldSeparator,
                                      String quoteChar,
                                      boolean hasHeader); static void fromParameters(MetadataStore mds,
                                      Collection<String> fileLocations,
                                      String schemaName,
                                      String fieldSeparator,
                                      String quoteChar,
                                      boolean hasHeader,
                                      String sqlFile); static void main(final String[] args);  }
@Test public void testImportViaFromParameters() throws Exception { MetadataStore metadataStore = new DefaultMetadataStore(); File testFolder = getTestResource("test-schema"); CreateSchemaForCsvFilesApp.fromParameters( metadataStore, Collections.singleton(testFolder.getAbsolutePath()), "test-schema", ";", "\"", true ); Schema schema = metadataStore.getSchemaByName("test-schema"); Assert.assertNotNull("test-schema"); Assert.assertEquals(2, schema.getTables().size()); Table table1 = metadataStore.getTableByName("test-schema.table1"); Assert.assertNotNull(table1); Assert.assertEquals(3, table1.getColumns().size()); Column table1Comments = metadataStore.getColumnByName("test-schema.table2.dat.Comments"); Assert.assertNotNull(table1Comments); }
@Test public void testImportWithSqlFile() throws Exception { MetadataStore metadataStore = new DefaultMetadataStore(); File testFolder = getTestResource("test-schema"); CreateSchemaForCsvFilesApp.fromParameters( metadataStore, Collections.singleton(testFolder.getAbsolutePath()), "test-schema", ";", "\"", false, getTestResource("test-schema.sql").getAbsolutePath() ); Schema schema = metadataStore.getSchemaByName("test-schema"); Assert.assertNotNull("test-schema"); Assert.assertEquals(2, schema.getTables().size()); Table table1 = metadataStore.getTableByName("test-schema.table1"); Assert.assertNotNull(table1); Assert.assertEquals(3, table1.getColumns().size()); List<Column> columns = new ArrayList<>(table1.getColumns()); columns.sort(Comparator.comparingInt(c -> metadataStore.getIdUtils().getLocalColumnId(c.getId()))); Assert.assertEquals("NAME", columns.get(0).getName()); Assert.assertEquals("FIRST_NAME", columns.get(1).getName()); Assert.assertEquals("PROFESSION", columns.get(2).getName()); Table table2 = metadataStore.getTableByName("test-schema.table2.dat"); Assert.assertNotNull(table2); Assert.assertEquals(3, table2.getColumns().size()); columns = new ArrayList<>(table2.getColumns()); columns.sort(Comparator.comparingInt(c -> metadataStore.getIdUtils().getLocalColumnId(c.getId()))); Assert.assertEquals("PROFESSION", columns.get(0).getName()); Assert.assertEquals("RECOGNITION", columns.get(1).getName()); Assert.assertEquals("COMMENTS", columns.get(2).getName()); }
@Test public void testImportToSqliteViaFromParameters() throws Exception { File dbFile = File.createTempFile("test", "db"); dbFile.deleteOnExit(); SQLiteInterface sqliteInterface = SQLiteInterface.createForFile(dbFile); MetadataStore metadataStore = RDBMSMetadataStore.createNewInstance(sqliteInterface); File testFolder = getTestResource("test-schema"); CreateSchemaForCsvFilesApp.fromParameters( metadataStore, Collections.singleton(testFolder.getAbsolutePath()), "test-schema", ";", "\"", true ); Schema schema = metadataStore.getSchemaByName("test-schema"); Assert.assertNotNull("test-schema"); Assert.assertEquals(2, schema.getTables().size()); Table table1 = metadataStore.getTableByName("test-schema.table1"); Assert.assertNotNull(table1); Assert.assertEquals(3, table1.getColumns().size()); Column table1Comments = metadataStore.getColumnByName("test-schema.table2.dat.Comments"); Assert.assertNotNull(table1Comments); }