tysonjh commented on a change in pull request #11566:
URL: https://github.com/apache/beam/pull/11566#discussion_r431463509



##########
File path: 
sdks/java/extensions/ml/src/main/java/org/apache/beam/sdk/extensions/ml/DLPDeidentifyText.java
##########
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.extensions.ml;
+
+import com.google.auto.value.AutoValue;
+import com.google.cloud.dlp.v2.DlpServiceClient;
+import com.google.privacy.dlp.v2.ContentItem;
+import com.google.privacy.dlp.v2.DeidentifyConfig;
+import com.google.privacy.dlp.v2.DeidentifyContentRequest;
+import com.google.privacy.dlp.v2.DeidentifyContentResponse;
+import com.google.privacy.dlp.v2.FieldId;
+import com.google.privacy.dlp.v2.InspectConfig;
+import com.google.privacy.dlp.v2.ProjectName;
+import com.google.privacy.dlp.v2.Table;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionView;
+
+/**
+ * A {@link PTransform} connecting to Cloud DLP 
(https://cloud.google.com/dlp/docs/libraries) and
+ * deidentifying text according to provided settings. The transform supports 
both CSV formatted
+ * input data and unstructured input.
+ *
+ * <p>If the csvHeader property is set and a sideinput with CSV headers is 
added to the PTransform,
+ * csvDelimiter also should be set, else the results will be incorrect. If 
csvHeader is neither set
+ * nor passed as sideinput, input is assumed to be unstructured.
+ *
+ * <p>Either deidentifyTemplateName (String) or deidentifyConfig {@link 
DeidentifyConfig} need to be
+ * set. inspectTemplateName and inspectConfig ({@link InspectConfig} are 
optional.
+ *
+ * <p>Batch size defines how big are batches sent to DLP at once in bytes.
+ *
+ * <p>The transform consumes {@link KV} of {@link String}s (assumed to be 
filename as key and
+ * contents as value) and outputs {@link KV} of {@link String} (eg. filename) 
and {@link
+ * DeidentifyContentResponse}, which will contain {@link Table} of results for 
the user to consume.
+ */
+@Experimental
+@AutoValue
+public abstract class DLPDeidentifyText
+    extends PTransform<
+        PCollection<KV<String, String>>, PCollection<KV<String, 
DeidentifyContentResponse>>> {
+
+  public static final Integer DLP_PAYLOAD_LIMIT_BYTES = 524000;
+
+  /** @return Template name for data inspection. */
+  @Nullable
+  public abstract String inspectTemplateName();
+
+  /** @return Template name for data deidentification. */
+  @Nullable
+  public abstract String deidentifyTemplateName();
+
+  /**
+   * @return Configuration object for data inspection. If present, supersedes 
the template settings.
+   */
+  @Nullable
+  public abstract InspectConfig inspectConfig();
+
+  /** @return Configuration object for deidentification. If present, 
supersedes the template. */
+  @Nullable
+  public abstract DeidentifyConfig deidentifyConfig();
+
+  /** @return List of column names if the input KV value is a CSV formatted 
row. */
+  @Nullable
+  public abstract PCollectionView<List<String>> csvHeader();
+
+  /** @return Delimiter to be used when splitting values from input strings 
into columns. */
+  @Nullable
+  public abstract String csvColumnDelimiter();

Review comment:
       Since the builder has setter methods prefixed with `set` having parity 
with getters prefixed with `get` would be nice. Also dropping the `csv` makes 
sense.
   
   ```suggestion
     public abstract String getColumnDelimiter();
   ```

##########
File path: 
sdks/java/extensions/ml/src/main/java/org/apache/beam/sdk/extensions/ml/DLPReidentifyText.java
##########
@@ -0,0 +1,271 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.extensions.ml;
+
+import com.google.auto.value.AutoValue;
+import com.google.cloud.dlp.v2.DlpServiceClient;
+import com.google.privacy.dlp.v2.ContentItem;
+import com.google.privacy.dlp.v2.DeidentifyConfig;
+import com.google.privacy.dlp.v2.FieldId;
+import com.google.privacy.dlp.v2.InspectConfig;
+import com.google.privacy.dlp.v2.ProjectName;
+import com.google.privacy.dlp.v2.ReidentifyContentRequest;
+import com.google.privacy.dlp.v2.ReidentifyContentResponse;
+import com.google.privacy.dlp.v2.Table;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionView;
+
+/**
+ * A {@link PTransform} connecting to Cloud DLP 
(https://cloud.google.com/dlp/docs/libraries) and
+ * inspecting text for identifying data according to provided settings.
+ *
+ * <p>The transform supports both CSV formatted input data and unstructured 
input.
+ *
+ * <p>If the csvHeader property is set and a sideinput with CSV headers is 
added to the PTransform,
+ * csvDelimiter also should be set, else the results will be incorrect. If 
csvHeader is neither set
+ * nor passed as sideinput, input is assumed to be unstructured.
+ *
+ * <p>Batch size defines how big are batches sent to DLP at once in bytes.
+ *
+ * <p>The transform consumes {@link KV} of {@link String}s (assumed to be 
filename as key and
+ * contents as value) and outputs {@link KV} of {@link String} (eg. filename) 
and {@link
+ * ReidentifyContentResponse}, which will contain {@link Table} of results for 
the user to consume.
+ *
+ * <p>Batch size defines how big are batches sent to DLP at once in bytes.
+ *
+ * <p>Either reidentifyTemplateName {@link String} or reidentifyConfig {@link 
DeidentifyConfig} need
+ * to be set. inspectConfig {@link InspectConfig} and inspectTemplateName 
{@link String} are
+ * optional.
+ *
+ * <p>Batch size defines how big are batches sent to DLP at once in bytes.
+ */
+@Experimental
+@AutoValue
+public abstract class DLPReidentifyText

Review comment:
       Similarly with this class, please apply comments from previous 
transforms here. For example, dropping the csv, naming getters with a prefix 
get, ensuring that all preconditions are validated in the build() method.

##########
File path: 
sdks/java/extensions/ml/src/main/java/org/apache/beam/sdk/extensions/ml/DLPDeidentifyText.java
##########
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.extensions.ml;
+
+import com.google.auto.value.AutoValue;
+import com.google.cloud.dlp.v2.DlpServiceClient;
+import com.google.privacy.dlp.v2.ContentItem;
+import com.google.privacy.dlp.v2.DeidentifyConfig;
+import com.google.privacy.dlp.v2.DeidentifyContentRequest;
+import com.google.privacy.dlp.v2.DeidentifyContentResponse;
+import com.google.privacy.dlp.v2.FieldId;
+import com.google.privacy.dlp.v2.InspectConfig;
+import com.google.privacy.dlp.v2.ProjectName;
+import com.google.privacy.dlp.v2.Table;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionView;
+
+/**
+ * A {@link PTransform} connecting to Cloud DLP 
(https://cloud.google.com/dlp/docs/libraries) and
+ * deidentifying text according to provided settings. The transform supports 
both CSV formatted

Review comment:
       ```suggestion
    * deidentifying text according to provided settings. The transform supports 
both delimited
   ```

##########
File path: 
sdks/java/extensions/ml/src/main/java/org/apache/beam/sdk/extensions/ml/DLPDeidentifyText.java
##########
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.extensions.ml;
+
+import com.google.auto.value.AutoValue;
+import com.google.cloud.dlp.v2.DlpServiceClient;
+import com.google.privacy.dlp.v2.ContentItem;
+import com.google.privacy.dlp.v2.DeidentifyConfig;
+import com.google.privacy.dlp.v2.DeidentifyContentRequest;
+import com.google.privacy.dlp.v2.DeidentifyContentResponse;
+import com.google.privacy.dlp.v2.FieldId;
+import com.google.privacy.dlp.v2.InspectConfig;
+import com.google.privacy.dlp.v2.ProjectName;
+import com.google.privacy.dlp.v2.Table;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionView;
+
+/**
+ * A {@link PTransform} connecting to Cloud DLP 
(https://cloud.google.com/dlp/docs/libraries) and
+ * deidentifying text according to provided settings. The transform supports 
both CSV formatted
+ * input data and unstructured input.
+ *
+ * <p>If the csvHeader property is set and a sideinput with CSV headers is 
added to the PTransform,
+ * csvDelimiter also should be set, else the results will be incorrect. If 
csvHeader is neither set
+ * nor passed as sideinput, input is assumed to be unstructured.
+ *
+ * <p>Either deidentifyTemplateName (String) or deidentifyConfig {@link 
DeidentifyConfig} need to be
+ * set. inspectTemplateName and inspectConfig ({@link InspectConfig} are 
optional.
+ *
+ * <p>Batch size defines how big are batches sent to DLP at once in bytes.
+ *
+ * <p>The transform consumes {@link KV} of {@link String}s (assumed to be 
filename as key and
+ * contents as value) and outputs {@link KV} of {@link String} (eg. filename) 
and {@link
+ * DeidentifyContentResponse}, which will contain {@link Table} of results for 
the user to consume.
+ */
+@Experimental
+@AutoValue
+public abstract class DLPDeidentifyText
+    extends PTransform<
+        PCollection<KV<String, String>>, PCollection<KV<String, 
DeidentifyContentResponse>>> {
+
+  public static final Integer DLP_PAYLOAD_LIMIT_BYTES = 524000;
+
+  /** @return Template name for data inspection. */
+  @Nullable
+  public abstract String inspectTemplateName();
+
+  /** @return Template name for data deidentification. */
+  @Nullable
+  public abstract String deidentifyTemplateName();
+
+  /**
+   * @return Configuration object for data inspection. If present, supersedes 
the template settings.
+   */
+  @Nullable
+  public abstract InspectConfig inspectConfig();
+
+  /** @return Configuration object for deidentification. If present, 
supersedes the template. */
+  @Nullable
+  public abstract DeidentifyConfig deidentifyConfig();
+
+  /** @return List of column names if the input KV value is a CSV formatted 
row. */
+  @Nullable
+  public abstract PCollectionView<List<String>> csvHeader();

Review comment:
       I think we previously agreed that the term 'csv' here is misleading 
since it could be any delimiter not just a comma. Perhaps the right name for 
this is `getHeaderColumns()`? That would match nicely with 
`getColumnDelimiter`, `setColumnDelimiter`, and `setHeaderColumns()`. 
   
   That would follow the style guide from 
[here](https://beam.apache.org/contribute/ptransform-style-guide/#api) more 
closely, though it would require updating other getters to match but the 
setters in the builder already conform.

##########
File path: 
sdks/java/extensions/ml/src/main/java/org/apache/beam/sdk/extensions/ml/DLPDeidentifyText.java
##########
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.extensions.ml;
+
+import com.google.auto.value.AutoValue;
+import com.google.cloud.dlp.v2.DlpServiceClient;
+import com.google.privacy.dlp.v2.ContentItem;
+import com.google.privacy.dlp.v2.DeidentifyConfig;
+import com.google.privacy.dlp.v2.DeidentifyContentRequest;
+import com.google.privacy.dlp.v2.DeidentifyContentResponse;
+import com.google.privacy.dlp.v2.FieldId;
+import com.google.privacy.dlp.v2.InspectConfig;
+import com.google.privacy.dlp.v2.ProjectName;
+import com.google.privacy.dlp.v2.Table;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionView;
+
+/**
+ * A {@link PTransform} connecting to Cloud DLP 
(https://cloud.google.com/dlp/docs/libraries) and
+ * deidentifying text according to provided settings. The transform supports 
both CSV formatted
+ * input data and unstructured input.
+ *
+ * <p>If the csvHeader property is set and a sideinput with CSV headers is 
added to the PTransform,
+ * csvDelimiter also should be set, else the results will be incorrect. If 
csvHeader is neither set
+ * nor passed as sideinput, input is assumed to be unstructured.

Review comment:
       This condition is not checked in the `build()` method. Can it be?

##########
File path: 
sdks/java/extensions/ml/src/main/java/org/apache/beam/sdk/extensions/ml/DLPDeidentifyText.java
##########
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.extensions.ml;
+
+import com.google.auto.value.AutoValue;
+import com.google.cloud.dlp.v2.DlpServiceClient;
+import com.google.privacy.dlp.v2.ContentItem;
+import com.google.privacy.dlp.v2.DeidentifyConfig;
+import com.google.privacy.dlp.v2.DeidentifyContentRequest;
+import com.google.privacy.dlp.v2.DeidentifyContentResponse;
+import com.google.privacy.dlp.v2.FieldId;
+import com.google.privacy.dlp.v2.InspectConfig;
+import com.google.privacy.dlp.v2.ProjectName;
+import com.google.privacy.dlp.v2.Table;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionView;
+
+/**
+ * A {@link PTransform} connecting to Cloud DLP 
(https://cloud.google.com/dlp/docs/libraries) and
+ * deidentifying text according to provided settings. The transform supports 
both CSV formatted
+ * input data and unstructured input.
+ *
+ * <p>If the csvHeader property is set and a sideinput with CSV headers is 
added to the PTransform,
+ * csvDelimiter also should be set, else the results will be incorrect. If 
csvHeader is neither set
+ * nor passed as sideinput, input is assumed to be unstructured.
+ *
+ * <p>Either deidentifyTemplateName (String) or deidentifyConfig {@link 
DeidentifyConfig} need to be
+ * set. inspectTemplateName and inspectConfig ({@link InspectConfig} are 
optional.
+ *
+ * <p>Batch size defines how big are batches sent to DLP at once in bytes.
+ *
+ * <p>The transform consumes {@link KV} of {@link String}s (assumed to be 
filename as key and
+ * contents as value) and outputs {@link KV} of {@link String} (eg. filename) 
and {@link
+ * DeidentifyContentResponse}, which will contain {@link Table} of results for 
the user to consume.
+ */
+@Experimental
+@AutoValue
+public abstract class DLPDeidentifyText
+    extends PTransform<
+        PCollection<KV<String, String>>, PCollection<KV<String, 
DeidentifyContentResponse>>> {
+
+  public static final Integer DLP_PAYLOAD_LIMIT_BYTES = 524000;
+
+  /** @return Template name for data inspection. */
+  @Nullable
+  public abstract String inspectTemplateName();
+
+  /** @return Template name for data deidentification. */
+  @Nullable
+  public abstract String deidentifyTemplateName();
+
+  /**
+   * @return Configuration object for data inspection. If present, supersedes 
the template settings.
+   */
+  @Nullable
+  public abstract InspectConfig inspectConfig();
+
+  /** @return Configuration object for deidentification. If present, 
supersedes the template. */
+  @Nullable
+  public abstract DeidentifyConfig deidentifyConfig();
+
+  /** @return List of column names if the input KV value is a CSV formatted 
row. */
+  @Nullable
+  public abstract PCollectionView<List<String>> csvHeader();
+
+  /** @return Delimiter to be used when splitting values from input strings 
into columns. */
+  @Nullable
+  public abstract String csvColumnDelimiter();
+
+  /** @return Size of input elements batch to be sent to Cloud DLP service in 
one request. */
+  public abstract Integer batchSizeBytes();
+
+  /** @return ID of Google Cloud project to be used when deidentifying data. */
+  public abstract String projectId();
+
+  @AutoValue.Builder
+  public abstract static class Builder {
+    /** @param inspectTemplateName Template name for data inspection. */
+    public abstract Builder setInspectTemplateName(String inspectTemplateName);
+
+    /** @param csvHeader List of column names if the input KV value is a CSV 
formatted row. */
+    public abstract Builder setCsvHeader(PCollectionView<List<String>> 
csvHeader);

Review comment:
       Since this is just a collection of column names for the header, I don't 
think the prefix `csv` is relevant here. Below is my suggestion that drops the 
`csv`, adds the word 'column', and adds a comment that describes the 
relationship between this method and the `setColumnDelimiter`.
   
   Note: I talk about the default header "value" here. It would make sense to 
mention this in `getHeaderColumns()` if my assumption is correct.
   
   ```suggestion
       /** 
       *  Sets the header column names corresponding to the delimited values of 
the input KV. If no header is set, 
       *  a single column name "value" will be used for the header. If 
specified, requires that a delimiter is 
       *  set using setColumnDelimiter.
       */
       public abstract Builder setHeaderColumns(PCollectionView<List<String>> 
header);
   ```
   
   

##########
File path: 
sdks/java/extensions/ml/src/main/java/org/apache/beam/sdk/extensions/ml/DLPInspectText.java
##########
@@ -0,0 +1,215 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.extensions.ml;
+
+import com.google.auto.value.AutoValue;
+import com.google.cloud.dlp.v2.DlpServiceClient;
+import com.google.privacy.dlp.v2.ContentItem;
+import com.google.privacy.dlp.v2.FieldId;
+import com.google.privacy.dlp.v2.InspectConfig;
+import com.google.privacy.dlp.v2.InspectContentRequest;
+import com.google.privacy.dlp.v2.InspectContentResponse;
+import com.google.privacy.dlp.v2.ProjectName;
+import com.google.privacy.dlp.v2.Table;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionView;
+
+/**
+ * A {@link PTransform} connecting to Cloud DLP 
(https://cloud.google.com/dlp/docs/libraries) and
+ * inspecting text for identifying data according to provided settings. The 
transform supports both
+ * CSV formatted input data and unstructured input.
+ *
+ * <p>If the csvHeader property is set and a sideinput with CSV headers is 
added to the PTransform,
+ * csvDelimiter also should be set, else the results will be incorrect. If 
csvHeader is neither set
+ * nor passed as sideinput, input is assumed to be unstructured.
+ *
+ * <p>Batch size defines how big are batches sent to DLP at once in bytes.
+ *
+ * <p>The transform consumes {@link KV} of {@link String}s (assumed to be 
filename as key and
+ * contents as value) and outputs {@link KV} of {@link String} (eg. filename) 
and {@link
+ * InspectContentResponse}, which will contain {@link Table} of results for 
the user to consume.
+ *
+ * <p>Either inspectTemplateName (String) or inspectConfig {@link 
InspectConfig} need to be set.
+ *
+ * <p>Batch size defines how big are batches sent to DLP at once in bytes.
+ */
+@Experimental
+@AutoValue
+public abstract class DLPInspectText

Review comment:
       It seems like the formatting is strange in this class. There aren't 
empty newlines between methods, did it pass the spotless check?
   
   Also can you apply the comments from previous transforms to this class? For 
example, dropping the `csv`, naming getters with a prefix `get`, ensuring that 
all preconditions are validated in the `build()` method.

##########
File path: 
sdks/java/extensions/ml/src/main/java/org/apache/beam/sdk/extensions/ml/DLPDeidentifyText.java
##########
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.extensions.ml;
+
+import com.google.auto.value.AutoValue;
+import com.google.cloud.dlp.v2.DlpServiceClient;
+import com.google.privacy.dlp.v2.ContentItem;
+import com.google.privacy.dlp.v2.DeidentifyConfig;
+import com.google.privacy.dlp.v2.DeidentifyContentRequest;
+import com.google.privacy.dlp.v2.DeidentifyContentResponse;
+import com.google.privacy.dlp.v2.FieldId;
+import com.google.privacy.dlp.v2.InspectConfig;
+import com.google.privacy.dlp.v2.ProjectName;
+import com.google.privacy.dlp.v2.Table;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionView;
+
+/**
+ * A {@link PTransform} connecting to Cloud DLP 
(https://cloud.google.com/dlp/docs/libraries) and
+ * deidentifying text according to provided settings. The transform supports 
both CSV formatted
+ * input data and unstructured input.
+ *
+ * <p>If the csvHeader property is set and a sideinput with CSV headers is 
added to the PTransform,
+ * csvDelimiter also should be set, else the results will be incorrect. If 
csvHeader is neither set
+ * nor passed as sideinput, input is assumed to be unstructured.
+ *
+ * <p>Either deidentifyTemplateName (String) or deidentifyConfig {@link 
DeidentifyConfig} need to be
+ * set. inspectTemplateName and inspectConfig ({@link InspectConfig} are 
optional.
+ *
+ * <p>Batch size defines how big are batches sent to DLP at once in bytes.
+ *
+ * <p>The transform consumes {@link KV} of {@link String}s (assumed to be 
filename as key and
+ * contents as value) and outputs {@link KV} of {@link String} (eg. filename) 
and {@link
+ * DeidentifyContentResponse}, which will contain {@link Table} of results for 
the user to consume.
+ */
+@Experimental
+@AutoValue
+public abstract class DLPDeidentifyText
+    extends PTransform<
+        PCollection<KV<String, String>>, PCollection<KV<String, 
DeidentifyContentResponse>>> {
+
+  public static final Integer DLP_PAYLOAD_LIMIT_BYTES = 524000;
+
+  /** @return Template name for data inspection. */
+  @Nullable
+  public abstract String inspectTemplateName();
+
+  /** @return Template name for data deidentification. */
+  @Nullable
+  public abstract String deidentifyTemplateName();
+
+  /**
+   * @return Configuration object for data inspection. If present, supersedes 
the template settings.
+   */
+  @Nullable
+  public abstract InspectConfig inspectConfig();
+
+  /** @return Configuration object for deidentification. If present, 
supersedes the template. */
+  @Nullable
+  public abstract DeidentifyConfig deidentifyConfig();
+
+  /** @return List of column names if the input KV value is a CSV formatted 
row. */

Review comment:
       I'm getting a bit confused at when a header is present and when one 
isn't now. When building the table for the request to the cloud API, if no 
header is present, we set one to "value" by default. If that column header ends 
up in the response, should this method also return "value" when set to null?
   
   If that is the case, this needs to be clear in the comments somewhere.

##########
File path: 
sdks/java/extensions/ml/src/main/java/org/apache/beam/sdk/extensions/ml/DLPDeidentifyText.java
##########
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.extensions.ml;
+
+import com.google.auto.value.AutoValue;
+import com.google.cloud.dlp.v2.DlpServiceClient;
+import com.google.privacy.dlp.v2.ContentItem;
+import com.google.privacy.dlp.v2.DeidentifyConfig;
+import com.google.privacy.dlp.v2.DeidentifyContentRequest;
+import com.google.privacy.dlp.v2.DeidentifyContentResponse;
+import com.google.privacy.dlp.v2.FieldId;
+import com.google.privacy.dlp.v2.InspectConfig;
+import com.google.privacy.dlp.v2.ProjectName;
+import com.google.privacy.dlp.v2.Table;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionView;
+
+/**
+ * A {@link PTransform} connecting to Cloud DLP 
(https://cloud.google.com/dlp/docs/libraries) and
+ * deidentifying text according to provided settings. The transform supports 
both CSV formatted
+ * input data and unstructured input.
+ *
+ * <p>If the csvHeader property is set and a sideinput with CSV headers is 
added to the PTransform,
+ * csvDelimiter also should be set, else the results will be incorrect. If 
csvHeader is neither set
+ * nor passed as sideinput, input is assumed to be unstructured.
+ *
+ * <p>Either deidentifyTemplateName (String) or deidentifyConfig {@link 
DeidentifyConfig} need to be
+ * set. inspectTemplateName and inspectConfig ({@link InspectConfig} are 
optional.
+ *
+ * <p>Batch size defines how big are batches sent to DLP at once in bytes.
+ *
+ * <p>The transform consumes {@link KV} of {@link String}s (assumed to be 
filename as key and
+ * contents as value) and outputs {@link KV} of {@link String} (eg. filename) 
and {@link
+ * DeidentifyContentResponse}, which will contain {@link Table} of results for 
the user to consume.
+ */
+@Experimental
+@AutoValue
+public abstract class DLPDeidentifyText
+    extends PTransform<
+        PCollection<KV<String, String>>, PCollection<KV<String, 
DeidentifyContentResponse>>> {
+
+  public static final Integer DLP_PAYLOAD_LIMIT_BYTES = 524000;
+
+  /** @return Template name for data inspection. */
+  @Nullable
+  public abstract String inspectTemplateName();
+
+  /** @return Template name for data deidentification. */
+  @Nullable
+  public abstract String deidentifyTemplateName();
+
+  /**
+   * @return Configuration object for data inspection. If present, supersedes 
the template settings.
+   */
+  @Nullable
+  public abstract InspectConfig inspectConfig();
+
+  /** @return Configuration object for deidentification. If present, 
supersedes the template. */
+  @Nullable
+  public abstract DeidentifyConfig deidentifyConfig();
+
+  /** @return List of column names if the input KV value is a CSV formatted 
row. */
+  @Nullable
+  public abstract PCollectionView<List<String>> csvHeader();
+
+  /** @return Delimiter to be used when splitting values from input strings 
into columns. */
+  @Nullable
+  public abstract String csvColumnDelimiter();
+
+  /** @return Size of input elements batch to be sent to Cloud DLP service in 
one request. */
+  public abstract Integer batchSizeBytes();
+
+  /** @return ID of Google Cloud project to be used when deidentifying data. */
+  public abstract String projectId();
+
+  @AutoValue.Builder
+  public abstract static class Builder {
+    /** @param inspectTemplateName Template name for data inspection. */
+    public abstract Builder setInspectTemplateName(String inspectTemplateName);
+
+    /** @param csvHeader List of column names if the input KV value is a CSV 
formatted row. */
+    public abstract Builder setCsvHeader(PCollectionView<List<String>> 
csvHeader);
+
+    /**
+     * @param delimiter Delimiter to be used when splitting values from input 
strings into columns.
+     */
+    public abstract Builder setCsvColumnDelimiter(String delimiter);

Review comment:
       Similarly here, no need to say `csv` in the method name or comments 
since it may be any delimiter. Also mention how this method relates to the 
`setHeader` method above.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to