You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/03/23 22:29:34 UTC

[GitHub] [pinot] Jackie-Jiang commented on a change in pull request #8394: Fix ingestion transform config bugs.

Jackie-Jiang commented on a change in pull request #8394:
URL: https://github.com/apache/pinot/pull/8394#discussion_r833767716



##########
File path: pinot-segment-local/src/main/java/org/apache/pinot/segment/local/recordtransformer/ExpressionTransformer.java
##########
@@ -40,12 +41,18 @@
  */
 public class ExpressionTransformer implements RecordTransformer {
 
-  private final LinkedHashMap<String, FunctionEvaluator> _expressionEvaluators = new LinkedHashMap<>();
+  @VisibleForTesting
+  final LinkedHashMap<String, FunctionEvaluator> _expressionEvaluators = new LinkedHashMap<>();
 
   public ExpressionTransformer(TableConfig tableConfig, Schema schema) {
     Map<String, FunctionEvaluator> expressionEvaluators = new HashMap<>();
     if (tableConfig.getIngestionConfig() != null && tableConfig.getIngestionConfig().getTransformConfigs() != null) {
       for (TransformConfig transformConfig : tableConfig.getIngestionConfig().getTransformConfigs()) {
+        String columnName = transformConfig.getColumnName();
+        if (expressionEvaluators.containsKey(columnName)) {
+          throw new RuntimeException("Cannot set more than one ingestion transform function on a column (column name: "
+              + "'" + columnName + "').");
+        }

Review comment:
       This part can be merged into the put to avoid one extra lookup
   ```suggestion
           FunctionEvaluator previous = expressionEvaluators.put(transformConfig.getColumnName(),
                 FunctionEvaluatorFactory.getExpressionEvaluator(transformConfig.getTransformFunction()));
           Preconditions.checkState(previous == null, "Cannot set more than one ingestion transform function on column: %s", transformConfig.getColumnName());
   ```

##########
File path: pinot-segment-local/src/main/java/org/apache/pinot/segment/local/recordtransformer/ExpressionTransformer.java
##########
@@ -60,29 +67,41 @@ public ExpressionTransformer(TableConfig tableConfig, Schema schema) {
       }
     }
 
-    // Sort the transform functions based on dependencies
-    Set<String> visited = new HashSet<>();
+    // Carry out DFS traversal to topologically sort column names based on transform function dependencies. Throw
+    // exception if a cycle is discovered. When a name is first seen it is added to discoveredNames set. When a name
+    // is completely processed (i.e the name and all of its children have been full explored and no cycles have been
+    // seen), it gets added to the _expressionEvaluators list in topologically sorted order. Fully explored names are
+    // removed from discoveredNames set.
+    Set<String> discoveredNames = new HashSet<>();
     for (Map.Entry<String, FunctionEvaluator> entry : expressionEvaluators.entrySet()) {
-      topologicalSort(entry.getKey(), expressionEvaluators, visited);
+      String columnName = entry.getKey();
+      if (!_expressionEvaluators.containsKey(columnName)) {
+        topologicalSort(columnName, expressionEvaluators, discoveredNames);
+      }
     }
   }
 
   private void topologicalSort(String column, Map<String, FunctionEvaluator> expressionEvaluators,
-      Set<String> visited) {
-    if (visited.contains(column)) {
-      return;
+      Set<String> discoveredNames) {
+    if (discoveredNames.contains(column)) {
+      throw new RuntimeException("Expression cycle found for column '" + column + "' in Ingestion Transform Function"

Review comment:
       Suggest throwing `IllegalStateException`




-- 
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: commits-unsubscribe@pinot.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org