Skip to content

Commit

Permalink
fix config type convert bug for item with default null value (vesoft-…
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole00 committed Nov 16, 2023
1 parent aa00466 commit 621d2fe
Showing 1 changed file with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ case class DataBaseConfigEntry(graphAddress: List[String],
for (address <- metaAddresses) {
require(
!address.contains(",") && !address.contains(""),
"nebula.address.meta has wrong format,,please make sure the format is [\"ip1:port1\",\"ip2:port2\"]")
"nebula.address.meta has wrong format, please make sure the format is [\"ip1:port1\",\"ip2:port2\"]")
}

override def toString: String = super.toString
Expand Down Expand Up @@ -414,7 +414,7 @@ object Configs {
// If you want to qualified the key policy, you can wrap them into a block.
var prefix: String = null
val vertexField = if (tagConfig.hasPath("vertex.field")) {
prefix = getOrElse(tagConfig, "vertex.prefix", null)
prefix = getStringOrNull(tagConfig, "vertex.prefix")
tagConfig.getString("vertex.field")
} else {
tagConfig.getString("vertex")
Expand Down Expand Up @@ -524,7 +524,7 @@ object Configs {
var sourcePrefix: String = null
val sourceField = if (!isGeo) {
if (edgeConfig.hasPath("source.field")) {
sourcePrefix = getOrElse(edgeConfig, "source.prefix", null)
sourcePrefix = getStringOrNull(edgeConfig, "source.prefix")
edgeConfig.getString("source.field")
} else {
edgeConfig.getString("source")
Expand All @@ -545,7 +545,7 @@ object Configs {
}
var targetPrefix: String = null
val targetField: String = if (edgeConfig.hasPath("target.field")) {
targetPrefix = getOrElse(edgeConfig, "target.prefix", null)
targetPrefix = getStringOrNull(edgeConfig, "target.prefix")
edgeConfig.getString("target.field")
} else {
edgeConfig.getString("target")
Expand Down Expand Up @@ -782,21 +782,21 @@ object Configs {
config.getString("host"),
config.getInt("port"),
config.getString("database"),
getOrElse(config, "table", null),
getStringOrNull(config, "table"),
config.getString("user"),
config.getString("password"),
getOrElse(config, "sentence", null)
getStringOrNull(config, "sentence")
)
case SourceCategory.POSTGRESQL =>
PostgreSQLSourceConfigEntry(
SourceCategory.POSTGRESQL,
config.getString("host"),
config.getInt("port"),
config.getString("database"),
getOrElse(config, "table", null),
getStringOrNull(config, "table"),
config.getString("user"),
config.getString("password"),
getOrElse(config, "sentence", null)
getStringOrNull(config, "sentence")
)
case SourceCategory.ORACLE =>
OracleConfigEntry(
Expand All @@ -805,8 +805,8 @@ object Configs {
config.getString("driver"),
config.getString("user"),
config.getString("password"),
getOrElse(config, "table", null),
getOrElse(config, "sentence", null)
getStringOrNull(config, "table"),
getStringOrNull(config, "sentence")
)
case SourceCategory.JDBC =>
val partitionColumn =
Expand Down Expand Up @@ -840,13 +840,13 @@ object Configs {
config.getString("driver"),
config.getString("user"),
config.getString("password"),
getOrElse(config, "table", null),
getStringOrNull(config, "table"),
partitionColumn,
lowerBound,
upperBound,
numPartitions,
fetchSize,
getOrElse(config, "sentence", null)
getStringOrNull(config, "sentence")
)
case SourceCategory.KAFKA =>
val intervalSeconds =
Expand Down Expand Up @@ -896,10 +896,10 @@ object Configs {
config.getString("columnFamily"),
fields.toSet.toList)
case SourceCategory.MAXCOMPUTE => {
val table = getOrElse(config, "table", null)
val partitionSpec = getOrElse(config, "partitionSpec", null)
val table = config.getString("table")
val partitionSpec = getStringOrNull(config, "partitionSpec")
val numPartitions = getOrElse(config, "numPartitions", "1")
val sentence = getOrElse(config, "sentence", null)
val sentence = getStringOrNull(config, "sentence")

MaxComputeConfigEntry(
SourceCategory.MAXCOMPUTE,
Expand All @@ -915,15 +915,15 @@ object Configs {
)
}
case SourceCategory.CLICKHOUSE => {
val partition: String = getOrElse (config, "numPartition", "1")
val partition: String = getOrElse(config, "numPartition", "1")
ClickHouseConfigEntry(
SourceCategory.CLICKHOUSE,
config.getString("url"),
config.getString("user"),
config.getString("password"),
partition,
getOrElse(config, "table", null),
getOrElse(config, "sentence", null)
getStringOrNull(config, "table"),
getStringOrNull(config, "sentence")
)
}
case _ =>
Expand Down Expand Up @@ -1003,6 +1003,21 @@ object Configs {
}
}

/**
* Get the String value from config
*
* @param config config item
* @path the path of config
* @return String
*/
private[this] def getStringOrNull(config: Config, path: String): String = {
if (config.hasPath(path)) {
config.getString(path)
} else {
null
}
}

private[this] def getOptOrElse(config: Config, path: String): Option[String] = {
if (config.hasPath(path)) {
Some(config.getString(path))
Expand Down

0 comments on commit 621d2fe

Please sign in to comment.