/** * Return a copy of the provided row with the mutation type field * appended and set to mutation type NONE. If the mutation type field * is already present the provided row is returned back unchanged. */ public static Row appendMutationTypeField(Row row) { if (!hasMutationTypeField(row)) { row = RowUtils.append(row, MutationType.MUTATION_TYPE_FIELD_NAME, DataTypes.StringType, MutationType.NONE.toString()); } return row; }
/** * Return a copy of the provided row with the mutation type set. * If the mutation type field is not present it will be added. * This does not modify the provided row. */ public static Row setMutationType(Row row, MutationType mutationType) { if (!hasMutationTypeField(row)) { row = appendMutationTypeField(row); } return RowUtils.set(row, MutationType.MUTATION_TYPE_FIELD_NAME, mutationType.toString()); }
@Test public void testGetMutationType() { Row row = new RowWithSchema(schemaWithMT, "hello", MutationType.DELETE.toString()); assertEquals(MutationType.DELETE, PlannerUtils.getMutationType(row)); }
@Test public void testSetMutationType() { Row rowWith = new RowWithSchema(schemaWithMT, "hello", null); rowWith = PlannerUtils.setMutationType(rowWith, MutationType.DELETE); assertEquals(rowWith.<String>getAs(MutationType.MUTATION_TYPE_FIELD_NAME), MutationType.DELETE.toString()); Row rowWithout = new RowWithSchema(schemaWithoutMT, "hello"); rowWithout = PlannerUtils.setMutationType(rowWithout, MutationType.DELETE); assertEquals(rowWithout.<String>getAs(MutationType.MUTATION_TYPE_FIELD_NAME), MutationType.DELETE.toString()); }
@Test public void testRemoveMutationTypeField() { Row rowWith = new RowWithSchema(schemaWithMT, "hello", MutationType.DELETE.toString()); Row rowWithout = PlannerUtils.removeMutationTypeField(rowWith); assertEquals(rowWithout.schema(), schemaWithoutMT); }
@Test public void testHasMutationTypeField() { Row rowWith = new RowWithSchema(schemaWithMT, "hello", MutationType.DELETE.toString()); Row rowWithout = PlannerUtils.removeMutationTypeField(rowWith); assertTrue(PlannerUtils.hasMutationTypeField(rowWith)); assertFalse(PlannerUtils.hasMutationTypeField(rowWithout)); }
break; default: throw new RuntimeException("Unsupported Kudu mutation type: " + mutationType.toString());