kunwp1 commented on code in PR #9448:
URL: https://github.com/apache/texera/pull/9448#discussion_r4580394072


##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/source/sql/SQLSourceOpExec.scala:
##########
@@ -49,7 +49,44 @@ abstract class SQLSourceOpExec(descString: String) extends 
SourceOperatorExecuto
     *
     * @return Iterator[TupleLike]
     */
-  override def produceTuple(): Iterator[TupleLike] = {
+  override def produceTuple(): Iterator[TupleLike] =
+    iterateRows[ResultSet](curResultSet, _.next())(
+      fetchNextJdbcResult,
+      clearJdbcResult,
+      f => cachedTuple.foreach(f),
+      f => curOffset.foreach(f),
+      f => curLimit.foreach(f)
+    )
+
+  private def fetchNextJdbcResult(): Boolean = {
+    curQuery = getNextQuery
+    curQuery match {
+      case Some(query) =>
+        curResultSet = Option(query.executeQuery)
+        true
+      case None =>
+        curResultSet = None
+        false
+    }
+  }
+
+  private def clearJdbcResult(): Unit = {
+    curResultSet.foreach(_.close())
+    curQuery.foreach(_.close())
+    curResultSet = None
+    curQuery = None
+  }
+
+  protected final def iterateRows[R](
+      currentRows: => Option[R],
+      advanceRow: R => Boolean
+  )(
+      fetchNextResult: () => Boolean,
+      clearResult: () => Unit,
+      forCachedTuple: (Tuple => Unit) => Unit,
+      forOffset: (Long => Unit) => Unit,
+      forLimit: (Long => Unit) => Unit

Review Comment:
   Both callers pass `f => cachedTuple.foreach(f)`, `f => curOffset.foreach(f)` 
and `f => curLimit.foreach(f)`, and those are fields of this class that the 
loop below already writes directly, so these three parameters only add 
indirection. Reading the fields here, as the old loop did, keeps the same 
non-local `return` and `break()` behavior and shortens both call sites.



##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/source/sql/SQLSourceOpExec.scala:
##########
@@ -383,8 +407,27 @@ abstract class SQLSourceOpExec(descString: String) extends 
SourceOperatorExecuto
   @throws[SQLException]
   protected def loadTableNames(): Unit
 
+  protected final def collectTableNames(preparedStatement: PreparedStatement): 
Unit = {
+    val resultSet = preparedStatement.executeQuery()
+    while (resultSet.next()) tableNames += resultSet.getString(1)
+    resultSet.close()
+    preparedStatement.close()
+  }
+
   protected def addFilterConditions(queryBuilder: StringBuilder): Unit
 
+  protected final def addJdbcKeywordCondition(queryBuilder: StringBuilder, 
column: String)(
+      enabled: => Boolean,
+      typeForColumn: => AttributeType
+  )(conditionFor: String => String): Unit = {
+    if (enabled) {
+      val columnType = typeForColumn
+      if (columnType != AttributeType.STRING)
+        throw new RuntimeException("Can't do keyword search on type " + 
columnType.toString)
+      queryBuilder ++= conditionFor(column)

Review Comment:
   The MySQL and PostgreSQL bodies explained that the column name is 
concatenated because a prepared statement can't bind it. That note went away in 
the move, and this line is where it now belongs.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to