PiiLogicalTypeVisitor extends PiiVisitor<Void> { @Override protected void onPiiField(Field field, Collection<String> breadcrumb) { Schema schema = field.schema(); if (schema.getType() == UNION) { for (Schema type : schema.getTypes()) { addLogicalType(type); } } else { addLogicalType(schema); } }    }
@Test public void typicalString() throws Exception { Schema schema = SchemaBuilder.builder().stringType(); Field field = new Field("b", schema, null, (Object) null); field.addProp(SENSITIVITY, PII); underTest.onPiiField(field, null); assertThat(schema.getProp("logicalType"), is("pii-string")); }
@Test public void typicalBytes() throws Exception { Schema schema = SchemaBuilder.builder().bytesType(); Field field = new Field("b", schema, null, (Object) null); field.addProp(SENSITIVITY, PII); underTest.onPiiField(field, null); assertThat(schema.getProp("logicalType"), is("pii-bytes")); }
@Test public void typicalNullableString() throws Exception { Schema schema = SchemaBuilder.builder().stringType(); Schema union = SchemaBuilder.unionOf().type(schema).and().nullType().endUnion(); Field field = new Field("b", union, null, (Object) null); field.addProp(SENSITIVITY, PII); underTest.onPiiField(field, null); assertThat(schema.getProp("logicalType"), is("pii-string")); }
@Test public void typicalNullableBytes() throws Exception { Schema schema = SchemaBuilder.builder().bytesType(); Schema union = SchemaBuilder.unionOf().type(schema).and().nullType().endUnion(); Field field = new Field("b", union, null, (Object) null); field.addProp(SENSITIVITY, PII); underTest.onPiiField(field, null); assertThat(schema.getProp("logicalType"), is("pii-bytes")); }