/** * 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; }
@Override public void applyBulkMutations(List<Tuple2<MutationType, Dataset<Row>>> planned) { for (Tuple2<MutationType, Dataset<Row>> mutation : planned) { MutationType mutationType = mutation._1(); Dataset<Row> mutationDF = mutation._2(); if (mutationType.equals(MutationType.INSERT)) { mutationDF.javaRDD().foreachPartition(new SendRowToKafkaFunction(config)); } } }
/** * Get the mutation type of the provided row. Throws an exception * if the row does not contain a mutation type field. */ public static MutationType getMutationType(Row row) { assertHasMutationTypeField(row); return MutationType.valueOf(row.<String>getAs(MutationType.MUTATION_TYPE_FIELD_NAME)); }
/** * 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()); }
@Override public void applyBulkMutations(List<Tuple2<MutationType, Dataset<Row>>> planned) { for (Tuple2<MutationType, Dataset<Row>> mutation : planned) { MutationType mutationType = mutation._1(); Dataset<Row> mutationDF = mutation._2(); if (mutationType.equals(MutationType.INSERT)) { mutationDF.javaRDD().foreach(new SendRowToLogFunction(delimiter, logLevel)); } } }
@Test public void testGetMutationType() { Row row = new RowWithSchema(schemaWithMT, "hello", MutationType.DELETE.toString()); assertEquals(MutationType.DELETE, PlannerUtils.getMutationType(row)); }
plan = RowUtils.set(plan, getCurrentFlagFieldName(), getCurrentFlagNoValue()); if (!PlannerUtils.getMutationType(plan).equals(MutationType.INSERT)) { plan = PlannerUtils.setMutationType(plan, MutationType.UPDATE); plan = RowUtils.set(plan, getCurrentFlagFieldName(), getCurrentFlagNoValue()); if (!PlannerUtils.getMutationType(plan).equals(MutationType.INSERT)) { plan = PlannerUtils.setMutationType(plan, MutationType.UPDATE); if (!PlannerUtils.getMutationType(plan).equals(MutationType.INSERT)) { plan = PlannerUtils.setMutationType(plan, MutationType.UPDATE); plan = RowUtils.set(plan, getCurrentFlagFieldName(), getCurrentFlagNoValue()); if (PlannerUtils.getMutationType(plan).equals(MutationType.INSERT)) { plannedForKey.set(position, carried); plan = carried; } else if (!PlannerUtils.getMutationType(plan).equals(MutationType.NONE)) { planned.add(plan); } else if (!PlannerUtils.getMutationType(plan).equals(MutationType.NONE)) { planned.add(plan); if (!PlannerUtils.getMutationType(plan).equals(MutationType.NONE)) { planned.add(plan);
@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()); }
plan = lastUpdatedTimeModel.setCurrentSystemTime(plan); if (!PlannerUtils.getMutationType(plan).equals(MutationType.INSERT)) { plan = PlannerUtils.setMutationType(plan, MutationType.UPDATE); plan = lastUpdatedTimeModel.setCurrentSystemTime(plan); if (!PlannerUtils.getMutationType(plan).equals(MutationType.INSERT)) { plan = PlannerUtils.setMutationType(plan, MutationType.UPDATE); plannedForKey.set(position, plan); if (!PlannerUtils.getMutationType(plan).equals(MutationType.NONE)) { planned.add(plan);
@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());