From 588fa0d1af343fe76f66e21a09d9dee2f9fde776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cv=5Fkkhuang=E2=80=9D?= <“420895376@qq.com”> Date: Mon, 16 Dec 2024 16:30:18 +0800 Subject: [PATCH] Code Optimization --- .../linkis/ujes/jdbc/UJESSQLResultSet.scala | 30 +++++++++++-------- .../io/executor/IoEngineConnExecutor.scala | 5 +++- .../engineplugin/io/utils/IOHelp.scala | 18 +++++------ 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/linkis-computation-governance/linkis-jdbc-driver/src/main/scala/org/apache/linkis/ujes/jdbc/UJESSQLResultSet.scala b/linkis-computation-governance/linkis-jdbc-driver/src/main/scala/org/apache/linkis/ujes/jdbc/UJESSQLResultSet.scala index 37c379a7ca..7a3fdf0f7e 100644 --- a/linkis-computation-governance/linkis-jdbc-driver/src/main/scala/org/apache/linkis/ujes/jdbc/UJESSQLResultSet.scala +++ b/linkis-computation-governance/linkis-jdbc-driver/src/main/scala/org/apache/linkis/ujes/jdbc/UJESSQLResultSet.scala @@ -175,13 +175,23 @@ class UJESSQLResultSet( if (null == resultSetResult) { return } - metaData = resultSetResult.getMetadata.asInstanceOf[util.List[util.Map[String, String]]] - if (null != metaData) { - for (cursor <- 1 to metaData.size()) { - val col = metaData.get(cursor - 1) - resultSetMetaData.setColumnNameProperties(cursor, col.get("columnName")) - resultSetMetaData.setDataTypeProperties(cursor, col.get("dataType")) - resultSetMetaData.setCommentPropreties(cursor, col.get("comment")) + val metaTmp = resultSetResult.getMetadata + if (NULL_VALUE.equals(String.valueOf(metaTmp))) { + val fileContentList = resultSetResult.getFileContent.asInstanceOf[util.List[util.List[String]]] + if (null != fileContentList) { + resultSetMetaData.setColumnNameProperties(1, "linkis_string") + resultSetMetaData.setDataTypeProperties(1, "String") + resultSetMetaData.setCommentPropreties(1, NULL_VALUE) + } + } else { + metaData = metaTmp.asInstanceOf[util.List[util.Map[String, String]]] + if (null != metaData) { + for (cursor <- 1 to metaData.size()) { + val col = metaData.get(cursor - 1) + resultSetMetaData.setColumnNameProperties(cursor, col.get("columnName")) + resultSetMetaData.setDataTypeProperties(cursor, col.get("dataType")) + resultSetMetaData.setCommentPropreties(cursor, col.get("comment")) + } } } } @@ -194,12 +204,6 @@ class UJESSQLResultSet( resultSetResult.getFileContent.asInstanceOf[util.ArrayList[util.ArrayList[String]]] } - def getResultSet(): util.ArrayList[util.ArrayList[String]] = { - resultSetResultInit() - resultSetInit() - resultSetRow - } - private def init(): Unit = { resultSetResultInit() metaDataInit() diff --git a/linkis-engineconn-plugins/io_file/src/main/scala/org/apache/linkis/manager/engineplugin/io/executor/IoEngineConnExecutor.scala b/linkis-engineconn-plugins/io_file/src/main/scala/org/apache/linkis/manager/engineplugin/io/executor/IoEngineConnExecutor.scala index e8feb0d354..a9ec71ba00 100644 --- a/linkis-engineconn-plugins/io_file/src/main/scala/org/apache/linkis/manager/engineplugin/io/executor/IoEngineConnExecutor.scala +++ b/linkis-engineconn-plugins/io_file/src/main/scala/org/apache/linkis/manager/engineplugin/io/executor/IoEngineConnExecutor.scala @@ -60,6 +60,8 @@ import java.util.concurrent.atomic.AtomicLong import scala.collection.JavaConverters._ import scala.collection.mutable.ArrayBuffer +import com.google.gson.internal.LinkedTreeMap + class IoEngineConnExecutor(val id: Int, val outputLimit: Int = 10) extends ConcurrentComputationExecutor(outputLimit) with Logging { @@ -322,7 +324,8 @@ class IoEngineConnExecutor(val id: Int, val outputLimit: Int = 10) s"Creator ${methodEntity.creatorUser} for user ${methodEntity.proxyUser} init fs $methodEntity" ) var fsId = methodEntity.id - val properties = methodEntity.params(0).asInstanceOf[Map[String, String]] + val properties = + methodEntity.params(0).asInstanceOf[LinkedTreeMap[String, String]].asScala.toMap val proxyUser = methodEntity.proxyUser if (!fsProxyService.canProxyUser(methodEntity.creatorUser, proxyUser, methodEntity.fsType)) { throw new StorageErrorException( diff --git a/linkis-engineconn-plugins/io_file/src/main/scala/org/apache/linkis/manager/engineplugin/io/utils/IOHelp.scala b/linkis-engineconn-plugins/io_file/src/main/scala/org/apache/linkis/manager/engineplugin/io/utils/IOHelp.scala index b6f35a2e8e..8d84a1b0b0 100644 --- a/linkis-engineconn-plugins/io_file/src/main/scala/org/apache/linkis/manager/engineplugin/io/utils/IOHelp.scala +++ b/linkis-engineconn-plugins/io_file/src/main/scala/org/apache/linkis/manager/engineplugin/io/utils/IOHelp.scala @@ -61,21 +61,17 @@ object IOHelp { writer.addRecord(ioRecord) writer.toString() } else if (method.params.length == 3) { - val position = - if (method.params(1).toString.toInt < 0) { - 0 - } else { - method.params(1).toString.toInt - } + val parm1 = BigDecimal(method.params(1).toString).intValue() + val parm2 = BigDecimal(method.params(2).toString).intValue() + if (parm1 > 0) { + inputStream.skip(parm1) + } val fetchSize = - if (method.params(2).toString.toInt > maxPageSize) { + if (parm2 > maxPageSize) { maxPageSize.toInt } else { - method.params(2).toString.toInt + parm2 } - if (position > 0) { - inputStream.skip(position) - } val bytes = new Array[Byte](fetchSize) val len = StorageUtils.readBytes(inputStream, bytes, fetchSize) val ioMetaData = new IOMetaData(0, len)