aakash-db commented on code in PR #51003:
URL: https://github.com/apache/spark/pull/51003#discussion_r2110418857


##########
sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/graph/CoreDataflowNodeProcessor.scala:
##########
@@ -0,0 +1,232 @@
+/*
+ * 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.spark.sql.pipelines.graph
+
+import java.util.concurrent.{ConcurrentHashMap, ConcurrentLinkedQueue}
+
+import scala.jdk.CollectionConverters._
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.AnalysisException
+import org.apache.spark.sql.catalyst.TableIdentifier
+import org.apache.spark.sql.pipelines.graph.DataflowGraphTransformer.{
+  TransformNodeFailedException,
+  TransformNodeRetryableException
+}
+
+/**
+ * Core processor that is responsible for analyzing each flow and sort the 
nodes in
+ * topological order
+ */
+class CoreDataflowNodeProcessor(rawGraph: DataflowGraph) {
+
+  private val flowResolver = new FlowResolver(rawGraph)
+
+  // Map of input identifier to resolved [[Input]].
+  private val resolvedInputs = new ConcurrentHashMap[TableIdentifier, Input]()
+  // Map & queue of resolved flows identifiers
+  // queue is there to track the topological order while map is used to store 
the id -> flow
+  // mapping
+  private val resolvedFlowNodesMap = new ConcurrentHashMap[TableIdentifier, 
ResolvedFlow]()
+  private val resolvedFlowNodesQueue = new 
ConcurrentLinkedQueue[ResolvedFlow]()
+
+  private def processUnresolvedFlow(flow: UnresolvedFlow): ResolvedFlow = {
+    val resolvedFlow = flowResolver.attemptResolveFlow(
+      flow,
+      rawGraph.inputIdentifiers,
+      resolvedInputs.asScala.toMap
+    )
+    resolvedFlowNodesQueue.add(resolvedFlow)
+    resolvedFlowNodesMap.put(flow.identifier, resolvedFlow)
+    resolvedFlow
+  }
+
+  /**
+   * Processes the node of the graph, re-arranging them if they are not 
topologically sorted.
+   * Takes care of resolving the flows and virtualization if needed for the 
nodes.
+   * @param node The node to process
+   * @param upstreamNodes Upstream nodes for the node
+   * @return
+   */
+  def processNode(node: GraphElement, upstreamNodes: Seq[GraphElement]): 
Seq[GraphElement] = {
+    node match {
+      case flow: UnresolvedFlow => Seq(processUnresolvedFlow(flow))
+      case failedFlow: ResolutionFailedFlow => 
Seq(processUnresolvedFlow(failedFlow.flow))
+      case table: Table =>
+        // Ensure all upstreamNodes for a table are flows
+        val flowsToTable = upstreamNodes.map {
+          case flow: Flow => flow
+          case _ =>
+            throw new IllegalArgumentException(
+              s"Unsupported upstream node type for table ${table.displayName}: 
" +
+              s"${upstreamNodes.getClass}"
+            )
+        }
+        val resolvedFlowsToTable = flowsToTable.map { flow =>
+          resolvedFlowNodesMap.get(flow.identifier)
+        }
+
+        // Assign isStreamingTable (MV or ST) to the table based on the 
resolvedFlowsToTable
+        val tableWithType = table.copy(
+          isStreamingTableOpt = Option(resolvedFlowsToTable.exists(f => 
f.df.isStreaming))
+        )
+
+        // Table will be virtual in either of the following scenarios:
+        // 1. If table is present in context.fullRefreshTables
+        // 2. If table has any virtual inputs (flows or tables)
+        // 3. If the table pre-existing metadata is different from current 
metadata

Review Comment:
   Yeah, that's true. I removed this for now.



-- 
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: reviews-unsubscr...@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to