From 880cca603b1f798b7ea2f3cdb00e9ae8a5b61df1 Mon Sep 17 00:00:00 2001 From: sjgllgh Date: Sun, 8 Oct 2023 13:40:26 +0800 Subject: [PATCH 1/3] Jdbc driver is compatible with multiple versions --- .../ujes/jdbc/LinkisSQLConnection.scala | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/linkis-computation-governance/linkis-jdbc-driver/src/main/scala/org/apache/linkis/ujes/jdbc/LinkisSQLConnection.scala b/linkis-computation-governance/linkis-jdbc-driver/src/main/scala/org/apache/linkis/ujes/jdbc/LinkisSQLConnection.scala index e111615cee..f1eaf79570 100644 --- a/linkis-computation-governance/linkis-jdbc-driver/src/main/scala/org/apache/linkis/ujes/jdbc/LinkisSQLConnection.scala +++ b/linkis-computation-governance/linkis-jdbc-driver/src/main/scala/org/apache/linkis/ujes/jdbc/LinkisSQLConnection.scala @@ -25,29 +25,14 @@ import org.apache.linkis.ujes.client.UJESClient import org.apache.linkis.ujes.client.request.JobSubmitAction import org.apache.linkis.ujes.client.response.JobExecuteResult import org.apache.linkis.ujes.jdbc.UJESSQLDriverMain._ - import org.apache.commons.lang3.StringUtils - import java.{sql, util} -import java.sql.{ - Blob, - CallableStatement, - Clob, - Connection, - DatabaseMetaData, - NClob, - PreparedStatement, - ResultSet, - Savepoint, - SQLException, - SQLWarning, - SQLXML, - Statement, - Struct -} +import java.sql.{Blob, CallableStatement, Clob, Connection, DatabaseMetaData, NClob, PreparedStatement, ResultSet, SQLException, SQLWarning, SQLXML, Savepoint, Statement, Struct} import java.util.Properties import java.util.concurrent.Executor +import org.apache.linkis.manager.label.builder.factory.LabelBuilderFactoryContext + import scala.collection.JavaConverters._ class LinkisSQLConnection(private[jdbc] val ujesClient: UJESClient, props: Properties) @@ -113,7 +98,17 @@ class LinkisSQLConnection(private[jdbc] val ujesClient: UJESClient, props: Prope if (params != null & params.length() > 0) { params.split(PARAM_SPLIT).map(_.split(KV_SPLIT)).foreach { case Array(k, v) if k.equals(UJESSQLDriver.ENGINE_TYPE) => - return EngineTypeLabelCreator.createEngineTypeLabel(v) + if (v.contains('-')) { + val factory = LabelBuilderFactoryContext.getLabelBuilderFactory + val label = factory.createLabel(classOf[EngineTypeLabel]) + val engineType = v.split("-").head + val version = v.replaceFirst(engineType + "-", "") + label.setEngineType(engineType) + label.setVersion(version) + return label + } else { + return EngineTypeLabelCreator.createEngineTypeLabel(v) + } case _ => } } @@ -442,7 +437,7 @@ class LinkisSQLConnection(private[jdbc] val ujesClient: UJESClient, props: Prope private[jdbc] def toSubmit(code: String): JobExecuteResult = { val engineTypeLabel = getEngineType - labelMap.put(LabelKeyConstant.ENGINE_TYPE_KEY, engineTypeLabel.getStringValue) + labelMap.put(LabelKeyConstant.ENGINE_TYPE_KEY, engineTypeLabel) labelMap.put(LabelKeyConstant.USER_CREATOR_TYPE_KEY, s"$user-$creator") labelMap.put(LabelKeyConstant.CODE_TYPE_KEY, engineToCodeType(engineTypeLabel.getEngineType)) From f2707f927593d5fed5797acfc9b3a1a875129689 Mon Sep 17 00:00:00 2001 From: sjgllgh Date: Sun, 8 Oct 2023 14:01:33 +0800 Subject: [PATCH 2/3] code formatting --- .../ujes/jdbc/LinkisSQLConnection.scala | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/linkis-computation-governance/linkis-jdbc-driver/src/main/scala/org/apache/linkis/ujes/jdbc/LinkisSQLConnection.scala b/linkis-computation-governance/linkis-jdbc-driver/src/main/scala/org/apache/linkis/ujes/jdbc/LinkisSQLConnection.scala index f1eaf79570..878341297c 100644 --- a/linkis-computation-governance/linkis-jdbc-driver/src/main/scala/org/apache/linkis/ujes/jdbc/LinkisSQLConnection.scala +++ b/linkis-computation-governance/linkis-jdbc-driver/src/main/scala/org/apache/linkis/ujes/jdbc/LinkisSQLConnection.scala @@ -18,6 +18,7 @@ package org.apache.linkis.ujes.jdbc import org.apache.linkis.common.utils.{Logging, Utils} +import org.apache.linkis.manager.label.builder.factory.LabelBuilderFactoryContext import org.apache.linkis.manager.label.constant.LabelKeyConstant import org.apache.linkis.manager.label.entity.engine.{EngineType, EngineTypeLabel, RunType} import org.apache.linkis.manager.label.utils.EngineTypeLabelCreator @@ -25,14 +26,29 @@ import org.apache.linkis.ujes.client.UJESClient import org.apache.linkis.ujes.client.request.JobSubmitAction import org.apache.linkis.ujes.client.response.JobExecuteResult import org.apache.linkis.ujes.jdbc.UJESSQLDriverMain._ + import org.apache.commons.lang3.StringUtils + import java.{sql, util} -import java.sql.{Blob, CallableStatement, Clob, Connection, DatabaseMetaData, NClob, PreparedStatement, ResultSet, SQLException, SQLWarning, SQLXML, Savepoint, Statement, Struct} +import java.sql.{ + Blob, + CallableStatement, + Clob, + Connection, + DatabaseMetaData, + NClob, + PreparedStatement, + ResultSet, + Savepoint, + SQLException, + SQLWarning, + SQLXML, + Statement, + Struct +} import java.util.Properties import java.util.concurrent.Executor -import org.apache.linkis.manager.label.builder.factory.LabelBuilderFactoryContext - import scala.collection.JavaConverters._ class LinkisSQLConnection(private[jdbc] val ujesClient: UJESClient, props: Properties) From 3a0aeedb75a3d1b6cd1c343292901006bf5b43bc Mon Sep 17 00:00:00 2001 From: sjgllgh Date: Tue, 17 Oct 2023 10:59:36 +0800 Subject: [PATCH 3/3] Update reference method --- .../org/apache/linkis/ujes/jdbc/LinkisSQLConnection.scala | 7 ++----- .../manager/label/entity/engine/EngineTypeLabel.java | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/linkis-computation-governance/linkis-jdbc-driver/src/main/scala/org/apache/linkis/ujes/jdbc/LinkisSQLConnection.scala b/linkis-computation-governance/linkis-jdbc-driver/src/main/scala/org/apache/linkis/ujes/jdbc/LinkisSQLConnection.scala index 878341297c..35ec8636dd 100644 --- a/linkis-computation-governance/linkis-jdbc-driver/src/main/scala/org/apache/linkis/ujes/jdbc/LinkisSQLConnection.scala +++ b/linkis-computation-governance/linkis-jdbc-driver/src/main/scala/org/apache/linkis/ujes/jdbc/LinkisSQLConnection.scala @@ -117,10 +117,7 @@ class LinkisSQLConnection(private[jdbc] val ujesClient: UJESClient, props: Prope if (v.contains('-')) { val factory = LabelBuilderFactoryContext.getLabelBuilderFactory val label = factory.createLabel(classOf[EngineTypeLabel]) - val engineType = v.split("-").head - val version = v.replaceFirst(engineType + "-", "") - label.setEngineType(engineType) - label.setVersion(version) + label.setStringValue(v) return label } else { return EngineTypeLabelCreator.createEngineTypeLabel(v) @@ -453,7 +450,7 @@ class LinkisSQLConnection(private[jdbc] val ujesClient: UJESClient, props: Prope private[jdbc] def toSubmit(code: String): JobExecuteResult = { val engineTypeLabel = getEngineType - labelMap.put(LabelKeyConstant.ENGINE_TYPE_KEY, engineTypeLabel) + labelMap.put(LabelKeyConstant.ENGINE_TYPE_KEY, engineTypeLabel.getStringValue) labelMap.put(LabelKeyConstant.USER_CREATOR_TYPE_KEY, s"$user-$creator") labelMap.put(LabelKeyConstant.CODE_TYPE_KEY, engineToCodeType(engineTypeLabel.getEngineType)) diff --git a/linkis-computation-governance/linkis-manager/linkis-label-common/src/main/java/org/apache/linkis/manager/label/entity/engine/EngineTypeLabel.java b/linkis-computation-governance/linkis-manager/linkis-label-common/src/main/java/org/apache/linkis/manager/label/entity/engine/EngineTypeLabel.java index 6e27151131..53145503e2 100644 --- a/linkis-computation-governance/linkis-manager/linkis-label-common/src/main/java/org/apache/linkis/manager/label/entity/engine/EngineTypeLabel.java +++ b/linkis-computation-governance/linkis-manager/linkis-label-common/src/main/java/org/apache/linkis/manager/label/entity/engine/EngineTypeLabel.java @@ -79,7 +79,7 @@ public Boolean isEmpty() { } @Override - protected void setStringValue(String stringValue) { + public void setStringValue(String stringValue) { if (StringUtils.isNotBlank(stringValue)) { try { HashMap valueMap =