@Test public void testSchemaDatasource() throws Exception { Map<String, Datasource> nameToDatasource = new HashMap<>(); nameToDatasource.put("mock", new MockDatasource("mock2", List.of("column", "column2", "column3"), List.of(new MockDataset("ds", Map.of("column", "value", "column2", "value2", "column3", "value3"))))); Datasource ds = new SchemaDatasource(nameToDatasource, new ConfigThingy("", "NAME \"schema\" SOURCE \"mock\" DROP (\"column\") RENAME (\"column2\" \"renameColumn\") ADD (\"newColumn\")"), null); assertEquals("schema", ds.getName()); assertEquals(List.of("column3", "newColumn", "renameColumn"), ds.getSchema()); QueryResults results = ds.getContents(); assertEquals(0, results.size()); results = ds.getDatasetsByKey(List.of("ds")); assertEquals(1, results.size()); results = ds.find(List.of(new QueryPart("renameColumn", "value2"))); assertEquals(1, results.size()); Dataset data = results.iterator().next(); assertEquals("ds", data.getKey()); assertThrows(ColumnNotFoundException.class, () -> data.get("column")); assertEquals("value2", data.get("renameColumn")); assertEquals("value3", data.get("column3")); assertNull(data.get("newColumn")); assertTrue(ds.find(List.of(new QueryPart("unkown", "value"))).isEmpty()); assertTrue(ds.find(List.of(new QueryPart("newColumn", "value"))).isEmpty()); assertFalse(ds.find(List.of(new QueryPart("column3", "value3"))).isEmpty()); }
public SchemaDatasource(Map<String, Datasource> nameToDatasource, ConfigThingy sourceDesc, URL context) { name = parseConfig(sourceDesc, "NAME", () -> L.m("NAME der Datenquelle fehlt")); sourceName = parseConfig(sourceDesc, "SOURCE", () -> L.m("SOURCE der Datenquelle %1 fehlt", name)); source = nameToDatasource.get(sourceName); if (source == null) throw new ConfigurationErrorException( L.m( "Fehler bei Initialisierung von Datenquelle \"%1\": Referenzierte Datenquelle \"%2\" nicht (oder fehlerhaft) definiert", name, sourceName)); schema = new ArrayList<>(source.getSchema()); mapNewToOld = new HashMap<>(); List<String> columnsToDrop = dropColumns(sourceDesc.query("DROP")); List<String> columnsToAdd = addColumns(sourceDesc.query("ADD"), columnsToDrop); renameColumn(sourceDesc.query("RENAME"), columnsToDrop, columnsToAdd); for (String spalte : columnsToAdd) { if (!schema.contains(spalte) && !mapNewToOld.containsKey(spalte)) mapNewToOld.put(spalte, EMPTY_COLUMN); } schema.removeAll(columnsToDrop); schema.addAll(columnsToAdd); }
SchemaDatasource extends Datasource { public SchemaDatasource(Map<String, Datasource> nameToDatasource, ConfigThingy sourceDesc, URL context) { name = parseConfig(sourceDesc, "NAME", () -> L.m("NAME der Datenquelle fehlt")); sourceName = parseConfig(sourceDesc, "SOURCE", () -> L.m("SOURCE der Datenquelle %1 fehlt", name)); source = nameToDatasource.get(sourceName); if (source == null) throw new ConfigurationErrorException( L.m( "Fehler bei Initialisierung von Datenquelle \"%1\": Referenzierte Datenquelle \"%2\" nicht (oder fehlerhaft) definiert", name, sourceName)); schema = new ArrayList<>(source.getSchema()); mapNewToOld = new HashMap<>(); List<String> columnsToDrop = dropColumns(sourceDesc.query("DROP")); List<String> columnsToAdd = addColumns(sourceDesc.query("ADD"), columnsToDrop); renameColumn(sourceDesc.query("RENAME"), columnsToDrop, columnsToAdd); for (String spalte : columnsToAdd) { if (!schema.contains(spalte) && !mapNewToOld.containsKey(spalte)) mapNewToOld.put(spalte, EMPTY_COLUMN); } schema.removeAll(columnsToDrop); schema.addAll(columnsToAdd); } }
SchemaDatasource extends Datasource { public SchemaDatasource(Map<String, Datasource> nameToDatasource, ConfigThingy sourceDesc, URL context) { name = parseConfig(sourceDesc, "NAME", () -> L.m("NAME der Datenquelle fehlt")); sourceName = parseConfig(sourceDesc, "SOURCE", () -> L.m("SOURCE der Datenquelle %1 fehlt", name)); source = nameToDatasource.get(sourceName); if (source == null) throw new ConfigurationErrorException( L.m( "Fehler bei Initialisierung von Datenquelle \"%1\": Referenzierte Datenquelle \"%2\" nicht (oder fehlerhaft) definiert", name, sourceName)); schema = new ArrayList<>(source.getSchema()); mapNewToOld = new HashMap<>(); List<String> columnsToDrop = dropColumns(sourceDesc.query("DROP")); List<String> columnsToAdd = addColumns(sourceDesc.query("ADD"), columnsToDrop); renameColumn(sourceDesc.query("RENAME"), columnsToDrop, columnsToAdd); for (String spalte : columnsToAdd) { if (!schema.contains(spalte) && !mapNewToOld.containsKey(spalte)) mapNewToOld.put(spalte, EMPTY_COLUMN); } schema.removeAll(columnsToDrop); schema.addAll(columnsToAdd); } SchemaDatasource(Map<String, Datasource> nameToDatasource,
      ConfigThingy sourceDesc, URL context); }
SchemaDatasource extends Datasource { public SchemaDatasource(Map<String, Datasource> nameToDatasource, ConfigThingy sourceDesc, URL context) { name = parseConfig(sourceDesc, "NAME", () -> L.m("NAME der Datenquelle fehlt")); sourceName = parseConfig(sourceDesc, "SOURCE", () -> L.m("SOURCE der Datenquelle %1 fehlt", name)); source = nameToDatasource.get(sourceName); if (source == null) throw new ConfigurationErrorException( L.m( "Fehler bei Initialisierung von Datenquelle \"%1\": Referenzierte Datenquelle \"%2\" nicht (oder fehlerhaft) definiert", name, sourceName)); schema = new ArrayList<>(source.getSchema()); mapNewToOld = new HashMap<>(); List<String> columnsToDrop = dropColumns(sourceDesc.query("DROP")); List<String> columnsToAdd = addColumns(sourceDesc.query("ADD"), columnsToDrop); renameColumn(sourceDesc.query("RENAME"), columnsToDrop, columnsToAdd); for (String spalte : columnsToAdd) { if (!schema.contains(spalte) && !mapNewToOld.containsKey(spalte)) mapNewToOld.put(spalte, EMPTY_COLUMN); } schema.removeAll(columnsToDrop); schema.addAll(columnsToAdd); } SchemaDatasource(Map<String, Datasource> nameToDatasource,
      ConfigThingy sourceDesc, URL context); @Override List<String> getSchema(); @Override QueryResults getDatasetsByKey(Collection<String> keys); @Override QueryResults getContents(); @Override QueryResults find(List<QueryPart> query); @Override String getName(); }
SchemaDatasource extends Datasource { public SchemaDatasource(Map<String, Datasource> nameToDatasource, ConfigThingy sourceDesc, URL context) { name = parseConfig(sourceDesc, "NAME", () -> L.m("NAME der Datenquelle fehlt")); sourceName = parseConfig(sourceDesc, "SOURCE", () -> L.m("SOURCE der Datenquelle %1 fehlt", name)); source = nameToDatasource.get(sourceName); if (source == null) throw new ConfigurationErrorException( L.m( "Fehler bei Initialisierung von Datenquelle \"%1\": Referenzierte Datenquelle \"%2\" nicht (oder fehlerhaft) definiert", name, sourceName)); schema = new ArrayList<>(source.getSchema()); mapNewToOld = new HashMap<>(); List<String> columnsToDrop = dropColumns(sourceDesc.query("DROP")); List<String> columnsToAdd = addColumns(sourceDesc.query("ADD"), columnsToDrop); renameColumn(sourceDesc.query("RENAME"), columnsToDrop, columnsToAdd); for (String spalte : columnsToAdd) { if (!schema.contains(spalte) && !mapNewToOld.containsKey(spalte)) mapNewToOld.put(spalte, EMPTY_COLUMN); } schema.removeAll(columnsToDrop); schema.addAll(columnsToAdd); } SchemaDatasource(Map<String, Datasource> nameToDatasource,
      ConfigThingy sourceDesc, URL context); @Override List<String> getSchema(); @Override QueryResults getDatasetsByKey(Collection<String> keys); @Override QueryResults getContents(); @Override QueryResults find(List<QueryPart> query); @Override String getName();  }