Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: exception when the size of pdAddresse is > 1 (#2473) #2477

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ case class TiAuthorization private (parameters: Map[String, String], tiConf: TiC
parsePrivilegeFromRow(input)
}

def getPDAddress(): String = {
def getPDAddresses(): String = {
try {
jdbcClient.getPDAddress
String.join(",", jdbcClient.getPDAddresses)
} catch {
case e: Throwable =>
throw new IllegalArgumentException(
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/org/apache/spark/sql/TiContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class TiContext(val sparkSession: SparkSession) extends Serializable with Loggin
final val tiConf: TiConfiguration = TiUtil.sparkConfToTiConf(
conf,
if (TiAuthorization.enableAuth) {
Option(tiAuthorization.get.getPDAddress())
Option(tiAuthorization.get.getPDAddresses())
} else Option.empty)
final val tiSession: TiSession = TiSession.getInstance(tiConf)
lazy val sqlContext: SQLContext = sparkSession.sqlContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class TiCatalog extends TableCatalog with SupportsNamespaces {

val pdAddress: String =
if (TiAuthorization.enableAuth) {
tiAuthorization.get.getPDAddress()
tiAuthorization.get.getPDAddresses()
} else {
if (!options.containsKey("pd.addresses") && !options.containsKey("pd.address")) {
throw new Exception("missing configuration spark.sql.catalog.tidb_catalog.pd.addresses")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class TiAuthIntegrationSuite extends SharedSQLContext {
}

test("Get PD address from TiDB should be correct") {
ti.tiAuthorization.get.getPDAddress() should be(pdAddresses)
ti.tiAuthorization.get.getPDAddresses() should be(pdAddresses)
}

test("Use database and select without privilege should not be passed") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public List<String> showGrants() {
}
}

public String getPDAddress() throws SQLException {
return queryForObject(GET_PD_ADDRESS, (rs, rowNum) -> rs.getString(1));
public List<String> getPDAddresses() throws SQLException {
return query(GET_PD_ADDRESS, (rs, rowNum) -> rs.getString(1));
}

public String getCurrentUser() throws SQLException {
Expand Down