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


##########
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:
   Agreed — `iterateRows` now reads `cachedTuple`, `curOffset` and `curLimit` 
itself, and both sources pass only their fetch and clear steps, in c08450d09c.
   



##########
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:
   Thanks — restored that note above the concatenation in 
`addJdbcKeywordCondition`, in c08450d09c.
   



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