/** * Given a data schema, remove data tables that are not compatible with this data schema. * <p>Upgrade the data schema passed in to cover all remaining data schemas. * * @param dataSchema data schema. * @param dataTableMap map from server to data table. * @return list of server names where the data table got removed. */ @Nonnull private List<String> removeConflictingResponses(@Nonnull DataSchema dataSchema, @Nonnull Map<ServerInstance, DataTable> dataTableMap) { List<String> droppedServers = new ArrayList<>(); Iterator<Map.Entry<ServerInstance, DataTable>> iterator = dataTableMap.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<ServerInstance, DataTable> entry = iterator.next(); DataSchema dataSchemaToCompare = entry.getValue().getDataSchema(); assert dataSchemaToCompare != null; if (!dataSchema.isTypeCompatibleWith(dataSchemaToCompare)) { droppedServers.add(entry.getKey().toString()); iterator.remove(); } else { dataSchema.upgradeToCover(dataSchemaToCompare); } } return droppedServers; }
@Test public void testTypeCompatible() { DataSchema dataSchema = new DataSchema(COLUMN_NAMES, COLUMN_DATA_TYPES); DataSchema compatibleDataSchema = new DataSchema(COLUMN_NAMES, COMPATIBLE_COLUMN_DATA_TYPES); Assert.assertTrue(dataSchema.isTypeCompatibleWith(compatibleDataSchema)); String[] anotherColumnNames = new String[NUM_COLUMNS]; Arrays.fill(anotherColumnNames, "foo"); DataSchema incompatibleDataSchema = new DataSchema(anotherColumnNames, COLUMN_DATA_TYPES); Assert.assertFalse(dataSchema.isTypeCompatibleWith(incompatibleDataSchema)); dataSchema.upgradeToCover(compatibleDataSchema); DataSchema upgradedDataSchema = new DataSchema(COLUMN_NAMES, UPGRADED_COLUMN_DATA_TYPES); Assert.assertEquals(dataSchema, upgradedDataSchema); }
@Test public void testCompatibleRowsDataTableTransformation() throws Exception { Collection<Serializable[]> rows = new ArrayList<>(2); rows.add(_row1.clone()); rows.add(_compatibleRow1.clone()); DataSchema dataSchema = _dataSchema.clone(); Assert.assertTrue(dataSchema.isTypeCompatibleWith(_compatibleDataSchema)); dataSchema.upgradeToCover(_compatibleDataSchema); Assert.assertEquals(dataSchema, _upgradedDataSchema); DataTable dataTable = SelectionOperatorUtils.getDataTableFromRows(rows, dataSchema); Serializable[] expectedRow1 = {0L, 1.0, 2.0, 3.0, "4", new long[]{5L}, new double[]{6.0}, new double[]{7.0}, new double[]{8.0}, new String[]{"9"}}; Serializable[] expectedCompatibleRow1 = {1L, 2.0, 3.0, 4.0, "5", new long[]{6L}, new double[]{7.0}, new double[]{8.0}, new double[]{9.0}, new String[]{"10"}}; Assert.assertEquals(SelectionOperatorUtils.extractRowFromDataTable(dataTable, 0), expectedRow1); Assert.assertEquals(SelectionOperatorUtils.extractRowFromDataTable(dataTable, 1), expectedCompatibleRow1); }
mergedBlockSchema.upgradeToCover(blockToMergeSchema);