You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@gobblin.apache.org by "homatthew (via GitHub)" <gi...@apache.org> on 2023/03/08 23:53:04 UTC

[GitHub] [gobblin] homatthew commented on a diff in pull request #3648: [GOBBLIN-1779] Ability to filter datasets that contain non optional unions

homatthew commented on code in PR #3648:
URL: https://github.com/apache/gobblin/pull/3648#discussion_r1130213358


##########
gobblin-data-management/src/main/java/org/apache/gobblin/data/management/dataset/DatasetsFinderFilteringDecorator.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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.gobblin.data.management.dataset;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.stream.Collectors;
+import org.apache.gobblin.dataset.Dataset;
+import org.apache.gobblin.dataset.DatasetsFinder;
+import org.apache.gobblin.util.PropertiesUtils;
+import org.apache.gobblin.util.function.CheckedExceptionPredicate;
+import org.apache.gobblin.util.reflection.GobblinConstructorUtils;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+
+
+/**
+ * A decorator for filtering datasets after a {@link DatasetsFinder} finds a {@link List} of {@link Dataset}s
+ */
+public class DatasetsFinderFilteringDecorator<T extends Dataset> implements DatasetsFinder<T> {
+  private static final String PREFIX = "filtering.datasets.finder.";
+  public static final String DATASET_CLASS = PREFIX + "class";
+  public static final String ALLOWED = PREFIX + "allowed.predicates";
+  public static final String DENIED = PREFIX + "denied.predicates";
+
+  protected DatasetsFinder<T> datasetFinder;
+  protected List<CheckedExceptionPredicate<T,IOException>> allowDatasetPredicates;
+  protected List<CheckedExceptionPredicate<T,IOException>> denyDatasetPredicates;
+
+  public DatasetsFinderFilteringDecorator(FileSystem fs, Properties properties) throws IOException {
+    this.datasetFinder = DatasetUtils.instantiateDatasetFinder(
+        DATASET_CLASS, properties, fs, DefaultFileSystemGlobFinder.class.getName());
+    this.allowDatasetPredicates = instantiatePredicates(ALLOWED, properties);
+    this.denyDatasetPredicates = instantiatePredicates(DENIED, properties);
+  }
+
+  @VisibleForTesting
+  DatasetsFinderFilteringDecorator(
+      DatasetsFinder<T> datasetsFinder,
+      List<CheckedExceptionPredicate<T,IOException>> allowDatasetPredicates,
+      List<CheckedExceptionPredicate<T,IOException>> denyDatasetPredicates) {
+    this.datasetFinder = datasetsFinder;
+    this.allowDatasetPredicates = allowDatasetPredicates;
+    this.denyDatasetPredicates = denyDatasetPredicates;
+  }
+
+  @Override
+  public List<T> findDatasets() throws IOException {
+    List<T> datasets = datasetFinder.findDatasets();
+    List<T> allowedDatasets = null;

Review Comment:
   In hindsight, does this value really matter? We can just return allowedDatasets as-is. 
   
   But to answer your question. We can never return null from this method. We always throw an exception or allowedDatasets is overwritten by datasets (which cannot be null)



-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@gobblin.apache.org

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